Skip to content

Commit

Permalink
Change implementation of bit_string.concat (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
sporto authored Jun 27, 2022
1 parent 5abe546 commit f3f9aa5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gleam_stdlib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down
16 changes: 16 additions & 0 deletions test/gleam/bit_string_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f3f9aa5

Please sign in to comment.