diff options
author | Sebastian Porto <s@porto5.com> | 2022-06-28 05:21:14 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-27 20:21:14 +0100 |
commit | f3f9aa54c1b9863fef0b2840deecd574f7c28aa6 (patch) | |
tree | 2ea4946fbe40316e759d78168954d60d59007fdb | |
parent | 5abe5464d9a633d75949fa305485a5a876c866fd (diff) | |
download | gleam_stdlib-f3f9aa54c1b9863fef0b2840deecd574f7c28aa6.tar.gz gleam_stdlib-f3f9aa54c1b9863fef0b2840deecd574f7c28aa6.zip |
Change implementation of bit_string.concat (#314)
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | src/gleam_stdlib.erl | 2 | ||||
-rw-r--r-- | test/gleam/bit_string_test.gleam | 16 |
3 files changed, 20 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f47119..28e600d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Unreleased + +- Fixed a bug in `big_string.concat`, it now uses `erlang:list_to_bitstring` - The `bit_builder` module gains the `from_bit_strings` function. ## v0.22.0 - 2022-06-15 diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl index e7b80d6..c4d01e4 100644 --- a/src/gleam_stdlib.erl +++ b/src/gleam_stdlib.erl @@ -163,7 +163,7 @@ string_pop_grapheme(String) -> end. bit_string_concat(BitStrings) -> - iolist_to_binary(BitStrings). + list_to_bitstring(BitStrings). bit_string_slice(Bin, Pos, Len) -> try {ok, binary:part(Bin, Pos, Len)} diff --git a/test/gleam/bit_string_test.gleam b/test/gleam/bit_string_test.gleam index a395672..48f66d6 100644 --- a/test/gleam/bit_string_test.gleam +++ b/test/gleam/bit_string_test.gleam @@ -23,6 +23,14 @@ pub fn append_test() { |> should.equal(<<1, 2, 3, 4>>) } +if erlang { + pub fn append_erlang_only_test() { + <<1, 2:4>> + |> bit_string.append(<<3>>) + |> should.equal(<<1, 2:4, 3>>) + } +} + pub fn concat_test() { [<<1, 2>>] |> bit_string.concat @@ -33,6 +41,14 @@ pub fn concat_test() { |> should.equal(<<1, 2, 3, 4>>) } +if erlang { + pub fn concat_erlang_only_test() { + [<<1, 2:4>>, <<3>>] + |> bit_string.concat + |> should.equal(<<1, 2:4, 3>>) + } +} + pub fn slice_test() { <<"hello":utf8>> |> bit_string.slice(0, 5) |