/**************************************** * NOTICE * ______________________________________ * * Copyright 2023 Tony Nguyen * * Project: * Name: to_snake_case * Links: * - https://gitlab.com/t101/to_snake_case * * Modified: 20-Feb-2023 * ______________________________________ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************/ #[cfg(test)] mod test_pascal_case { use to_snake_case::ToSnakeCase; #[test] fn test_pascal_case() { let expected = "to_snake_case"; let input = String::from("ToSnakeCase"); let output = input.to_snake_case(); assert_eq!(expected, &output); } #[test] fn test_with_space() { let expected = "to snake case"; let input = String::from("To Snake Case"); let output = input.to_snake_case(); assert_eq!(expected, &output); } #[test] fn test_pascal_case_short_word_one_letter() { let expected = "a"; let input = String::from("a"); let output = input.to_snake_case(); assert_eq!(expected, &output); } #[test] fn test_pascal_case_short_word_two_letters() { let expected = "ab"; let input = String::from("Ab"); let output = input.to_snake_case(); assert_eq!(expected, &output); } #[test] fn test_pascal_case_end_capital() { let expected = "ab_c"; let input = String::from("AbC"); let output = input.to_snake_case(); assert_eq!(expected, &output); } #[test] fn test_pascal_case_with_acronym_at_end() { let expected = "to_ascii"; let input = String::from("ToASCII"); let output = input.to_snake_case(); assert_eq!(expected, &output); } #[test] fn test_pascal_case_with_acronym_at_start() { let expected = "ascii_from"; let input = String::from("ASCIIFrom"); let output = input.to_snake_case(); assert_eq!(expected, &output); } #[test] fn test_pascal_case_with_acronym_at_start_short_text() { let expected = "a_bc"; let input = String::from("ABc"); let output = input.to_snake_case(); assert_eq!(expected, &output); } #[test] fn test_pascal_case_with_acronym_at_end_short_text() { let expected = "ab_cd"; let input = String::from("AbCD"); let output = input.to_snake_case(); assert_eq!(expected, &output); } }