aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorinoas <mail@inoas.com>2022-11-29 07:38:19 +0100
committerLouis Pilfold <louis@lpil.uk>2022-12-22 20:44:33 +0000
commit86532391dac84e5136031940db962d45a7814a02 (patch)
tree3dca09c98ce5eed790dd8f30e3d0c428f99973c1 /test
parent04b84338c488c38a6d180149277f9ca943a38415 (diff)
downloadgleam_stdlib-86532391dac84e5136031940db962d45a7814a02.tar.gz
gleam_stdlib-86532391dac84e5136031940db962d45a7814a02.zip
readd tests
Diffstat (limited to 'test')
-rw-r--r--test/gleam/string_test.gleam100
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