diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-08-17 10:35:47 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-08-17 10:43:15 +0100 |
commit | f90bd89adba09502b5a7ff188a910750257ef1b0 (patch) | |
tree | 10887e506df6ee671b41c2760c55cb14f72ddba4 | |
parent | 46ae58fb4bf6c3229ee96c842aff66087ba1aa26 (diff) | |
download | gleam_stdlib-f90bd89adba09502b5a7ff188a910750257ef1b0.tar.gz gleam_stdlib-f90bd89adba09502b5a7ff188a910750257ef1b0.zip |
Update stdlib for new struct syntax
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | gen/src/gleam@any.erl | 6 | ||||
-rw-r--r-- | gen/test/gleam@any_test.erl | 14 | ||||
-rw-r--r-- | src/gleam/any.gleam | 4 | ||||
-rw-r--r-- | src/gleam/bool.gleam | 10 | ||||
-rw-r--r-- | src/gleam/list.gleam | 26 | ||||
-rw-r--r-- | src/gleam/map_dict.gleam | 6 | ||||
-rw-r--r-- | src/gleam/order.gleam | 24 | ||||
-rw-r--r-- | src/gleam/tuple.gleam | 10 | ||||
-rw-r--r-- | src/gleam__stdlib.erl | 6 | ||||
-rw-r--r-- | test/gleam/any_test.gleam | 32 | ||||
-rw-r--r-- | test/gleam/list_test.gleam | 34 | ||||
-rw-r--r-- | test/gleam/map_dict_test.gleam | 133 | ||||
-rw-r--r-- | test/gleam/result_test.gleam | 4 | ||||
-rw-r--r-- | test/gleam/tuple_test.gleam | 14 |
15 files changed, 174 insertions, 151 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 01caaaf..9359814 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,12 @@ ## Unreleased +- Syntax has been updated for Gleam v0.4. - `list:sort` now requires a compare function as comparison operators now only work on Ints. - `list:sort`'s performance has been slightly optimised. - The `float` module gains a `compare` function. +- `any:tuple` has been renamed `any:struct2`. ## v0.3.1 - 2019-08-08 diff --git a/gen/src/gleam@any.erl b/gen/src/gleam@any.erl index c04aae4..5bd9157 100644 --- a/gen/src/gleam@any.erl +++ b/gen/src/gleam@any.erl @@ -1,7 +1,7 @@ -module(gleam@any). -compile(no_auto_import). --export([from/1, unsafe_coerce/1, string/1, int/1, float/1, atom/1, bool/1, thunk/1, list/2, tuple/1, field/2]). +-export([from/1, unsafe_coerce/1, string/1, int/1, float/1, atom/1, bool/1, thunk/1, list/2, struct2/1, field/2]). from(A) -> gleam__stdlib:identity(A). @@ -36,8 +36,8 @@ list(Any, Decode) -> fun(Capture1) -> gleam@list:traverse(Capture1, Decode) end ). -tuple(A) -> - gleam__stdlib:decode_tuple(A). +struct2(A) -> + gleam__stdlib:decode_struct2(A). field(A, B) -> gleam__stdlib:decode_field(A, B). diff --git a/gen/test/gleam@any_test.erl b/gen/test/gleam@any_test.erl index 6c65706..c8deb45 100644 --- a/gen/test/gleam@any_test.erl +++ b/gen/test/gleam@any_test.erl @@ -1,7 +1,7 @@ -module(gleam@any_test). -compile(no_auto_import). --export([string_test/0, int_test/0, float_test/0, thunk_test/0, bool_test/0, atom_test/0, list_test/0, tuple_test/0, field_test/0]). +-export([string_test/0, int_test/0, float_test/0, thunk_test/0, bool_test/0, atom_test/0, list_test/0, struct2_test/0, field_test/0]). string_test() -> gleam@expect:equal(gleam@any:string(gleam@any:from(<<"">>)), {ok, <<"">>}), @@ -117,21 +117,21 @@ list_test() -> ) ). -tuple_test() -> +struct2_test() -> gleam@expect:equal( - gleam@any:tuple(gleam@any:from({1, []})), + gleam@any:struct2(gleam@any:from({1, []})), {ok, {gleam@any:from(1), gleam@any:from([])}} ), gleam@expect:equal( - gleam@any:tuple(gleam@any:from({<<"ok">>, <<"ok">>})), + gleam@any:struct2(gleam@any:from({<<"ok">>, <<"ok">>})), {ok, {gleam@any:from(<<"ok">>), gleam@any:from(<<"ok">>)}} ), - gleam@expect:is_error(gleam@any:tuple(gleam@any:from({1}))), - gleam@expect:is_error(gleam@any:tuple(gleam@any:from({1, 2, 3}))), + gleam@expect:is_error(gleam@any:struct2(gleam@any:from({1}))), + gleam@expect:is_error(gleam@any:struct2(gleam@any:from({1, 2, 3}))), gleam@expect:equal( gleam@result:then( gleam@result:then( - gleam@any:tuple(gleam@any:from({1, 2.0})), + gleam@any:struct2(gleam@any:from({1, 2.0})), fun(X) -> gleam@result:map( gleam@any:int(gleam@tuple:first(X)), diff --git a/src/gleam/any.gleam b/src/gleam/any.gleam index 44e2dd8..ae26bc5 100644 --- a/src/gleam/any.gleam +++ b/src/gleam/any.gleam @@ -46,8 +46,8 @@ pub fn list(any, decode) { |> result:then(_, list_mod:traverse(_, decode)) } -pub external fn tuple(Any) -> Result({Any, Any}, String) - = "gleam__stdlib" "decode_tuple" +pub external fn struct2(Any) -> Result(struct(Any, Any), String) + = "gleam__stdlib" "decode_struct2" pub external fn field(Any, a) -> Result(Any, String) = "gleam__stdlib" "decode_field" diff --git a/src/gleam/bool.gleam b/src/gleam/bool.gleam index e99333b..f003691 100644 --- a/src/gleam/bool.gleam +++ b/src/gleam/bool.gleam @@ -8,11 +8,11 @@ pub fn negate(bool) { } pub fn compare(a, b) { - case {a, b} { - | {True, True} -> order:Eq - | {True, False} -> order:Gt - | {False, False} -> order:Eq - | {False, True} -> order:Lt + case struct(a, b) { + | struct(True, True) -> order:Eq + | struct(True, False) -> order:Gt + | struct(False, False) -> order:Eq + | struct(False, True) -> order:Lt } } diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 24437c6..f0adb44 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -179,7 +179,7 @@ pub fn all(list, f) { pub fn any(list, f) { case list { | [] -> False - | [ x | rest] -> + | [x | rest] -> case f(x) { | False -> any(rest, f) | _ -> True @@ -188,10 +188,10 @@ pub fn any(list, f) { } pub fn zip(l1, l2) { - case {l1, l2} { - | {[], _} -> [] - | {_, []} -> [] - | {[x1 | rest1], [x2 | rest2] } -> [ {x1, x2} | zip(rest1, rest2) ] + case struct(l1, l2) { + | struct([], _) -> [] + | struct(_, []) -> [] + | struct([x1 | rest1], [x2 | rest2]) -> [ struct(x1, x2) | zip(rest1, rest2) ] } } @@ -233,10 +233,10 @@ pub fn unique(list) { } fn merge_sort(a, b, compare) { - case {a, b} { - | {[], _} -> b - | {_, []} -> a - | {[ax | ar], [bx | br]} -> + case struct(a, b) { + | struct([], _) -> b + | struct(_, []) -> a + | struct([ax | ar], [bx | br]) -> case compare(ax, bx) { | order:Lt -> [ax | merge_sort(ar, b, compare)] | _ -> [bx | merge_sort(a, br, compare)] @@ -284,10 +284,10 @@ pub fn repeat(a, times) { fn do_split(list, n, taken) { case n <= 0 { - | True -> {reverse(taken), list} + | True -> struct(reverse(taken), list) | False -> case list { - | [] -> {reverse(taken), []} + | [] -> struct(reverse(taken), []) | [x | xs] -> do_split(xs, n - 1, [x | taken]) } } @@ -299,10 +299,10 @@ pub fn split(list, n) { fn do_split_while(list, f, acc) { case list { - | [] -> {reverse(acc), []} + | [] -> struct(reverse(acc), []) | [x | xs] -> case f(x) { - | False -> {reverse(acc), list} + | False -> struct(reverse(acc), list) | _ -> do_split_while(xs, f, [x | acc]) } } diff --git a/src/gleam/map_dict.gleam b/src/gleam/map_dict.gleam index bf3ed87..e77e861 100644 --- a/src/gleam/map_dict.gleam +++ b/src/gleam/map_dict.gleam @@ -10,10 +10,10 @@ pub enum NotFound = pub external fn size(MapDict(k, v)) -> Int = "maps" "size" -pub external fn to_list(MapDict(key, value)) -> List({key, value}) +pub external fn to_list(MapDict(key, value)) -> List(struct(key, value)) = "maps" "to_list" -pub external fn from_list(List({key, value})) -> MapDict(key, value) +pub external fn from_list(List(struct(key, value))) -> MapDict(key, value) = "maps" "from_list" external fn is_key(key, MapDict(key, v)) -> Bool @@ -90,7 +90,7 @@ pub fn update(dict, key, f) { fn do_fold(list, acc, f) { case list { | [] -> acc - | [{k, v} | tail] -> do_fold(tail, f(k, v, acc), f) + | [struct(k, v) | tail] -> do_fold(tail, f(k, v, acc), f) } } diff --git a/src/gleam/order.gleam b/src/gleam/order.gleam index 4d39705..48a4b40 100644 --- a/src/gleam/order.gleam +++ b/src/gleam/order.gleam @@ -21,28 +21,28 @@ pub fn to_int(order) { } pub fn compare(a, b) { - case {a, b} { - | {Lt, Lt} -> Eq - | {Lt, _} -> Lt - | {Eq, Eq} -> Eq - | {Gt, Gt} -> Eq - | {Eq, Gt} -> Lt + case struct(a, b) { + | struct(Lt, Lt) -> Eq + | struct(Lt, _) -> Lt + | struct(Eq, Eq) -> Eq + | struct(Gt, Gt) -> Eq + | struct(Eq, Gt) -> Lt | _ -> Gt } } pub fn max(a, b) { - case {a, b} { - | {Gt, _} -> Gt - | {Eq, Lt} -> Eq + case struct(a, b) { + | struct(Gt, _) -> Gt + | struct(Eq, Lt) -> Eq | _ -> b } } pub fn min(a, b) { - case {a, b} { - | {Lt, _} -> Lt - | {Eq, Gt} -> Eq + case struct(a, b) { + | struct(Lt, _) -> Lt + | struct(Eq, Gt) -> Eq | _ -> b } } diff --git a/src/gleam/tuple.gleam b/src/gleam/tuple.gleam index 05968d0..5260682 100644 --- a/src/gleam/tuple.gleam +++ b/src/gleam/tuple.gleam @@ -1,22 +1,22 @@ import gleam/list pub fn new(a, b) { - {a, b} + struct(a, b) } pub fn first(tup) { - let {a, _} = tup + let struct(a, _) = tup a } pub fn second(tup) { - let {_, a} = tup + let struct(_, a) = tup a } pub fn swap(tup) { - let {a, b} = tup - {b, a} + let struct(a, b) = tup + struct(b, a) } pub fn fetch(haystack, needle) { diff --git a/src/gleam__stdlib.erl b/src/gleam__stdlib.erl index 5640e70..8434082 100644 --- a/src/gleam__stdlib.erl +++ b/src/gleam__stdlib.erl @@ -6,7 +6,7 @@ atom_create_from_string/1, atom_to_string/1, map_fetch/2, iodata_append/2, iodata_prepend/2, identity/1, decode_int/1, decode_string/1, decode_bool/1, decode_float/1, decode_thunk/1, decode_atom/1, - decode_tuple/1, decode_list/1, decode_field/2, parse_int/1, parse_float/1]). + decode_struct2/1, decode_list/1, decode_field/2, parse_int/1, parse_float/1]). expect_equal(Actual, Expected) -> ?assertEqual(Expected, Actual). expect_not_equal(Actual, Expected) -> ?assertNotEqual(Expected, Actual). @@ -58,8 +58,8 @@ decode_bool(Data) -> decode_error_msg("a Bool", Data). decode_thunk(Data) when is_function(Data, 0) -> {ok, Data}; decode_thunk(Data) -> decode_error_msg("a zero arity function", Data). -decode_tuple(Data = {_, _}) -> {ok, Data}; -decode_tuple(Data) -> decode_error_msg("a 2 element tuple", Data). +decode_struct2(Data = {_, _}) -> {ok, Data}; +decode_struct2(Data) -> decode_error_msg("a 2 element struct", Data). decode_list(Data) when is_list(Data) -> {ok, Data}; decode_list(Data) -> decode_error_msg("a List", Data). diff --git a/test/gleam/any_test.gleam b/test/gleam/any_test.gleam index 7a968c2..5dda768 100644 --- a/test/gleam/any_test.gleam +++ b/test/gleam/any_test.gleam @@ -209,43 +209,43 @@ pub fn list_test() { |> expect:is_error } -pub fn tuple_test() { - {1, []} +pub fn struct2_test() { + struct(1, []) |> any:from - |> any:tuple - |> expect:equal(_, Ok({any:from(1), any:from([])})) + |> any:struct2 + |> expect:equal(_, Ok(struct(any:from(1), any:from([])))) - {"ok", "ok"} + struct("ok", "ok") |> any:from - |> any:tuple - |> expect:equal(_, Ok({any:from("ok"), any:from("ok")})) + |> any:struct2 + |> expect:equal(_, Ok(struct(any:from("ok"), any:from("ok")))) - {1} + struct(1) |> any:from - |> any:tuple + |> any:struct2 |> expect:is_error - {1, 2, 3} + struct(1, 2, 3) |> any:from - |> any:tuple + |> any:struct2 |> expect:is_error - {1, 2.0} + struct(1, 2.0) |> any:from - |> any:tuple + |> any:struct2 |> result:then(_, fn(x) { x |> tuple:first |> any:int - |> result:map(_, fn(f) { {f, tuple:second(x)} }) + |> result:map(_, fn(f) { struct(f, tuple:second(x)) }) }) |> result:then(_, fn(x) { x |> tuple:second |> any:float - |> result:map(_, fn(f) { {tuple:first(x), f} }) + |> result:map(_, fn(f) { struct(tuple:first(x), f) }) }) - |> expect:equal(_, Ok({1, 2.0})) + |> expect:equal(_, Ok(struct(1, 2.0))) } pub fn field_test() { diff --git a/test/gleam/list_test.gleam b/test/gleam/list_test.gleam index bb9168a..9710574 100644 --- a/test/gleam/list_test.gleam +++ b/test/gleam/list_test.gleam @@ -196,13 +196,13 @@ pub fn zip_test() { |> expect:equal(_, []) list:zip([1, 2, 3], [4, 5, 6]) - |> expect:equal(_, [{1, 4}, {2, 5}, {3, 6}]) + |> expect:equal(_, [struct(1, 4), struct(2, 5), struct(3, 6)]) list:zip([5, 6], [1, 2, 3]) - |> expect:equal(_, [{5, 1}, {6, 2}]) + |> expect:equal(_, [struct(5, 1), struct(6, 2)]) list:zip([5, 6, 7], [1, 2]) - |> expect:equal(_, [{5, 1}, {6, 2}]) + |> expect:equal(_, [struct(5, 1), struct(6, 2)]) } pub fn strict_zip_test() { @@ -213,7 +213,7 @@ pub fn strict_zip_test() { |> expect:is_error list:strict_zip([1, 2, 3], [4, 5, 6]) - |> expect:equal(_, Ok([{1, 4}, {2, 5}, {3, 6}])) + |> expect:equal(_, Ok([struct(1, 4), struct(2, 5), struct(3, 6)])) list:strict_zip([5, 6], [1, 2, 3]) |> expect:is_error @@ -277,8 +277,8 @@ pub fn sort_test() { } pub fn index_map_test() { - list:index_map([3, 4, 5], fn(i, x) { {i, x} }) - |> expect:equal(_, [{0, 3}, {1, 4}, {2, 5}]) + list:index_map([3, 4, 5], fn(i, x) { struct(i, x) }) + |> expect:equal(_, [struct(0, 3), struct(1, 4), struct(2, 5)]) let f = fn(i, x) { string:append(x, int:to_string(i)) @@ -323,37 +323,37 @@ pub fn repeat_test() { pub fn split_test() { list:split([], 0) - |> expect:equal(_, {[], []}) + |> expect:equal(_, struct([], [])) list:split([0, 1, 2, 3, 4], 0) - |> expect:equal(_, {[], [0, 1, 2, 3, 4]}) + |> expect:equal(_, struct([], [0, 1, 2, 3, 4])) list:split([0, 1, 2, 3, 4], -2) - |> expect:equal(_, {[], [0, 1, 2, 3, 4]}) + |> expect:equal(_, struct([], [0, 1, 2, 3, 4])) list:split([0, 1, 2, 3, 4], 1) - |> expect:equal(_, {[0], [1, 2, 3, 4]}) + |> expect:equal(_, struct([0], [1, 2, 3, 4])) list:split([0, 1, 2, 3, 4], 3) - |> expect:equal(_, {[0, 1, 2], [3, 4]}) + |> expect:equal(_, struct([0, 1, 2], [3, 4])) list:split([0, 1, 2, 3, 4], 9) - |> expect:equal(_, {[0, 1, 2, 3, 4], []}) + |> expect:equal(_, struct([0, 1, 2, 3, 4], [])) } pub fn split_while_test() { list:split_while([], fn(x) { x <= 5 }) - |> expect:equal(_, {[], []}) + |> expect:equal(_, struct([], [])) list:split_while([1, 2, 3, 4, 5], fn(x) { x <= 5 }) - |> expect:equal(_, {[1, 2, 3, 4, 5], []}) + |> expect:equal(_, struct([1, 2, 3, 4, 5], [])) list:split_while([1, 2, 3, 4, 5], fn(x) { x == 2 }) - |> expect:equal(_, {[], [1, 2, 3, 4, 5]}) + |> expect:equal(_, struct([], [1, 2, 3, 4, 5])) list:split_while([1, 2, 3, 4, 5], fn(x) { x <= 3 }) - |> expect:equal(_, {[1, 2, 3], [4, 5]}) + |> expect:equal(_, struct([1, 2, 3], [4, 5])) list:split_while([1, 2, 3, 4, 5], fn(x) { x <= -3 }) - |> expect:equal(_, {[], [1, 2, 3, 4, 5]}) + |> expect:equal(_, struct([], [1, 2, 3, 4, 5])) } diff --git a/test/gleam/map_dict_test.gleam b/test/gleam/map_dict_test.gleam index 778838c..2b7dbdb 100644 --- a/test/gleam/map_dict_test.gleam +++ b/test/gleam/map_dict_test.gleam @@ -4,8 +4,8 @@ import gleam/map_dict pub fn from_list_test() { [ - {4, 0}, - {1, 0}, + struct(4, 0), + struct(1, 0), ] |> map_dict:from_list |> map_dict:size @@ -19,23 +19,23 @@ pub fn has_key_test() { |> expect:false [ - {1, 0}, + struct(1, 0), ] |> map_dict:from_list |> map_dict:has_key(_, 1) |> expect:true [ - {4, 0}, - {1, 0}, + struct(4, 0), + struct(1, 0), ] |> map_dict:from_list |> map_dict:has_key(_, 1) |> expect:true [ - {4, 0}, - {1, 0}, + struct(4, 0), + struct(1, 0), ] |> map_dict:from_list |> map_dict:has_key(_, 0) @@ -54,8 +54,8 @@ pub fn new_test() { pub fn fetch_test() { let proplist = [ - {4, 0}, - {1, 1}, + struct(4, 0), + struct(1, 1), ] let m = map_dict:from_list(proplist) @@ -77,25 +77,33 @@ pub fn put_test() { |> map_dict:put(_, "a", 0) |> map_dict:put(_, "b", 1) |> map_dict:put(_, "c", 2) - |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 1}, {"c", 2}])) + |> expect:equal(_, map_dict:from_list([ + struct("a", 0), + struct("b", 1), + struct("c", 2), + ])) } pub fn map_values_test() { [ - {1, 0}, - {2, 1}, - {3, 2}, + struct(1, 0), + struct(2, 1), + struct(3, 2), ] |> map_dict:from_list |> map_dict:map_values(_, fn(k, v) { k + v }) - |> expect:equal(_, map_dict:from_list([{1, 1}, {2, 3}, {3, 5}])) + |> expect:equal(_, map_dict:from_list([ + struct(1, 1), + struct(2, 3), + struct(3, 5), + ])) } pub fn keys_test() { [ - {"a", 0}, - {"b", 1}, - {"c", 2}, + struct("a", 0), + struct("b", 1), + struct("c", 2), ] |> map_dict:from_list |> map_dict:keys @@ -104,9 +112,9 @@ pub fn keys_test() { pub fn values_test() { [ - {"a", 0}, - {"b", 1}, - {"c", 2}, + struct("a", 0), + struct("b", 1), + struct("c", 2), ] |> map_dict:from_list |> map_dict:values @@ -115,72 +123,72 @@ pub fn values_test() { pub fn take_test() { [ - {"a", 0}, - {"b", 1}, - {"c", 2}, + struct("a", 0), + struct("b", 1), + struct("c", 2), ] |> map_dict:from_list |> map_dict:take(_, ["a", "b", "d"]) - |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 1}])) + |> expect:equal(_, map_dict:from_list([struct("a", 0), struct("b", 1)])) } pub fn drop_test() { [ - {"a", 0}, - {"b", 1}, - {"c", 2}, + struct("a", 0), + struct("b", 1), + struct("c", 2), ] |> map_dict:from_list |> map_dict:drop(_, ["a", "b", "d"]) - |> expect:equal(_, map_dict:from_list([{"c", 2}])) + |> expect:equal(_, map_dict:from_list([struct("c", 2)])) } pub fn merge_test() { let a = map_dict:from_list([ - {"a", 2}, - {"c", 4}, - {"d", 3}, + struct("a", 2), + struct("c", 4), + struct("d", 3), ]) let b = map_dict:from_list([ - {"a", 0}, - {"b", 1}, - {"c", 2}, + struct("a", 0), + struct("b", 1), + struct("c", 2), ]) map_dict:merge(a, b) |> expect:equal(_, map_dict:from_list([ - {"a", 0}, - {"b", 1}, - {"c", 2}, - {"d", 3}, + struct("a", 0), + struct("b", 1), + struct("c", 2), + struct("d", 3), ])) map_dict:merge(b, a) |> expect:equal(_, map_dict:from_list([ - {"a", 2}, - {"b", 1}, - {"c", 4}, - {"d", 3}, + struct("a", 2), + struct("b", 1), + struct("c", 4), + struct("d", 3), ])) } pub fn delete_test() { [ - {"a", 0}, - {"b", 1}, - {"c", 2}, + struct("a", 0), + struct("b", 1), + struct("c", 2), ] |> map_dict:from_list |> map_dict:delete(_, "a") |> map_dict:delete(_, "d") - |> expect:equal(_, map_dict:from_list([{"b", 1}, {"c", 2}])) + |> expect:equal(_, map_dict:from_list([struct("b", 1), struct("c", 2)])) } pub fn update_test() { let dict = map_dict:from_list([ - {"a", 0}, - {"b", 1}, - {"c", 2}, + struct("a", 0), + struct("b", 1), + struct("c", 2), ]) let inc_or_zero = fn(x) { @@ -192,23 +200,36 @@ pub fn update_test() { dict |> map_dict:update(_, "a", inc_or_zero) - |> expect:equal(_, map_dict:from_list([{"a", 1}, {"b", 1}, {"c", 2}])) + |> expect:equal(_, map_dict:from_list([ + struct("a", 1), + struct("b", 1), + struct("c", 2), + ])) dict |> map_dict:update(_, "b", inc_or_zero) - |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 2}, {"c", 2}])) + |> expect:equal(_, map_dict:from_list([ + struct("a", 0), + struct("b", 2), + struct("c", 2), + ])) dict |> map_dict:update(_, "z", inc_or_zero) - |> expect:equal(_, map_dict:from_list([{"a", 0}, {"b", 1}, {"c", 2}, {"z", 0}])) + |> expect:equal(_, map_dict:from_list([ + struct("a", 0), + struct("b", 1), + struct("c", 2), + struct("z", 0), + ])) } pub fn fold_test() { let dict = map_dict:from_list([ - {"a", 0}, - {"b", 1}, - {"c", 2}, - {"d", 3}, + struct("a", 0), + struct("b", 1), + struct("c", 2), + struct("d", 3), ]) let add = fn(_, v, acc) { diff --git a/test/gleam/result_test.gleam b/test/gleam/result_test.gleam index 1eb241f..c513665 100644 --- a/test/gleam/result_test.gleam +++ b/test/gleam/result_test.gleam @@ -37,8 +37,8 @@ pub fn map_error_test() { |> expect:equal(_, Ok(1)) Error(1) - |> result:map_error(_, fn(x) { {"ok", x + 1} }) - |> expect:equal(_, Error({"ok", 2})) + |> result:map_error(_, fn(x) { struct("ok", x + 1) }) + |> expect:equal(_, Error(struct("ok", 2))) } pub fn flatten_test() { diff --git a/test/gleam/tuple_test.gleam b/test/gleam/tuple_test.gleam index a5530e7..398967b 100644 --- a/test/gleam/tuple_test.gleam +++ b/test/gleam/tuple_test.gleam @@ -3,32 +3,32 @@ import gleam/tuple pub fn new_test() { tuple:new(1, 2) - |> expect:equal(_, {1, 2}) + |> expect:equal(_, struct(1, 2)) tuple:new(2, "3") - |> expect:equal(_, {2, "3"}) + |> expect:equal(_, struct(2, "3")) } pub fn first_test() { - {1, 2} + struct(1, 2) |> tuple:first |> expect:equal(_, 1) } pub fn second_test() { - {1, 2} + struct(1, 2) |> tuple:second |> expect:equal(_, 2) } pub fn swap_test() { - {1, "2"} + struct(1, "2") |> tuple:swap - |> expect:equal(_, {"2", 1}) + |> expect:equal(_, struct("2", 1)) } pub fn fetch_test() { - let proplist = [{0, "1"}, {1, "2"}] + let proplist = [struct(0, "1"), struct(1, "2")] proplist |> tuple:fetch(_, 0) |