mirror of https://github.com/helix-editor/helix
refactor: remove complex test helper definition, use for loop instead
parent
efab176b06
commit
58177afb2a
|
@ -151,153 +151,179 @@ pub fn to_snake_case(text: impl Iterator<Item = char>) -> Tendril {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn case_tester<'a, F>(change_fn: F) -> impl Fn(&'a str, &'a str) + 'a
|
#[test]
|
||||||
where
|
fn test_camel_case_conversion() {
|
||||||
F: Fn(std::str::Chars<'a>) -> Tendril + 'a,
|
let tests = [
|
||||||
{
|
("hello world", "helloWorld"),
|
||||||
move |input: &str, expected: &str| {
|
("Hello World", "helloWorld"),
|
||||||
let transformed = change_fn(input.chars());
|
("hello_world", "helloWorld"),
|
||||||
let m = transformed.to_string();
|
("HELLO_WORLD", "helloWorld"),
|
||||||
dbg!(input);
|
("hello-world", "helloWorld"),
|
||||||
assert_eq!(m.as_str(), expected)
|
("hello world", "helloWorld"),
|
||||||
|
(" hello world", "helloWorld"),
|
||||||
|
("hello\tworld", "helloWorld"),
|
||||||
|
("HELLO WORLD", "helloWorld"),
|
||||||
|
("HELLO-world", "helloWorld"),
|
||||||
|
("hello WORLD ", "helloWorld"),
|
||||||
|
("helloWorld", "helloWorld"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in tests {
|
||||||
|
assert_eq!(to_camel_case(input.chars()), expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_camel_case_conversion() {
|
|
||||||
let camel_test = case_tester(to_camel_case);
|
|
||||||
camel_test("hello world", "helloWorld");
|
|
||||||
camel_test("Hello World", "helloWorld");
|
|
||||||
camel_test("hello_world", "helloWorld");
|
|
||||||
camel_test("HELLO_WORLD", "helloWorld");
|
|
||||||
camel_test("hello-world", "helloWorld");
|
|
||||||
camel_test("hello world", "helloWorld");
|
|
||||||
camel_test(" hello world", "helloWorld");
|
|
||||||
camel_test("hello\tworld", "helloWorld");
|
|
||||||
camel_test("HELLO WORLD", "helloWorld");
|
|
||||||
camel_test("HELLO-world", "helloWorld");
|
|
||||||
camel_test("hello WORLD ", "helloWorld");
|
|
||||||
camel_test("helloWorld", "helloWorld");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lower_case_conversion() {
|
fn test_lower_case_conversion() {
|
||||||
let lower_test = case_tester(to_lower_case);
|
let tests = [
|
||||||
lower_test("HelloWorld", "helloworld");
|
("HelloWorld", "helloworld"),
|
||||||
lower_test("HELLO WORLD", "hello world");
|
("HELLO WORLD", "hello world"),
|
||||||
lower_test("hello_world", "hello_world");
|
("hello_world", "hello_world"),
|
||||||
lower_test("Hello-World", "hello-world");
|
("Hello-World", "hello-world"),
|
||||||
lower_test("Hello", "hello");
|
("Hello", "hello"),
|
||||||
lower_test("WORLD", "world");
|
("WORLD", "world"),
|
||||||
lower_test("hello world", "hello world");
|
("hello world", "hello world"),
|
||||||
lower_test("HELLOworld", "helloworld");
|
("HELLOworld", "helloworld"),
|
||||||
lower_test("hello-world", "hello-world");
|
("hello-world", "hello-world"),
|
||||||
lower_test("hello_world_here", "hello_world_here");
|
("hello_world_here", "hello_world_here"),
|
||||||
lower_test("HELLO_world", "hello_world");
|
("HELLO_world", "hello_world"),
|
||||||
lower_test("MixEdCaseString", "mixedcasestring");
|
("MixEdCaseString", "mixedcasestring"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in tests {
|
||||||
|
assert_eq!(to_lower_case(input.chars()), expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_upper_case_conversion() {
|
fn test_upper_case_conversion() {
|
||||||
let upper_test = case_tester(to_upper_case);
|
let tests = [
|
||||||
upper_test("helloWorld", "HELLOWORLD");
|
("helloWorld", "HELLOWORLD"),
|
||||||
upper_test("hello world", "HELLO WORLD");
|
("hello world", "HELLO WORLD"),
|
||||||
upper_test("hello_world", "HELLO_WORLD");
|
("hello_world", "HELLO_WORLD"),
|
||||||
upper_test("Hello-World", "HELLO-WORLD");
|
("Hello-World", "HELLO-WORLD"),
|
||||||
upper_test("Hello", "HELLO");
|
("Hello", "HELLO"),
|
||||||
upper_test("world", "WORLD");
|
("world", "WORLD"),
|
||||||
upper_test("hello world", "HELLO WORLD");
|
("hello world", "HELLO WORLD"),
|
||||||
upper_test("helloworld", "HELLOWORLD");
|
("helloworld", "HELLOWORLD"),
|
||||||
upper_test("hello-world", "HELLO-WORLD");
|
("hello-world", "HELLO-WORLD"),
|
||||||
upper_test("hello_world_here", "HELLO_WORLD_HERE");
|
("hello_world_here", "HELLO_WORLD_HERE"),
|
||||||
upper_test("hello_WORLD", "HELLO_WORLD");
|
("hello_WORLD", "HELLO_WORLD"),
|
||||||
upper_test("mixedCaseString", "MIXEDCASESTRING");
|
("mixedCaseString", "MIXEDCASESTRING"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in tests {
|
||||||
|
assert_eq!(to_upper_case(input.chars()), expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pascal_case_conversion() {
|
fn test_pascal_case_conversion() {
|
||||||
let pascal_test = case_tester(to_pascal_case);
|
let tests = [
|
||||||
pascal_test("hello world", "HelloWorld");
|
("hello world", "HelloWorld"),
|
||||||
pascal_test("Hello World", "HelloWorld");
|
("Hello World", "HelloWorld"),
|
||||||
pascal_test("hello_world", "HelloWorld");
|
("hello_world", "HelloWorld"),
|
||||||
pascal_test("HELLO_WORLD", "HelloWorld");
|
("HELLO_WORLD", "HelloWorld"),
|
||||||
pascal_test("hello-world", "HelloWorld");
|
("hello-world", "HelloWorld"),
|
||||||
pascal_test("hello world", "HelloWorld");
|
("hello world", "HelloWorld"),
|
||||||
pascal_test(" hello world", "HelloWorld");
|
(" hello world", "HelloWorld"),
|
||||||
pascal_test("hello\tworld", "HelloWorld");
|
("hello\tworld", "HelloWorld"),
|
||||||
pascal_test("HELLO WORLD", "HelloWorld");
|
("HELLO WORLD", "HelloWorld"),
|
||||||
pascal_test("HELLO-world", "HelloWorld");
|
("HELLO-world", "HelloWorld"),
|
||||||
pascal_test("hello WORLD ", "HelloWorld");
|
("hello WORLD ", "HelloWorld"),
|
||||||
pascal_test("helloWorld", "HelloWorld");
|
("helloWorld", "HelloWorld"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in tests {
|
||||||
|
assert_eq!(to_pascal_case(input.chars()), expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_alternate_case_conversion() {
|
fn test_alternate_case_conversion() {
|
||||||
let alternate_test = case_tester(to_alternate_case);
|
let tests = [
|
||||||
alternate_test("hello world", "HELLO WORLD");
|
("hello world", "HELLO WORLD"),
|
||||||
alternate_test("Hello World", "hELLO wORLD");
|
("Hello World", "hELLO wORLD"),
|
||||||
alternate_test("helLo_woRlD", "HELlO_WOrLd");
|
("helLo_woRlD", "HELlO_WOrLd"),
|
||||||
alternate_test("HELLO_world", "hello_WORLD");
|
("HELLO_world", "hello_WORLD"),
|
||||||
alternate_test("hello-world", "HELLO-WORLD");
|
("hello-world", "HELLO-WORLD"),
|
||||||
alternate_test("Hello-world", "hELLO-WORLD");
|
("Hello-world", "hELLO-WORLD"),
|
||||||
alternate_test("hello", "HELLO");
|
("hello", "HELLO"),
|
||||||
alternate_test("HELLO", "hello");
|
("HELLO", "hello"),
|
||||||
alternate_test("hello123", "HELLO123");
|
("hello123", "HELLO123"),
|
||||||
alternate_test("hello WORLD", "HELLO world");
|
("hello WORLD", "HELLO world"),
|
||||||
alternate_test("HELLO123 world", "hello123 WORLD");
|
("HELLO123 world", "hello123 WORLD"),
|
||||||
alternate_test("world hello", "WORLD HELLO");
|
("world hello", "WORLD HELLO"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in tests {
|
||||||
|
assert_eq!(to_alternate_case(input.chars()), expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_title_case_conversion() {
|
fn test_title_case_conversion() {
|
||||||
let title_test = case_tester(to_title_case);
|
let tests = [
|
||||||
title_test("hello world", "Hello World");
|
("hello world", "Hello World"),
|
||||||
title_test("Hello World", "Hello World");
|
("Hello World", "Hello World"),
|
||||||
title_test("hello_world", "Hello World");
|
("hello_world", "Hello World"),
|
||||||
title_test("HELLO_WORLD", "Hello World");
|
("HELLO_WORLD", "Hello World"),
|
||||||
title_test("hello-world", "Hello World");
|
("hello-world", "Hello World"),
|
||||||
|
("hello world", "Hello World"),
|
||||||
|
(" hello world", "Hello World"),
|
||||||
|
("hello\tworld", "Hello World"),
|
||||||
|
// ("HELLO WORLD", "Hello World"),
|
||||||
|
("HELLO-world", "Hello World"),
|
||||||
|
// ("hello WORLD ", "Hello World"),
|
||||||
|
// ("helloWorld", "Hello World"),
|
||||||
|
];
|
||||||
|
|
||||||
title_test("hello world", "Hello World");
|
for (input, expected) in tests {
|
||||||
|
assert_eq!(to_title_case(input.chars()), expected)
|
||||||
title_test(" hello world", "Hello World");
|
}
|
||||||
title_test("hello\tworld", "Hello World");
|
|
||||||
// title_test("HELLO WORLD", "Hello World");
|
|
||||||
title_test("HELLO-world", "Hello World");
|
|
||||||
// title_test("hello WORLD ", "Hello World");
|
|
||||||
// title_test("helloWorld", "Hello World");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_kebab_case_conversion() {
|
fn test_kebab_case_conversion() {
|
||||||
let kebab_test = case_tester(to_kebab_case);
|
let tests = [
|
||||||
kebab_test("helloWorld", "hello-world");
|
("helloWorld", "hello-world"),
|
||||||
kebab_test("HelloWorld", "hello-world");
|
("HelloWorld", "hello-world"),
|
||||||
kebab_test("hello_world", "hello-world");
|
("hello_world", "hello-world"),
|
||||||
kebab_test("HELLO_WORLD", "hello-world");
|
("HELLO_WORLD", "hello-world"),
|
||||||
kebab_test("hello-world", "hello-world");
|
("hello-world", "hello-world"),
|
||||||
kebab_test("hello world", "hello-world");
|
("hello world", "hello-world"),
|
||||||
kebab_test("hello\tworld", "hello-world");
|
("hello\tworld", "hello-world"),
|
||||||
kebab_test("HELLO WORLD", "hello-world");
|
("HELLO WORLD", "hello-world"),
|
||||||
kebab_test("HELLO-world", "hello-world");
|
("HELLO-world", "hello-world"),
|
||||||
kebab_test("hello WORLD ", "hello-world");
|
("hello WORLD ", "hello-world"),
|
||||||
kebab_test("helloWorld", "hello-world");
|
("helloWorld", "hello-world"),
|
||||||
kebab_test("HelloWorld123", "hello-world123");
|
("HelloWorld123", "hello-world123"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in tests {
|
||||||
|
assert_eq!(to_kebab_case(input.chars()), expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_snake_case_conversion() {
|
fn test_snake_case_conversion() {
|
||||||
let snake_test = case_tester(to_snake_case);
|
let tests = [
|
||||||
snake_test("helloWorld", "hello_world");
|
("helloWorld", "hello_world"),
|
||||||
snake_test("HelloWorld", "hello_world");
|
("HelloWorld", "hello_world"),
|
||||||
snake_test("hello world", "hello_world");
|
("hello world", "hello_world"),
|
||||||
snake_test("HELLO WORLD", "hello_world");
|
("HELLO WORLD", "hello_world"),
|
||||||
snake_test("hello-world", "hello_world");
|
("hello-world", "hello_world"),
|
||||||
snake_test("hello world", "hello_world");
|
("hello world", "hello_world"),
|
||||||
snake_test("hello\tworld", "hello_world");
|
("hello\tworld", "hello_world"),
|
||||||
snake_test("HELLO WORLD", "hello_world");
|
("HELLO WORLD", "hello_world"),
|
||||||
snake_test("HELLO-world", "hello_world");
|
("HELLO-world", "hello_world"),
|
||||||
snake_test("hello WORLD ", "hello_world");
|
("hello WORLD ", "hello_world"),
|
||||||
snake_test("helloWorld", "hello_world");
|
("helloWorld", "hello_world"),
|
||||||
snake_test("helloWORLD123", "hello_world123");
|
("helloWORLD123", "hello_world123"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in tests {
|
||||||
|
assert_eq!(to_snake_case(input.chars()), expected)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue