diff options
author | inoas <mail@inoas.com> | 2022-11-29 07:38:19 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-12-22 20:44:33 +0000 |
commit | 86532391dac84e5136031940db962d45a7814a02 (patch) | |
tree | 3dca09c98ce5eed790dd8f30e3d0c428f99973c1 /test | |
parent | 04b84338c488c38a6d180149277f9ca943a38415 (diff) | |
download | gleam_stdlib-86532391dac84e5136031940db962d45a7814a02.tar.gz gleam_stdlib-86532391dac84e5136031940db962d45a7814a02.zip |
readd tests
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/string_test.gleam | 100 |
1 files changed, 94 insertions, 6 deletions
diff --git a/test/gleam/string_test.gleam b/test/gleam/string_test.gleam index 88840fd..2092b8b 100644 --- a/test/gleam/string_test.gleam +++ b/test/gleam/string_test.gleam @@ -351,6 +351,14 @@ pub fn pop_grapheme_test() { |> string.pop_grapheme |> should.equal(Ok(#("g", ""))) + "π³οΈβπ" + |> string.pop_grapheme + |> should.equal(Ok(#("π³οΈβπ", ""))) + + "π¨βπ©βπ¦βπ¦" + |> string.pop_grapheme() + |> should.equal(Ok(#("π¨βπ©βπ¦βπ¦", ""))) + "" |> string.pop_grapheme |> should.equal(Error(Nil)) @@ -373,9 +381,17 @@ pub fn to_graphemes_test() { |> string.to_graphemes |> should.equal(["a", "b", "c"]) - "π·ππ©πππ³οΈβπ" + "π·ππ©ππ" + |> string.to_graphemes + |> should.equal(["π·", "π", "π©", "π", "π"]) + + "π³οΈβπ" + |> string.to_graphemes + |> should.equal(["π³οΈβπ"]) + + "ππ³οΈβππ·" |> string.to_graphemes - |> should.equal(["π·", "π", "π©", "π", "π", "π³οΈβπ"]) + |> should.equal(["π", "π³οΈβπ", "π·"]) "ΔΉoΝΕΘ©mΜ
" |> string.to_graphemes @@ -389,13 +405,20 @@ pub fn to_graphemes_test() { |> string.to_graphemes() |> should.equal(["π¨βπ©βπ¦βπ¦"]) - "γγγγγ«γγ‘γγ―γ" + "π¨βπ©βπ¦βπ¦π³οΈβππ¨βπ©βπ¦βπ¦π³οΈβπ" |> string.to_graphemes() - |> should.equal(["γγ", "γγ", "γ«γ", "γ‘γ", "γ―γ"]) + |> should.equal([ + "π¨βπ©βπ¦βπ¦", "π³οΈβπ", "π¨βπ©βπ¦βπ¦", + "π³οΈβπ", + ]) + + "γγγγ«γγ’γ°" + |> string.to_graphemes() + |> should.equal(["γ", "γγ", "γ«γ", "γ’", "γ°"]) - "γγγγγγγγγγ" + "γγγγγ" |> string.to_graphemes() - |> should.equal(["γγ", "γγ", "γγ", "γγ", "γγ"]) + |> should.equal(["γ", "γ", "γ", "γ", "γ"]) "ZΝΝ«ΜΝͺΜΝ«Μ½ΝΜ΄ΜΜ€ΜΝΝΜ―ΜΜ ΝAΜ΄Μ΅ΜΜ°ΝΝ«ΝΝ’LΜ Ν¨Ν§Ν©ΝGΜ΄Μ»ΝΝΝΜΉΜΝΜΜ
ΝΜΗͺΜ΅ΜΉΜ»ΜΜ³ΝΜΜΝ!ΝΜ¬Μ°ΜΜΜΏΜΝ₯Ν₯ΜΝ£ΜΜΜΝΝ" |> string.to_graphemes @@ -406,6 +429,71 @@ pub fn to_graphemes_test() { ]) } +pub fn to_utf_codepoints_test() { + "" + |> string.to_utf_codepoints + |> should.equal([]) + + "gleam" + |> string.to_utf_codepoints + |> should.equal({ + assert #(Ok(g), Ok(l), Ok(e), Ok(a), Ok(m)) = #( + string.utf_codepoint(103), + string.utf_codepoint(108), + string.utf_codepoint(101), + string.utf_codepoint(97), + string.utf_codepoint(109), + ) + [g, l, e, a, m] + }) + + "π³οΈβπ" + |> string.to_utf_codepoints + |> should.equal({ + // ["π³", "οΈ", "β", "π"] + assert #( + Ok(waving_white_flag), + Ok(variant_selector_16), + Ok(zero_width_joiner), + Ok(rainbow), + ) = #( + string.utf_codepoint(127987), + string.utf_codepoint(65039), + string.utf_codepoint(8205), + string.utf_codepoint(127752), + ) + [waving_white_flag, variant_selector_16, zero_width_joiner, rainbow] + }) +} + +pub fn from_utf_codepoints_test() { + "" + |> string.to_utf_codepoints + |> string.from_utf_codepoints + |> should.equal("") + + "gleam" + |> string.to_utf_codepoints + |> string.from_utf_codepoints + |> should.equal("gleam") + + "π³οΈβπ" + |> string.to_utf_codepoints + |> string.from_utf_codepoints + |> should.equal("π³οΈβπ") + + { + assert #(Ok(a), Ok(b), Ok(c)) = #( + string.utf_codepoint(97), + string.utf_codepoint(98), + string.utf_codepoint(99), + ) + [a, b, c] + } + |> string.from_utf_codepoints + |> should.equal("abc") +} + pub fn utf_codepoint_test() { string.utf_codepoint(1114444) |> should.be_error |