String case conversion utility for MoonBit
///|
test "common conversions" {
assert_eq(@case.camel_case("hello world"), "helloWorld")
assert_eq(@case.pascal_case("hello world"), "HelloWorld")
assert_eq(@case.snake_case("hello world"), "hello_world")
assert_eq(@case.kebab_case("hello world"), "hello-world")
assert_eq(@case.constant_case("hello world"), "HELLO_WORLD")
assert_eq(@case.flat_case("hello world"), "helloworld")
assert_eq(@case.upper_flat_case("hello world"), "HELLOWORLD")
assert_eq(@case.cobol_case("hello world"), "HELLO-WORLD")
assert_eq(@case.ada_case("hello world"), "Hello_World")
}fn ada_case(text : String) -> Stringtest "ada_case doc example" {
assert_eq(ada_case("hello world"), "Hello_World")
assert_eq(ada_case("test123value"), "Test_123_Value")
assert_eq(ada_case(""), "")
}fn alternating_case(text : String) -> Stringtest "alternating_case doc example" {
assert_eq(alternating_case("hello world"), "hElLo WoRlD")
assert_eq(alternating_case("hello123world"), "hElLo123WoRlD")
assert_eq(alternating_case(""), "")
}fn camel_case(text : String) -> Stringtest "camel_case doc example" {
assert_eq(camel_case("hello world"), "helloWorld")
assert_eq(camel_case("XMLHttpRequest"), "xmlHttpRequest")
assert_eq(camel_case("test123value"), "test123Value")
}fn capital_case(text : String) -> Stringtest "capital_case doc example" {
assert_eq(capital_case("hello_world"), "Hello World")
assert_eq(capital_case("XMLHttpRequest"), "Xml Http Request")
assert_eq(capital_case(""), "")
}fn cobol_case(text : String) -> Stringtest "cobol_case doc example" {
assert_eq(cobol_case("hello world"), "HELLO-WORLD")
assert_eq(cobol_case("XMLHttpRequest"), "XML-HTTP-REQUEST")
assert_eq(cobol_case(""), "")
}fn constant_case(text : String) -> Stringtest "constant_case doc example" {
assert_eq(constant_case("hello world"), "HELLO_WORLD")
assert_eq(constant_case("iPhone-App"), "I_PHONE_APP")
assert_eq(constant_case(""), "")
}fn dot_case(text : String) -> Stringtest "dot_case doc example" {
assert_eq(dot_case("hello world"), "hello.world")
assert_eq(dot_case("databaseConnectionString"), "database.connection.string")
assert_eq(dot_case(""), "")
}fn flat_case(text : String) -> Stringtest "flat_case doc example" {
assert_eq(flat_case("hello world"), "helloworld")
assert_eq(flat_case("test123value"), "test123value")
assert_eq(flat_case(""), "")
}fn kebab_case(text : String) -> Stringtest "kebab_case doc example" {
assert_eq(kebab_case("hello world"), "hello-world")
assert_eq(kebab_case("XMLHttpRequest"), "xml-http-request")
assert_eq(kebab_case(""), "")
}fn no_case(text : String) -> Stringtest "no_case doc example" {
assert_eq(no_case("HelloWorld"), "hello world")
assert_eq(no_case("test123value"), "test 123 value")
assert_eq(no_case(""), "")
}fn pascal_case(text : String) -> Stringtest "pascal_case doc example" {
assert_eq(pascal_case("hello world"), "HelloWorld")
assert_eq(pascal_case("test123value"), "Test123Value")
assert_eq(pascal_case(""), "")
}fn path_case(text : String) -> Stringtest "path_case doc example" {
assert_eq(path_case("hello world"), "hello/world")
assert_eq(path_case("XMLHttpRequest"), "xml/http/request")
assert_eq(path_case(""), "")
}fn reverse_case(text : String) -> Stringtest "reverse_case doc example" {
assert_eq(reverse_case("hello"), "olleh")
assert_eq(reverse_case("Test123"), "321tseT")
assert_eq(reverse_case(""), "")
}fn sentence_case(text : String) -> Stringtest "sentence_case doc example" {
assert_eq(sentence_case("hello_world"), "Hello world")
assert_eq(sentence_case("XMLHttpRequest"), "Xml http request")
assert_eq(sentence_case(""), "")
}fn snake_case(text : String) -> Stringtest "snake_case doc example" {
assert_eq(snake_case("hello world"), "hello_world")
assert_eq(snake_case("test123value"), "test_123_value")
assert_eq(snake_case(""), "")
}fn sponge_case(text : String) -> Stringtest "sponge_case doc example" {
assert_eq(sponge_case("hello world"), "hElLo WoRlD")
assert_eq(sponge_case("test123value"), "tEsT123vAlUe")
assert_eq(sponge_case(""), "")
}fn swap_case(text : String) -> Stringtest "swap_case doc example" {
assert_eq(swap_case("Hello World"), "hELLO wORLD")
assert_eq(swap_case("snake_case"), "SNAKE_CASE")
assert_eq(swap_case(""), "")
}fn title_case(text : String) -> Stringtest "title_case doc example" {
assert_eq(title_case("the lord of the rings"), "The Lord of the Rings")
assert_eq(title_case("war and peace"), "War and Peace")
assert_eq(title_case(""), "")
}fn train_case(text : String) -> Stringtest "train_case doc example" {
assert_eq(train_case("hello world"), "Hello-World")
assert_eq(train_case("test123value"), "Test-123-Value")
assert_eq(train_case(""), "")
}fn upper_flat_case(text : String) -> Stringtest "upper_flat_case doc example" {
assert_eq(upper_flat_case("hello world"), "HELLOWORLD")
assert_eq(upper_flat_case("iPhone-App"), "IPHONEAPP")
assert_eq(upper_flat_case(""), "")
}String case conversion utility for MoonBit