Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Add bit_string decoder and prep for new release
Browse files Browse the repository at this point in the history
  • Loading branch information
rjdellecese committed Feb 27, 2021
1 parent fdb0202 commit 06b0767
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
]}.
```

Expand Down
6 changes: 6 additions & 0 deletions src/decode.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/gleam_decode.app.src
Original file line number Diff line number Diff line change
@@ -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,[]},
Expand Down
12 changes: 10 additions & 2 deletions test/decode_test.gleam
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 06b0767

Please sign in to comment.