From 06b07675a7881e0b8e58949c4c3fdcfe3f1f3cc5 Mon Sep 17 00:00:00 2001 From: RJ Dellecese Date: Sat, 27 Feb 2021 15:38:59 -0500 Subject: [PATCH] Add bit_string decoder and prep for new release --- CHANGELOG.md | 6 ++++++ README.md | 2 +- src/decode.gleam | 6 ++++++ src/gleam_decode.app.src | 2 +- test/decode_test.gleam | 12 ++++++++++-- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f6fa18..9cde2f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +## v1.7.0 - 2021-02-27 + +### Added + +- `bit_string` decoder for decoding `BitString`s. + ## v1.6.0 - 2021-02-25 ### Changed diff --git a/README.md b/README.md index bac00b7..ef7f8f4 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ Add `gleam_decode` to the deps section of your `rebar.config` file. ```erlang {deps, [ - {gleam_decode, "1.6.0"} + {gleam_decode, "1.7.0"} ]}. ``` diff --git a/src/decode.gleam b/src/decode.gleam index 4424377..9f27bd1 100644 --- a/src/decode.gleam +++ b/src/decode.gleam @@ -39,6 +39,12 @@ pub fn string() -> Decoder(String) { Decoder(dynamic_mod.string) } +/// Create a decoder that will attempt to transform a `Dynamic` into a +/// `BitString`. +pub fn bit_string() -> Decoder(BitString) { + Decoder(dynamic_mod.bit_string) +} + // NESTED DATA /// Create a decoder that retrieves an element in a tuple at the given position. pub fn element(at position: Int, with decoder: Decoder(value)) -> Decoder(value) { diff --git a/src/gleam_decode.app.src b/src/gleam_decode.app.src index 31f189b..d89074f 100644 --- a/src/gleam_decode.app.src +++ b/src/gleam_decode.app.src @@ -1,6 +1,6 @@ {application,gleam_decode, [{description,"Transform Erlang or Elixir data into Gleam data"}, - {vsn,"1.6.0"}, + {vsn,"1.7.0"}, {registered,[]}, {applications,[kernel,stdlib]}, {env,[]}, diff --git a/test/decode_test.gleam b/test/decode_test.gleam index f155ee7..afc0722 100644 --- a/test/decode_test.gleam +++ b/test/decode_test.gleam @@ -1,6 +1,7 @@ import decode.{ - atom, atom_field, bool, decode_dynamic, dynamic, element, fail, field, float, from_result, - int, list, map, map2, ok_error_tuple, one_of, string, succeed, then, + atom, atom_field, bit_string, bool, decode_dynamic, dynamic, element, fail, field, + float, from_result, int, list, map, map2, ok_error_tuple, one_of, string, succeed, + then, } import gleam/atom as atom_mod import gleam/dynamic.{Dynamic} as dynamic_mod @@ -47,6 +48,13 @@ pub fn string_test() { |> should.equal(Ok("string")) } +pub fn bit_string_test() { + <<"bit_string":utf8>> + |> dynamic_mod.from + |> decode_dynamic(bit_string()) + |> should.equal(Ok(<<"bit_string":utf8>>)) +} + pub fn element_test() { tuple(1, 2.3, "string") |> dynamic_mod.from