diff options
author | Peter Saxton <peterhsaxton@gmail.com> | 2020-06-22 15:17:37 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-06-22 20:15:00 +0100 |
commit | e4cf585c6a19b813d06658a3dc4dce7968ae3621 (patch) | |
tree | 7bd36c7bc30d2477b4d2c1f3b13b2d757942c13b /test | |
parent | ea3a318c0d6c133c8c05d9fa20a7adddc500ad75 (diff) | |
download | gleam_stdlib-e4cf585c6a19b813d06658a3dc4dce7968ae3621.tar.gz gleam_stdlib-e4cf585c6a19b813d06658a3dc4dce7968ae3621.zip |
Add pop utility functions for lists
Diffstat (limited to 'test')
-rw-r--r-- | test/gleam/list_test.gleam | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index 35e5701..ef096f6 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -424,3 +424,36 @@ pub fn key_find_test() { |> list.key_find(2) |> should.equal(Error(Nil)) } + +pub fn pop_test() { + list.pop([1, 2, 3], fn(x) { x > 2 }) + |> should.equal(Ok(tuple(3, [1, 2]))) + + list.pop([1, 2, 3], fn(x) { x > 4 }) + |> should.equal(Error(Nil)) + + list.pop([], fn(_x) { True }) + |> should.equal(Error(Nil)) +} + +pub fn pop_map_test() { + list.pop_map(["foo", "2", "3"], int.parse) + |> should.equal(Ok(tuple(2, ["foo", "3"]))) + + list.pop_map(["foo", "bar"], int.parse) + |> should.equal(Error(Nil)) + + list.pop_map([], int.parse) + |> should.equal(Error(Nil)) +} + +pub fn key_pop_test() { + list.key_pop([tuple("a", 0), tuple("b", 1)], "a") + |> should.equal(Ok(tuple(0, [tuple("b", 1)]))) + + list.key_pop([tuple("a", 0), tuple("b", 1)], "b") + |> should.equal(Ok(tuple(1, [tuple("a", 0)]))) + + list.key_pop([tuple("a", 0), tuple("b", 1)], "c") + |> should.equal(Error(Nil)) +} |