diff options
author | Louis Pilfold <louis@lpil.uk> | 2021-07-22 21:44:57 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-07-22 21:44:57 +0100 |
commit | 8d56e443e1df58a320629dfeae42270f9e7ef4da (patch) | |
tree | b4e92d91324a3a622553d247f44f8030310c4839 /test | |
parent | 0cca8008dd81ee5cf4086bfd28280b2f398096c7 (diff) | |
download | gleam_stdlib-8d56e443e1df58a320629dfeae42270f9e7ef4da.tar.gz gleam_stdlib-8d56e443e1df58a320629dfeae42270f9e7ef4da.zip |
Convert more string functions
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/string_test.gleam | 354 |
1 files changed, 176 insertions, 178 deletions
diff --git a/test/gleam/string_test.gleam b/test/gleam/string_test.gleam index a890d0f..b6762ca 100644 --- a/test/gleam/string_test.gleam +++ b/test/gleam/string_test.gleam @@ -43,20 +43,18 @@ pub fn split_test() { |> should.equal(["Gleam", "Erlang,Elixir"]) } -if erlang { - pub fn split_once_test() { - "Gleam,Erlang,Elixir" - |> string.split_once(",") - |> should.equal(Ok(#("Gleam", "Erlang,Elixir"))) - - "Gleam" - |> string.split_once(",") - |> should.equal(Error(Nil)) - - "" - |> string.split_once(",") - |> should.equal(Error(Nil)) - } +pub fn split_once_test() { + "Gleam,Erlang,Elixir" + |> string.split_once(",") + |> should.equal(Ok(#("Gleam", "Erlang,Elixir"))) + + "Gleam" + |> string.split_once(",") + |> should.equal(Error(Nil)) + + "" + |> string.split_once(",") + |> should.equal(Error(Nil)) } pub fn replace_test() { @@ -65,12 +63,10 @@ pub fn replace_test() { |> should.equal("Gleam++Erlang++Elixir") } -if erlang { - pub fn append_test() { - "Test" - |> string.append(" Me") - |> should.equal("Test Me") - } +pub fn append_test() { + "Test" + |> string.append(" Me") + |> should.equal("Test Me") } pub fn compare_test() { @@ -90,179 +86,179 @@ pub fn compare_test() { |> should.equal(order.Gt) } -if erlang { - pub fn contains_test() { - "gleam" - |> string.contains("ea") - |> should.equal(True) +pub fn contains_test() { + "gleam" + |> string.contains("ea") + |> should.equal(True) - "gleam" - |> string.contains("x") - |> should.equal(False) + "gleam" + |> string.contains("x") + |> should.equal(False) - string.contains(does: "bellwether", contain: "bell") - |> should.equal(True) - } + string.contains(does: "bellwether", contain: "bell") + |> should.equal(True) +} - pub fn concat_test() { - ["Hello", ", ", "world!"] - |> string.concat - |> should.equal("Hello, world!") - } +pub fn concat_test() { + ["Hello", ", ", "world!"] + |> string.concat + |> should.equal("Hello, world!") +} - pub fn repeat_test() { - "hi" - |> string.repeat(times: 3) - |> should.equal("hihihi") +pub fn repeat_test() { + "hi" + |> string.repeat(times: 3) + |> should.equal("hihihi") - "hi" - |> string.repeat(0) - |> should.equal("") + "hi" + |> string.repeat(0) + |> should.equal("") - "hi" - |> string.repeat(-1) - |> should.equal("") - } + "hi" + |> string.repeat(-1) + |> should.equal("") +} - pub fn join_test() { - ["Hello", "world!"] - |> string.join(with: ", ") - |> should.equal("Hello, world!") +pub fn join_test() { + ["Hello", "world!"] + |> string.join(with: ", ") + |> should.equal("Hello, world!") - ["Hello", "world!"] - |> string.join(with: "-") - |> should.equal("Hello-world!") - } + ["Hello", "world!"] + |> string.join(with: "-") + |> should.equal("Hello-world!") +} - pub fn trim_test() { - " hats \n" - |> string.trim() - |> should.equal("hats") - } +pub fn trim_test() { + " hats \n" + |> string.trim() + |> should.equal("hats") +} - pub fn trim_left_test() { - " hats \n" - |> string.trim_left() - |> should.equal("hats \n") - } +pub fn trim_left_test() { + " hats \n" + |> string.trim_left() + |> should.equal("hats \n") +} - pub fn trim_right_test() { - " hats \n" - |> string.trim_right() - |> should.equal(" hats") - } +pub fn trim_right_test() { + " hats \n" + |> string.trim_right() + |> should.equal(" hats") +} - pub fn starts_with_test() { - "theory" - |> string.starts_with("") - |> should.equal(True) +pub fn starts_with_test() { + "theory" + |> string.starts_with("") + |> should.equal(True) - "theory" - |> string.starts_with("the") - |> should.equal(True) + "theory" + |> string.starts_with("the") + |> should.equal(True) - "theory" - |> string.starts_with("ory") - |> should.equal(False) + "theory" + |> string.starts_with("ory") + |> should.equal(False) - "theory" - |> string.starts_with("theory2") - |> should.equal(False) - } + "theory" + |> string.starts_with("theory2") + |> should.equal(False) +} - pub fn ends_with_test() { - "theory" - |> string.ends_with("") - |> should.equal(True) +pub fn ends_with_test() { + "theory" + |> string.ends_with("") + |> should.equal(True) - "theory" - |> string.ends_with("ory") - |> should.equal(True) + "theory" + |> string.ends_with("ory") + |> should.equal(True) - "theory" - |> string.ends_with("the") - |> should.equal(False) + "theory" + |> string.ends_with("the") + |> should.equal(False) - "theory" - |> string.ends_with("theory2") - |> should.equal(False) - } + "theory" + |> string.ends_with("theory2") + |> should.equal(False) +} - pub fn slice_test() { - "gleam" - |> string.slice(at_index: 1, length: 2) - |> should.equal("le") +pub fn slice_test() { + "gleam" + |> string.slice(at_index: 1, length: 2) + |> should.equal("le") - "gleam" - |> string.slice(at_index: 1, length: 10) - |> should.equal("leam") + "gleam" + |> string.slice(at_index: 1, length: 10) + |> should.equal("leam") - "gleam" - |> string.slice(at_index: 10, length: 3) - |> should.equal("") + "gleam" + |> string.slice(at_index: 10, length: 3) + |> should.equal("") - "gleam" - |> string.slice(at_index: -2, length: 2) - |> should.equal("am") + "gleam" + |> string.slice(at_index: -2, length: 2) + |> should.equal("am") - "gleam" - |> string.slice(at_index: -12, length: 2) - |> should.equal("") + "gleam" + |> string.slice(at_index: -12, length: 2) + |> should.equal("") - "gleam" - |> string.slice(at_index: 2, length: -3) - |> should.equal("") - } + "gleam" + |> string.slice(at_index: 2, length: -3) + |> should.equal("") +} - pub fn crop_test() { - "gleam" - |> string.crop("gl") - |> should.equal("gleam") +pub fn crop_test() { + "gleam" + |> string.crop("gl") + |> should.equal("gleam") - "gleam" - |> string.crop("le") - |> should.equal("leam") + "gleam" + |> string.crop("le") + |> should.equal("leam") - string.crop(from: "gleam", before: "ea") - |> should.equal("eam") + string.crop(from: "gleam", before: "ea") + |> should.equal("eam") - "gleam" - |> string.crop("") - |> should.equal("gleam") + "gleam" + |> string.crop("") + |> should.equal("gleam") - "gleam" - |> string.crop("!") - |> should.equal("gleam") - } + "gleam" + |> string.crop("!") + |> should.equal("gleam") +} - pub fn drop_left_test() { - "gleam" - |> string.drop_left(up_to: 2) - |> should.equal("eam") +pub fn drop_left_test() { + "gleam" + |> string.drop_left(up_to: 2) + |> should.equal("eam") - "gleam" - |> string.drop_left(up_to: 6) - |> should.equal("") + "gleam" + |> string.drop_left(up_to: 6) + |> should.equal("") - "gleam" - |> string.drop_left(up_to: -2) - |> should.equal("gleam") - } + "gleam" + |> string.drop_left(up_to: -2) + |> should.equal("gleam") +} - pub fn drop_right_test() { - "gleam" - |> string.drop_right(up_to: 2) - |> should.equal("gle") +pub fn drop_right_test() { + "gleam" + |> string.drop_right(up_to: 2) + |> should.equal("gle") - "gleam" - |> string.drop_right(up_to: 5) - |> should.equal("") + "gleam" + |> string.drop_right(up_to: 5) + |> should.equal("") - "gleam" - |> string.drop_right(up_to: -2) - |> should.equal("gleam") - } + "gleam" + |> string.drop_right(up_to: -2) + |> should.equal("gleam") +} +if erlang { pub fn pad_left_test() { "121" |> string.pad_left(to: 5, with: ".") @@ -298,35 +294,37 @@ if erlang { |> string.pad_right(to: 5, with: "XY") |> should.equal("121XYXY") } +} - pub fn pop_grapheme_test() { - "gleam" - |> string.pop_grapheme() - |> should.equal(Ok(#("g", "leam"))) +pub fn pop_grapheme_test() { + "gleam" + |> string.pop_grapheme() + |> should.equal(Ok(#("g", "leam"))) - "g" - |> string.pop_grapheme() - |> should.equal(Ok(#("g", ""))) + "g" + |> string.pop_grapheme() + |> should.equal(Ok(#("g", ""))) - "" - |> string.pop_grapheme() - |> should.equal(Error(Nil)) - } + "" + |> string.pop_grapheme() + |> should.equal(Error(Nil)) +} - pub fn to_graphemes_test() { - "abc" - |> string.to_graphemes() - |> should.equal(["a", "b", "c"]) +pub fn to_graphemes_test() { + "abc" + |> string.to_graphemes() + |> should.equal(["a", "b", "c"]) - "a" - |> string.to_graphemes() - |> should.equal(["a"]) + "a" + |> string.to_graphemes() + |> should.equal(["a"]) - "" - |> string.to_graphemes() - |> should.equal([]) - } + "" + |> string.to_graphemes() + |> should.equal([]) +} +if erlang { pub fn utf_codepoint_test() { string.utf_codepoint(1114444) |> should.be_error |