diff options
author | Louis Pilfold <louis@lpil.uk> | 2020-07-10 21:13:36 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-07-10 21:13:36 +0100 |
commit | 0cff914b427e2d37a3b889e0f9586ab59cef3d39 (patch) | |
tree | 85dd6f98c2630f69e0c6ea8bbc56a60fb01117c4 | |
parent | 28fdf1078ca67f224944bffebe46151ba4a9234a (diff) | |
download | gleam_stdlib-0cff914b427e2d37a3b889e0f9586ab59cef3d39.tar.gz gleam_stdlib-0cff914b427e2d37a3b889e0f9586ab59cef3d39.zip |
bit_builder.from_string
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/gleam/bit_builder.gleam | 7 | ||||
-rw-r--r-- | test/gleam/bit_builder_test.gleam | 9 |
3 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f09670c..f706231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - The `dynamic.typed_list` argument label has changed from `containing` to `of`. - The `dynamic` module gains the `any` function. +- The `bit_builder` module gains the `from_string` function. ## v0.10.1 - 2020-07-01 diff --git a/src/gleam/bit_builder.gleam b/src/gleam/bit_builder.gleam index dc066ae..bcc4c4c 100644 --- a/src/gleam/bit_builder.gleam +++ b/src/gleam/bit_builder.gleam @@ -69,6 +69,13 @@ pub external fn append_string(to: BitBuilder, suffix: String) -> BitBuilder = pub external fn concat(List(BitBuilder)) -> BitBuilder = "gleam_stdlib" "identity" +/// Create a new builder from a string. +/// +/// Runs in constant time. +/// +pub external fn from_string(String) -> BitBuilder = + "gleam_stdlib" "wrap_list" + /// Create a new builder from a bit string. /// /// Runs in constant time. diff --git a/test/gleam/bit_builder_test.gleam b/test/gleam/bit_builder_test.gleam index b1635e5..48ea555 100644 --- a/test/gleam/bit_builder_test.gleam +++ b/test/gleam/bit_builder_test.gleam @@ -57,9 +57,16 @@ pub fn concat_test() { |> should.equal(<<1, 2, 3, 4, 5, 6>>) } -pub fn from_string_test() { +pub fn from_bit_string_test() { // Regression test: no additional modification of the builder bit_builder.from_bit_string(<<>>) |> bit_builder.to_bit_string |> should.equal(<<>>) } + +pub fn from_string_test() { + // Regression test: no additional modification of the builder + bit_builder.from_string("") + |> bit_builder.to_bit_string + |> should.equal(<<>>) +} |