diff options
author | Louis Pilfold <louis@lpil.uk> | 2021-08-08 22:14:56 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2021-08-08 22:14:56 +0100 |
commit | 29398e1848b0615afda30fb1da4ec8d81eccc1c5 (patch) | |
tree | 5762a473ca246cee13adb1632b7d5850a91fd78c /test | |
parent | c5a001977a3b76f257a3a7ea4605f6ff61f1a590 (diff) | |
download | gleam_stdlib-29398e1848b0615afda30fb1da4ec8d81eccc1c5.tar.gz gleam_stdlib-29398e1848b0615afda30fb1da4ec8d81eccc1c5.zip |
Bit string slice
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/bit_string_test.gleam | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/test/gleam/bit_string_test.gleam b/test/gleam/bit_string_test.gleam index e86dd5d..a395672 100644 --- a/test/gleam/bit_string_test.gleam +++ b/test/gleam/bit_string_test.gleam @@ -33,40 +33,42 @@ pub fn concat_test() { |> should.equal(<<1, 2, 3, 4>>) } -if erlang { - pub fn part_test() { - bit_string.from_string("hello") - |> bit_string.part(0, 5) - |> should.equal(Ok(bit_string.from_string("hello"))) - - bit_string.from_string("hello") - |> bit_string.part(0, 0) - |> should.equal(Ok(bit_string.from_string(""))) - - bit_string.from_string("hello") - |> bit_string.part(2, 2) - |> should.equal(Ok(bit_string.from_string("ll"))) - - bit_string.from_string("hello") - |> bit_string.part(5, -2) - |> should.equal(Ok(bit_string.from_string("lo"))) - - bit_string.from_string("") - |> bit_string.part(0, 0) - |> should.equal(Ok(bit_string.from_string(""))) - - bit_string.from_string("hello") - |> bit_string.part(6, 0) - |> should.equal(Error(Nil)) - - bit_string.from_string("hello") - |> bit_string.part(-1, 1) - |> should.equal(Error(Nil)) - - bit_string.from_string("hello") - |> bit_string.part(1, 6) - |> should.equal(Error(Nil)) - } +pub fn slice_test() { + <<"hello":utf8>> + |> bit_string.slice(0, 5) + |> should.equal(Ok(<<"hello":utf8>>)) + + <<"hello":utf8>> + |> bit_string.slice(0, 0) + |> should.equal(Ok(<<"":utf8>>)) + + <<"hello":utf8>> + |> bit_string.slice(2, 2) + |> should.equal(Ok(<<"ll":utf8>>)) + + <<"hello":utf8>> + |> bit_string.slice(5, -2) + |> should.equal(Ok(<<"lo":utf8>>)) + + <<"":utf8>> + |> bit_string.slice(0, 0) + |> should.equal(Ok(<<"":utf8>>)) + + <<"hello":utf8>> + |> bit_string.slice(6, 0) + |> should.equal(Error(Nil)) + + <<"hello":utf8>> + |> bit_string.slice(1, -2) + |> should.equal(Error(Nil)) + + bit_string.from_string("hello") + |> bit_string.slice(-1, 1) + |> should.equal(Error(Nil)) + + bit_string.from_string("hello") + |> bit_string.slice(1, 6) + |> should.equal(Error(Nil)) } pub fn to_string_test() { |