diff options
author | Louis Pilfold <louis@lpil.uk> | 2019-05-29 21:02:55 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2019-06-02 21:12:59 +0100 |
commit | 5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31 (patch) | |
tree | 5d0d281c66cf71c6e3ca880e6621138a71b95e7b /gen | |
parent | ee03f5a0465e176e220060164a5ffc408f73ed0d (diff) | |
download | gleam_stdlib-5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31.tar.gz gleam_stdlib-5a1f3494eb9517a7b7a332cb74dd10a6a7d32d31.zip |
Enable namespaced modules
Diffstat (limited to 'gen')
-rw-r--r-- | gen/src/std@any.erl (renamed from gen/src/any.erl) | 12 | ||||
-rw-r--r-- | gen/src/std@atom.erl (renamed from gen/src/atom.erl) | 2 | ||||
-rw-r--r-- | gen/src/std@bool.erl (renamed from gen/src/bool.erl) | 2 | ||||
-rw-r--r-- | gen/src/std@expect.erl (renamed from gen/src/expect.erl) | 2 | ||||
-rw-r--r-- | gen/src/std@float.erl (renamed from gen/src/float.erl) | 4 | ||||
-rw-r--r-- | gen/src/std@http.erl (renamed from gen/src/http.erl) | 2 | ||||
-rw-r--r-- | gen/src/std@int.erl (renamed from gen/src/int.erl) | 2 | ||||
-rw-r--r-- | gen/src/std@iodata.erl (renamed from gen/src/iodata.erl) | 2 | ||||
-rw-r--r-- | gen/src/std@list.erl (renamed from gen/src/list.erl) | 4 | ||||
-rw-r--r-- | gen/src/std@map_dict.erl (renamed from gen/src/map_dict.erl) | 4 | ||||
-rw-r--r-- | gen/src/std@order.erl (renamed from gen/src/order.erl) | 2 | ||||
-rw-r--r-- | gen/src/std@result.erl (renamed from gen/src/result.erl) | 2 | ||||
-rw-r--r-- | gen/src/std@string.erl | 28 | ||||
-rw-r--r-- | gen/src/std@tuple.erl | 28 | ||||
-rw-r--r-- | gen/src/str.erl | 25 | ||||
-rw-r--r-- | gen/src/tuple.erl | 28 | ||||
-rw-r--r-- | gen/test/any_test.erl | 97 | ||||
-rw-r--r-- | gen/test/atom_test.erl | 23 | ||||
-rw-r--r-- | gen/test/bool_test.erl | 30 | ||||
-rw-r--r-- | gen/test/float_test.erl | 42 | ||||
-rw-r--r-- | gen/test/int_test.erl | 29 | ||||
-rw-r--r-- | gen/test/iodata_test.erl | 52 | ||||
-rw-r--r-- | gen/test/list_test.erl | 183 | ||||
-rw-r--r-- | gen/test/map_dict_test.erl | 128 | ||||
-rw-r--r-- | gen/test/order_test.erl | 47 | ||||
-rw-r--r-- | gen/test/result_test.erl | 39 | ||||
-rw-r--r-- | gen/test/std@any_test.erl | 110 | ||||
-rw-r--r-- | gen/test/std@atom_test.erl | 24 | ||||
-rw-r--r-- | gen/test/std@bool_test.erl | 30 | ||||
-rw-r--r-- | gen/test/std@float_test.erl | 42 | ||||
-rw-r--r-- | gen/test/std@http_test.erl (renamed from gen/test/http_test.erl) | 2 | ||||
-rw-r--r-- | gen/test/std@int_test.erl | 29 | ||||
-rw-r--r-- | gen/test/std@iodata_test.erl | 57 | ||||
-rw-r--r-- | gen/test/std@list_test.erl | 196 | ||||
-rw-r--r-- | gen/test/std@map_dict_test.erl | 133 | ||||
-rw-r--r-- | gen/test/std@order_test.erl | 47 | ||||
-rw-r--r-- | gen/test/std@result_test.erl | 47 | ||||
-rw-r--r-- | gen/test/std@string_test.erl | 33 | ||||
-rw-r--r-- | gen/test/std@tuple_test.erl | 23 | ||||
-rw-r--r-- | gen/test/str_test.erl | 31 | ||||
-rw-r--r-- | gen/test/tuple_test.erl | 23 |
41 files changed, 848 insertions, 798 deletions
diff --git a/gen/src/any.erl b/gen/src/std@any.erl index 62be0c6..8aec08c 100644 --- a/gen/src/any.erl +++ b/gen/src/std@any.erl @@ -1,10 +1,10 @@ --module(any). +-module(std@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]). list_module() -> - list. + std@list. from(A) -> gleam__stdlib:identity(A). @@ -34,10 +34,10 @@ list_any(A) -> gleam__stdlib:decode_list(A). list(Any, Decode) -> - result:then(list_any(Any), - fun(Capture1) -> - (list_module()):traverse(Capture1, Decode) - end). + std@result:then(list_any(Any), + fun(Capture1) -> + (list_module()):traverse(Capture1, Decode) + end). tuple(A) -> gleam__stdlib:decode_tuple(A). diff --git a/gen/src/atom.erl b/gen/src/std@atom.erl index 450245a..a964101 100644 --- a/gen/src/atom.erl +++ b/gen/src/std@atom.erl @@ -1,4 +1,4 @@ --module(atom). +-module(std@atom). -compile(no_auto_import). -export([from_string/1, create_from_string/1, to_string/1]). diff --git a/gen/src/bool.erl b/gen/src/std@bool.erl index 47fba5d..c77a2d8 100644 --- a/gen/src/bool.erl +++ b/gen/src/std@bool.erl @@ -1,4 +1,4 @@ --module(bool). +-module(std@bool). -compile(no_auto_import). -export([negate/1, compare/2, max/2, min/2, to_int/1]). diff --git a/gen/src/expect.erl b/gen/src/std@expect.erl index 602f3fb..30b3156 100644 --- a/gen/src/expect.erl +++ b/gen/src/std@expect.erl @@ -1,4 +1,4 @@ --module(expect). +-module(std@expect). -compile(no_auto_import). -export([equal/2, not_equal/2, true/1, false/1, is_ok/1, is_error/1, fail/0]). diff --git a/gen/src/float.erl b/gen/src/std@float.erl index cd1385c..c627707 100644 --- a/gen/src/float.erl +++ b/gen/src/std@float.erl @@ -1,4 +1,4 @@ --module(float). +-module(std@float). -compile(no_auto_import). -export([parse/1, to_string/1, ceiling/1, floor/1, round/1, truncate/1]). @@ -7,7 +7,7 @@ parse(A) -> gleam__stdlib:parse_float(A). to_string(F) -> - iodata:to_string(iodata:from_float(F)). + std@iodata:to_string(std@iodata:from_float(F)). ceiling(A) -> math:ceil(A). diff --git a/gen/src/http.erl b/gen/src/std@http.erl index 6d2e42a..c141e95 100644 --- a/gen/src/http.erl +++ b/gen/src/std@http.erl @@ -1,4 +1,4 @@ --module(http). +-module(std@http). -compile(no_auto_import). -export([]). diff --git a/gen/src/int.erl b/gen/src/std@int.erl index 21ad7d3..9942040 100644 --- a/gen/src/int.erl +++ b/gen/src/std@int.erl @@ -1,4 +1,4 @@ --module(int). +-module(std@int). -compile(no_auto_import). -export([parse/1, to_string/1, to_base_string/2, compare/2]). diff --git a/gen/src/iodata.erl b/gen/src/std@iodata.erl index 540af1b..e115bbc 100644 --- a/gen/src/iodata.erl +++ b/gen/src/std@iodata.erl @@ -1,4 +1,4 @@ --module(iodata). +-module(std@iodata). -compile(no_auto_import). -export([prepend/2, append/2, prepend_iodata/2, append_iodata/2, from_strings/1, concat/1, new/1, to_string/1, byte_size/1, from_float/1, lowercase/1, uppercase/1, reverse/1, split/2, replace/3, is_equal/2, is_empty/1]). diff --git a/gen/src/list.erl b/gen/src/std@list.erl index 8df10f6..db2efae 100644 --- a/gen/src/list.erl +++ b/gen/src/std@list.erl @@ -1,4 +1,4 @@ --module(list). +-module(std@list). -compile(no_auto_import). -export([length/1, reverse/1, is_empty/1, contains/2, head/1, tail/1, filter/2, map/2, index_map/2, traverse/2, drop/2, take/2, new/0, append/2, flatten/1, fold/3, fold_right/3, find/2, all/2, any/2, zip/2, strict_zip/2, intersperse/2, at/2, unique/1, sort/1, range/2, repeat/2, split/2, split_while/2]). @@ -309,7 +309,7 @@ sort(List) -> end. range(Start, Stop) -> - case int:compare(Start, Stop) of + case std@int:compare(Start, Stop) of eq -> []; diff --git a/gen/src/map_dict.erl b/gen/src/std@map_dict.erl index 5155ec7..b736096 100644 --- a/gen/src/map_dict.erl +++ b/gen/src/std@map_dict.erl @@ -1,4 +1,4 @@ --module(map_dict). +-module(std@map_dict). -compile(no_auto_import). -export([size/1, to_list/1, from_list/1, has_key/2, new/0, fetch/2, put/3, map_values/2, keys/1, values/1, filter/2, take/2, merge/2, delete/2, drop/2, update/3, fold/3]). @@ -64,7 +64,7 @@ delete(Map, Key) -> erl_delete(Key, Map). drop(Map, Keys) -> - list:fold(Keys, Map, fun(Key, Acc) -> delete(Acc, Key) end). + std@list:fold(Keys, Map, fun(Key, Acc) -> delete(Acc, Key) end). update(Dict, Key, F) -> case fetch(Dict, Key) of diff --git a/gen/src/order.erl b/gen/src/std@order.erl index 7921740..3a816d5 100644 --- a/gen/src/order.erl +++ b/gen/src/std@order.erl @@ -1,4 +1,4 @@ --module(order). +-module(std@order). -compile(no_auto_import). -export([reverse/1, to_int/1, compare/2, max/2, min/2]). diff --git a/gen/src/result.erl b/gen/src/std@result.erl index cd66908..eccddfd 100644 --- a/gen/src/result.erl +++ b/gen/src/std@result.erl @@ -1,4 +1,4 @@ --module(result). +-module(std@result). -compile(no_auto_import). -export([is_ok/1, is_error/1, map/2, map_error/2, flatten/1, then/2, unwrap/2]). diff --git a/gen/src/std@string.erl b/gen/src/std@string.erl new file mode 100644 index 0000000..a86cfac --- /dev/null +++ b/gen/src/std@string.erl @@ -0,0 +1,28 @@ +-module(std@string). +-compile(no_auto_import). + +-export([length/1, lowercase/1, uppercase/1, reverse/1, split/2, replace/3, append/2]). + +length(A) -> + string:length(A). + +lowercase(A) -> + string:lowercase(A). + +uppercase(A) -> + string:uppercase(A). + +reverse(String) -> + std@iodata:to_string(std@iodata:reverse(std@iodata:new(String))). + +split(String, On) -> + std@list:map(std@iodata:split(std@iodata:new(String), On), + fun std@iodata:to_string/1). + +replace(String, Pattern, With) -> + std@iodata:to_string(std@iodata:replace(std@iodata:new(String), + Pattern, + With)). + +append(S1, S2) -> + std@iodata:to_string(std@iodata:append(std@iodata:new(S1), S2)). diff --git a/gen/src/std@tuple.erl b/gen/src/std@tuple.erl new file mode 100644 index 0000000..0c9e89d --- /dev/null +++ b/gen/src/std@tuple.erl @@ -0,0 +1,28 @@ +-module(std@tuple). +-compile(no_auto_import). + +-export([new/2, first/1, second/1, swap/1, fetch/2]). + +new(A, B) -> + {A, B}. + +first(Tup) -> + {A, _} = Tup, + A. + +second(Tup) -> + {_, A} = Tup, + A. + +swap(Tup) -> + {A, B} = Tup, + {B, A}. + +fetch(Haystack, Needle) -> + std@list:find(Haystack, fun(Tuple) -> case first(Tuple) =:= Needle of + true -> + {ok, second(Tuple)}; + + false -> + {error, []} + end end). diff --git a/gen/src/str.erl b/gen/src/str.erl deleted file mode 100644 index 153fd49..0000000 --- a/gen/src/str.erl +++ /dev/null @@ -1,25 +0,0 @@ --module(str). --compile(no_auto_import). - --export([length/1, lowercase/1, uppercase/1, reverse/1, split/2, replace/3, append/2]). - -length(A) -> - string:length(A). - -lowercase(A) -> - string:lowercase(A). - -uppercase(A) -> - string:uppercase(A). - -reverse(String) -> - iodata:to_string(iodata:reverse(iodata:new(String))). - -split(String, On) -> - list:map(iodata:split(iodata:new(String), On), fun iodata:to_string/1). - -replace(String, Pattern, With) -> - iodata:to_string(iodata:replace(iodata:new(String), Pattern, With)). - -append(S1, S2) -> - iodata:to_string(iodata:append(iodata:new(S1), S2)). diff --git a/gen/src/tuple.erl b/gen/src/tuple.erl deleted file mode 100644 index fe3ce03..0000000 --- a/gen/src/tuple.erl +++ /dev/null @@ -1,28 +0,0 @@ --module(tuple). --compile(no_auto_import). - --export([new/2, first/1, second/1, swap/1, fetch/2]). - -new(A, B) -> - {A, B}. - -first(Tup) -> - {A, _} = Tup, - A. - -second(Tup) -> - {_, A} = Tup, - A. - -swap(Tup) -> - {A, B} = Tup, - {B, A}. - -fetch(Haystack, Needle) -> - list:find(Haystack, fun(Tuple) -> case first(Tuple) =:= Needle of - true -> - {ok, second(Tuple)}; - - false -> - {error, []} - end end). diff --git a/gen/test/any_test.erl b/gen/test/any_test.erl deleted file mode 100644 index 6e5bd73..0000000 --- a/gen/test/any_test.erl +++ /dev/null @@ -1,97 +0,0 @@ --module(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]). - -string_test() -> - expect:equal(any:string(any:from(<<"">>)), {ok, <<"">>}), - expect:equal(any:string(any:from(<<"Hello">>)), {ok, <<"Hello">>}), - expect:equal(any:string(any:from(1)), - {error, <<"Expected a String, got `1`">>}), - expect:equal(any:string(any:from([])), - {error, <<"Expected a String, got `[]`">>}). - -int_test() -> - expect:equal(any:int(any:from(1)), {ok, 1}), - expect:equal(any:int(any:from(2)), {ok, 2}), - expect:equal(any:int(any:from(1.0)), - {error, <<"Expected an Int, got `1.0`">>}), - expect:equal(any:int(any:from([])), - {error, <<"Expected an Int, got `[]`">>}). - -float_test() -> - expect:equal(any:float(any:from(1.0)), {ok, 1.0}), - expect:equal(any:float(any:from(2.2)), {ok, 2.2}), - expect:equal(any:float(any:from(1)), - {error, <<"Expected a Float, got `1`">>}), - expect:equal(any:float(any:from([])), - {error, <<"Expected a Float, got `[]`">>}). - -thunk_test() -> - expect:is_ok(any:thunk(any:from(fun() -> 1 end))), - expect:equal(result:map(any:thunk(any:from(fun() -> 1 end)), - fun(F) -> F() end), - {ok, any:from(1)}), - expect:is_error(any:thunk(any:from(fun(X) -> X end))), - expect:is_error(any:thunk(any:from(1))), - expect:is_error(any:thunk(any:from([]))). - -bool_test() -> - expect:equal(any:bool(any:from(true)), {ok, true}), - expect:equal(any:bool(any:from(false)), {ok, false}), - expect:equal(any:bool(any:from(1)), - {error, <<"Expected a Bool, got `1`">>}), - expect:equal(any:bool(any:from([])), - {error, <<"Expected a Bool, got `[]`">>}). - -atom_test() -> - expect:equal(any:atom(any:from(atom:create_from_string(<<"">>))), - {ok, atom:create_from_string(<<"">>)}), - expect:equal(any:atom(any:from(atom:create_from_string(<<"ok">>))), - {ok, atom:create_from_string(<<"ok">>)}), - expect:is_error(any:atom(any:from(1))), - expect:is_error(any:atom(any:from([]))). - -list_test() -> - expect:equal(any:list(any:from([]), fun any:string/1), {ok, []}), - expect:equal(any:list(any:from([]), fun any:int/1), {ok, []}), - expect:equal(any:list(any:from([1, 2, 3]), fun any:int/1), {ok, [1, 2, 3]}), - expect:equal(any:list(any:from([[1], [2], [3]]), - fun(Capture1) -> - any:list(Capture1, fun any:int/1) - end), - {ok, [[1], [2], [3]]}), - expect:is_error(any:list(any:from(1), fun any:string/1)), - expect:is_error(any:list(any:from(1.0), fun any:int/1)), - expect:is_error(any:list(any:from([<<"">>]), fun any:int/1)), - expect:is_error(any:list(any:from([any:from(1), any:from(<<"not an int">>)]), - fun any:int/1)). - -tuple_test() -> - expect:equal(any:tuple(any:from({1, []})), - {ok, {any:from(1), any:from([])}}), - expect:equal(any:tuple(any:from({<<"ok">>, <<"ok">>})), - {ok, {any:from(<<"ok">>), any:from(<<"ok">>)}}), - expect:is_error(any:tuple(any:from({1}))), - expect:is_error(any:tuple(any:from({1, 2, 3}))), - expect:equal(result:then(result:then(any:tuple(any:from({1, 2.0})), - fun(X) -> - result:map(any:int(tuple:first(X)), - fun(F) -> - {F, tuple:second(X)} - end) - end), - fun(X) -> - result:map(any:float(tuple:second(X)), - fun(F) -> {tuple:first(X), F} end) - end), - {ok, {1, 2.0}}). - -field_test() -> - {ok, OkAtom} = atom:from_string(<<"ok">>), - expect:equal(any:field(any:from(#{}#{ok => 1}), OkAtom), {ok, any:from(1)}), - expect:equal(any:field(any:from(#{}#{ok => 3}#{earlier => 2}), OkAtom), - {ok, any:from(3)}), - expect:is_error(any:field(any:from(#{}), OkAtom)), - expect:is_error(any:field(any:from(1), OkAtom)), - expect:is_error(any:field(any:from([]), [])). diff --git a/gen/test/atom_test.erl b/gen/test/atom_test.erl deleted file mode 100644 index ae9f76b..0000000 --- a/gen/test/atom_test.erl +++ /dev/null @@ -1,23 +0,0 @@ --module(atom_test). --compile(no_auto_import). - --export([from_string_test/0, create_from_string_test/0, to_string_test/0]). - -from_string_test() -> - expect:is_ok(atom:from_string(<<"ok">>)), - expect:is_ok(atom:from_string(<<"expect">>)), - expect:is_error(atom:from_string(<<"this is not an atom we have seen before">>)). - -create_from_string_test() -> - expect:equal({ok, atom:create_from_string(<<"ok">>)}, - atom:from_string(<<"ok">>)), - expect:equal({ok, atom:create_from_string(<<"expect">>)}, - atom:from_string(<<"expect">>)), - expect:equal({ok, - atom:create_from_string(<<"this is another atom we have not seen before">>)}, - atom:from_string(<<"this is another atom we have not seen before">>)). - -to_string_test() -> - expect:equal(atom:to_string(atom:create_from_string(<<"ok">>)), <<"ok">>), - expect:equal(atom:to_string(atom:create_from_string(<<"expect">>)), - <<"expect">>). diff --git a/gen/test/bool_test.erl b/gen/test/bool_test.erl deleted file mode 100644 index d2f0322..0000000 --- a/gen/test/bool_test.erl +++ /dev/null @@ -1,30 +0,0 @@ --module(bool_test). --compile(no_auto_import). - --export([negate_test/0, compare_test/0, max_test/0, min_test/0, to_int_test/0]). - -negate_test() -> - expect:false(bool:negate(true)), - expect:true(bool:negate(false)). - -compare_test() -> - expect:equal(bool:compare(true, true), eq), - expect:equal(bool:compare(true, false), gt), - expect:equal(bool:compare(false, false), eq), - expect:equal(bool:compare(false, true), lt). - -max_test() -> - expect:equal(bool:max(true, true), true), - expect:equal(bool:max(true, false), true), - expect:equal(bool:max(false, false), false), - expect:equal(bool:max(false, true), true). - -min_test() -> - expect:equal(bool:min(true, true), true), - expect:equal(bool:min(true, false), false), - expect:equal(bool:min(false, false), false), - expect:equal(bool:min(false, true), false). - -to_int_test() -> - expect:equal(bool:to_int(true), 1), - expect:equal(bool:to_int(false), 0). diff --git a/gen/test/float_test.erl b/gen/test/float_test.erl deleted file mode 100644 index 36eb3ad..0000000 --- a/gen/test/float_test.erl +++ /dev/null @@ -1,42 +0,0 @@ --module(float_test). --compile(no_auto_import). - --export([parse_test/0, to_string_test/0, ceiling_test/0, floor_test/0, round_test/0, truncate_test/0]). - -parse_test() -> - expect:equal(float:parse(<<"1.23">>), {ok, 1.23}), - expect:equal(float:parse(<<"5.0">>), {ok, 5.0}), - expect:equal(float:parse(<<"0.123456789">>), {ok, 0.123456789}), - expect:is_error(float:parse(<<"">>)), - expect:is_error(float:parse(<<"what">>)), - expect:is_error(float:parse(<<"1">>)). - -to_string_test() -> - expect:equal(float:to_string(123.0), <<"123.0">>), - expect:equal(float:to_string(-8.1), <<"-8.1">>). - -ceiling_test() -> - expect:equal(float:ceiling(8.1), 9.0), - expect:equal(float:ceiling(-8.1), -8.0), - expect:equal(float:ceiling(-8.0), -8.0). - -floor_test() -> - expect:equal(float:floor(8.1), 8.0), - expect:equal(float:floor(-8.1), -9.0), - expect:equal(float:floor(-8.0), -8.0). - -round_test() -> - expect:equal(float:round(8.1), 8), - expect:equal(float:round(8.4), 8), - expect:equal(float:round(8.499), 8), - expect:equal(float:round(8.5), 9), - expect:equal(float:round(-8.1), -8), - expect:equal(float:round(-7.5), -8). - -truncate_test() -> - expect:equal(float:truncate(8.1), 8), - expect:equal(float:truncate(8.4), 8), - expect:equal(float:truncate(8.499), 8), - expect:equal(float:truncate(8.5), 8), - expect:equal(float:truncate(-8.1), -8), - expect:equal(float:truncate(-7.5), -7). diff --git a/gen/test/int_test.erl b/gen/test/int_test.erl deleted file mode 100644 index 0d3163e..0000000 --- a/gen/test/int_test.erl +++ /dev/null @@ -1,29 +0,0 @@ --module(int_test). --compile(no_auto_import). - --export([to_string/0, parse/0, to_base_string/0, compare_test/0]). - -to_string() -> - expect:equal(int:to_string(123), <<"123">>), - expect:equal(int:to_string(-123), <<"-123">>), - expect:equal(int:to_string(123), <<"123">>). - -parse() -> - expect:equal(int:parse(<<"123">>), {ok, 123}), - expect:equal(int:parse(<<"-123">>), {ok, -123}), - expect:equal(int:parse(<<"0123">>), {ok, 123}), - expect:is_error(int:parse(<<"">>)), - expect:is_error(int:parse(<<"what">>)), - expect:is_error(int:parse(<<"1.23">>)). - -to_base_string() -> - expect:equal(int:to_base_string(100, 16), <<"64">>), - expect:equal(int:to_base_string(-100, 16), <<"-64">>). - -compare_test() -> - expect:equal(int:compare(0, 0), eq), - expect:equal(int:compare(1, 1), eq), - expect:equal(int:compare(0, 1), lt), - expect:equal(int:compare(-2, -1), lt), - expect:equal(int:compare(2, 1), gt), - expect:equal(int:compare(-1, -2), gt). diff --git a/gen/test/iodata_test.erl b/gen/test/iodata_test.erl deleted file mode 100644 index b996bec..0000000 --- a/gen/test/iodata_test.erl +++ /dev/null @@ -1,52 +0,0 @@ --module(iodata_test). --compile(no_auto_import). - --export([iodata_test/0, lowercase_test/0, uppercase_test/0, split_test/0, is_equal_test/0, is_empty_test/0]). - -iodata_test() -> - Data = iodata:prepend(iodata:append(iodata:append(iodata:new(<<"ello">>), - <<",">>), - <<" world!">>), - <<"H">>), - expect:equal(iodata:to_string(Data), <<"Hello, world!">>), - expect:equal(iodata:byte_size(Data), 13), - Data1 = iodata:prepend_iodata(iodata:append_iodata(iodata:append_iodata(iodata:new(<<"ello">>), - iodata:new(<<",">>)), - iodata:concat([iodata:new(<<" wo">>), - iodata:new(<<"rld!">>)])), - iodata:new(<<"H">>)), - expect:equal(iodata:to_string(Data1), <<"Hello, world!">>), - expect:equal(iodata:byte_size(Data1), 13). - -lowercase_test() -> - expect:equal(iodata:to_string(iodata:lowercase(iodata:from_strings([<<"Gleam">>, - <<"Gleam">>]))), - <<"gleamgleam">>). - -uppercase_test() -> - expect:equal(iodata:to_string(iodata:uppercase(iodata:from_strings([<<"Gleam">>, - <<"Gleam">>]))), - <<"GLEAMGLEAM">>). - -split_test() -> - expect:equal(iodata:split(iodata:new(<<"Gleam,Erlang,Elixir">>), <<",">>), - [iodata:new(<<"Gleam">>), - iodata:new(<<"Erlang">>), - iodata:new(<<"Elixir">>)]), - expect:equal(iodata:split(iodata:from_strings([<<"Gleam, Erl">>, - <<"ang,Elixir">>]), - <<", ">>), - [iodata:new(<<"Gleam">>), - iodata:from_strings([<<"Erl">>, <<"ang,Elixir">>])]). - -is_equal_test() -> - expect:true(iodata:is_equal(iodata:new(<<"12">>), - iodata:from_strings([<<"1">>, <<"2">>]))), - expect:true(iodata:is_equal(iodata:new(<<"12">>), iodata:new(<<"12">>))), - expect:false(iodata:is_equal(iodata:new(<<"12">>), iodata:new(<<"2">>))). - -is_empty_test() -> - expect:true(iodata:is_empty(iodata:new(<<"">>))), - expect:false(iodata:is_empty(iodata:new(<<"12">>))), - expect:true(iodata:is_empty(iodata:from_strings([]))), - expect:true(iodata:is_empty(iodata:from_strings([<<"">>, <<"">>]))). diff --git a/gen/test/list_test.erl b/gen/test/list_test.erl deleted file mode 100644 index 6cfe07f..0000000 --- a/gen/test/list_test.erl +++ /dev/null @@ -1,183 +0,0 @@ --module(list_test). --compile(no_auto_import). - --export([length_test/0, reverse_test/0, is_empty_test/0, contains_test/0, head_test/0, tail_test/0, filter_test/0, map_test/0, traverse_test/0, drop_test/0, take_test/0, new_test/0, append_test/0, flatten_test/0, fold_test/0, fold_right_test/0, find_test/0, all_test/0, any_test/0, zip_test/0, strict_zip_test/0, intersperse_test/0, at_test/0, unique_test/0, sort_test/0, index_map_test/0, range_test/0, repeat_test/0, split_test/0, split_while_test/0]). - -length_test() -> - expect:equal(list:length([]), 0), - expect:equal(list:length([1]), 1), - expect:equal(list:length([1, 1]), 2), - expect:equal(list:length([1, 1, 1]), 3). - -reverse_test() -> - expect:equal(list:reverse([]), []), - expect:equal(list:reverse([1, 2, 3, 4, 5]), [5, 4, 3, 2, 1]). - -is_empty_test() -> - expect:true(list:is_empty([])), - expect:false(list:is_empty([1])). - -contains_test() -> - expect:true(list:contains([0, 4, 5, 1], 1)), - expect:false(list:contains([0, 4, 5, 7], 1)), - expect:false(list:contains([], 1)). - -head_test() -> - expect:equal(list:head([0, 4, 5, 7]), {ok, 0}), - expect:is_error(list:head([])). - -tail_test() -> - expect:equal(list:tail([0, 4, 5, 7]), {ok, [4, 5, 7]}), - expect:equal(list:tail([0]), {ok, []}), - expect:is_error(list:tail([])). - -filter_test() -> - expect:equal(list:filter([], fun(_) -> true end), []), - expect:equal(list:filter([0, 4, 5, 7, 3], fun(_) -> true end), - [0, 4, 5, 7, 3]), - expect:equal(list:filter([0, 4, 5, 7, 3], fun(X) -> X > 4 end), [5, 7]), - expect:equal(list:filter([0, 4, 5, 7, 3], fun(X) -> X < 4 end), [0, 3]). - -map_test() -> - expect:equal(list:map([], fun(X) -> X * 2 end), []), - expect:equal(list:map([0, 4, 5, 7, 3], fun(X) -> X * 2 end), - [0, 8, 10, 14, 6]). - -traverse_test() -> - Fun = fun(X) -> case X =:= 6 orelse X =:= 5 orelse X =:= 4 of - true -> - {ok, X * 2}; - - false -> - {error, X} - end end, - expect:equal(list:traverse([5, 6, 5, 6], Fun), {ok, [10, 12, 10, 12]}), - expect:equal(list:traverse([4, 6, 5, 7, 3], Fun), {error, 7}). - -drop_test() -> - expect:equal(list:drop([], 5), []), - expect:equal(list:drop([1, 2, 3, 4, 5, 6, 7, 8], 5), [6, 7, 8]). - -take_test() -> - expect:equal(list:take([], 5), []), - expect:equal(list:take([1, 2, 3, 4, 5, 6, 7, 8], 5), [1, 2, 3, 4, 5]). - -new_test() -> - expect:equal(list:new(), []). - -append_test() -> - expect:equal(list:append([1], [2, 3]), [1, 2, 3]). - -flatten_test() -> - expect:equal(list:flatten([]), []), - expect:equal(list:flatten([[]]), []), - expect:equal(list:flatten([[], [], []]), []), - expect:equal(list:flatten([[1, 2], [], [3, 4]]), [1, 2, 3, 4]). - -fold_test() -> - expect:equal(list:fold([1, 2, 3], [], fun(X, Acc) -> [X | Acc] end), - [3, 2, 1]). - -fold_right_test() -> - expect:equal(list:fold_right([1, 2, 3], [], fun(X, Acc) -> [X | Acc] end), - [1, 2, 3]). - -find_test() -> - F = fun(X) -> case X of - 2 -> - {ok, 4}; - - _ -> - {error, 0} - end end, - expect:equal(list:find([1, 2, 3], F), {ok, 4}), - expect:equal(list:find([1, 3, 2], F), {ok, 4}), - expect:is_error(list:find([1, 3], F)). - -all_test() -> - expect:equal(list:all([1, 2, 3, 4, 5], fun(X) -> X > 0 end), true), - expect:equal(list:all([1, 2, 3, 4, 5], fun(X) -> X < 0 end), false), - expect:equal(list:all([], fun(_) -> false end), true). - -any_test() -> - expect:equal(list:any([1, 2, 3, 4, 5], fun(X) -> X =:= 2 end), true), - expect:equal(list:any([1, 2, 3, 4, 5], fun(X) -> X < 0 end), false), - expect:equal(list:any([], fun(_) -> false end), false). - -zip_test() -> - expect:equal(list:zip([], [1, 2, 3]), []), - expect:equal(list:zip([1, 2], []), []), - expect:equal(list:zip([1, 2, 3], [4, 5, 6]), [{1, 4}, {2, 5}, {3, 6}]), - expect:equal(list:zip([5, 6], [1, 2, 3]), [{5, 1}, {6, 2}]), - expect:equal(list:zip([5, 6, 7], [1, 2]), [{5, 1}, {6, 2}]). - -strict_zip_test() -> - expect:is_error(list:strict_zip([], [1, 2, 3])), - expect:is_error(list:strict_zip([1, 2], [])), - expect:equal(list:strict_zip([1, 2, 3], [4, 5, 6]), - {ok, [{1, 4}, {2, 5}, {3, 6}]}), - expect:is_error(list:strict_zip([5, 6], [1, 2, 3])), - expect:is_error(list:strict_zip([5, 6, 7], [1, 2])). - -intersperse_test() -> - expect:equal(list:intersperse([1, 2, 3], 4), [1, 4, 2, 4, 3]), - expect:equal(list:intersperse([], 2), []). - -at_test() -> - expect:equal(list:at([1, 2, 3], 2), {ok, 3}), - expect:is_error(list:at([1, 2, 3], 5)), - expect:is_error(list:at([], 0)), - expect:is_error(list:at([1, 2, 3, 4, 5, 6], -1)). - -unique_test() -> - expect:equal(list:unique([1, 1, 2, 3, 4, 4, 4, 5, 6]), [1, 2, 3, 4, 5, 6]), - expect:equal(list:unique([7, 1, 45, 6, 2, 47, 2, 7, 5]), - [7, 1, 45, 6, 2, 47, 5]), - expect:equal(list:unique([3, 4, 5]), [3, 4, 5]), - expect:equal(list:unique([]), []). - -sort_test() -> - expect:equal(list:sort([4, 3, 6, 5, 4]), [3, 4, 4, 5, 6]), - expect:equal(list:sort([]), []), - expect:equal(list:sort([{1, 2}, {4, 5}, {3, 2}]), [{1, 2}, {3, 2}, {4, 5}]). - -index_map_test() -> - expect:equal(list:index_map([3, 4, 5], fun(I, X) -> {I, X} end), - [{0, 3}, {1, 4}, {2, 5}]), - F = fun(I, X) -> str:append(X, int:to_string(I)) end, - expect:equal(list:index_map([<<"a">>, <<"b">>, <<"c">>], F), - [<<"a0">>, <<"b1">>, <<"c2">>]). - -range_test() -> - expect:equal(list:range(0, 0), []), - expect:equal(list:range(1, 1), []), - expect:equal(list:range(-1, -1), []), - expect:equal(list:range(0, 1), [0]), - expect:equal(list:range(0, 5), [0, 1, 2, 3, 4]), - expect:equal(list:range(1, -5), [1, 0, -1, -2, -3, -4]). - -repeat_test() -> - expect:equal(list:repeat(1, -10), []), - expect:equal(list:repeat(1, 0), []), - expect:equal(list:repeat(2, 3), [2, 2, 2]), - expect:equal(list:repeat(<<"x">>, 5), - [<<"x">>, <<"x">>, <<"x">>, <<"x">>, <<"x">>]). - -split_test() -> - expect:equal(list:split([], 0), {[], []}), - expect:equal(list:split([0, 1, 2, 3, 4], 0), {[], [0, 1, 2, 3, 4]}), - expect:equal(list:split([0, 1, 2, 3, 4], -2), {[], [0, 1, 2, 3, 4]}), - expect:equal(list:split([0, 1, 2, 3, 4], 1), {[0], [1, 2, 3, 4]}), - expect:equal(list:split([0, 1, 2, 3, 4], 3), {[0, 1, 2], [3, 4]}), - expect:equal(list:split([0, 1, 2, 3, 4], 9), {[0, 1, 2, 3, 4], []}). - -split_while_test() -> - expect:equal(list:split_while([], fun(X) -> X =< 5 end), {[], []}), - expect:equal(list:split_while([1, 2, 3, 4, 5], fun(X) -> X =< 5 end), - {[1, 2, 3, 4, 5], []}), - expect:equal(list:split_while([1, 2, 3, 4, 5], fun(X) -> X =:= 2 end), - {[], [1, 2, 3, 4, 5]}), - expect:equal(list:split_while([1, 2, 3, 4, 5], fun(X) -> X =< 3 end), - {[1, 2, 3], [4, 5]}), - expect:equal(list:split_while([1, 2, 3, 4, 5], fun(X) -> X =< -3 end), - {[], [1, 2, 3, 4, 5]}). diff --git a/gen/test/map_dict_test.erl b/gen/test/map_dict_test.erl deleted file mode 100644 index 03be65a..0000000 --- a/gen/test/map_dict_test.erl +++ /dev/null @@ -1,128 +0,0 @@ --module(map_dict_test). --compile(no_auto_import). - --export([from_list_test/0, has_key_test/0, new_test/0, fetch_test/0, put_test/0, map_values_test/0, keys_test/0, values_test/0, take_test/0, drop_test/0, merge_test/0, delete_test/0, update_test/0, fold_test/0]). - -from_list_test() -> - expect:equal(map_dict:size(map_dict:from_list([{4, 0}, {1, 0}])), 2). - -has_key_test() -> - expect:false(map_dict:has_key(map_dict:from_list([]), 1)), - expect:true(map_dict:has_key(map_dict:from_list([{1, 0}]), 1)), - expect:true(map_dict:has_key(map_dict:from_list([{4, 0}, {1, 0}]), 1)), - expect:false(map_dict:has_key(map_dict:from_list([{4, 0}, {1, 0}]), 0)). - -new_test() -> - expect:equal(map_dict:size(map_dict:new()), 0), - expect:equal(map_dict:to_list(map_dict:new()), []). - -fetch_test() -> - Proplist = [{4, 0}, {1, 1}], - M = map_dict:from_list(Proplist), - expect:equal(map_dict:fetch(M, 4), {ok, 0}), - expect:equal(map_dict:fetch(M, 1), {ok, 1}), - expect:is_error(map_dict:fetch(M, 2)). - -put_test() -> - expect:equal(map_dict:put(map_dict:put(map_dict:put(map_dict:new(), - <<"a">>, - 0), - <<"b">>, - 1), - <<"c">>, - 2), - map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 1}, - {<<"c">>, 2}])). - -map_values_test() -> - expect:equal(map_dict:map_values(map_dict:from_list([{1, 0}, - {2, 1}, - {3, 2}]), - fun(K, V) -> K + V end), - map_dict:from_list([{1, 1}, {2, 3}, {3, 5}])). - -keys_test() -> - expect:equal(map_dict:keys(map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 1}, - {<<"c">>, 2}])), - [<<"a">>, <<"b">>, <<"c">>]). - -values_test() -> - expect:equal(map_dict:values(map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 1}, - {<<"c">>, 2}])), - [0, 1, 2]). - -take_test() -> - expect:equal(map_dict:take(map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 1}, - {<<"c">>, 2}]), - [<<"a">>, <<"b">>, <<"d">>]), - map_dict:from_list([{<<"a">>, 0}, {<<"b">>, 1}])). - -drop_test() -> - expect:equal(map_dict:drop(map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 1}, - {<<"c">>, 2}]), - [<<"a">>, <<"b">>, <<"d">>]), - map_dict:from_list([{<<"c">>, 2}])). - -merge_test() -> - A = map_dict:from_list([{<<"a">>, 2}, {<<"c">>, 4}, {<<"d">>, 3}]), - B = map_dict:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]), - expect:equal(map_dict:merge(A, B), - map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 1}, - {<<"c">>, 2}, - {<<"d">>, 3}])), - expect:equal(map_dict:merge(B, A), - map_dict:from_list([{<<"a">>, 2}, - {<<"b">>, 1}, - {<<"c">>, 4}, - {<<"d">>, 3}])). - -delete_test() -> - expect:equal(map_dict:delete(map_dict:delete(map_dict:from_list([{<<"a">>, - 0}, - {<<"b">>, - 1}, - {<<"c">>, - 2}]), - <<"a">>), - <<"d">>), - map_dict:from_list([{<<"b">>, 1}, {<<"c">>, 2}])). - -update_test() -> - Dict = map_dict:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]), - IncOrZero = fun(X) -> case X of - {ok, I} -> - I + 1; - - {error, _} -> - 0 - end end, - expect:equal(map_dict:update(Dict, <<"a">>, IncOrZero), - map_dict:from_list([{<<"a">>, 1}, - {<<"b">>, 1}, - {<<"c">>, 2}])), - expect:equal(map_dict:update(Dict, <<"b">>, IncOrZero), - map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 2}, - {<<"c">>, 2}])), - expect:equal(map_dict:update(Dict, <<"z">>, IncOrZero), - map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 1}, - {<<"c">>, 2}, - {<<"z">>, 0}])). - -fold_test() -> - Dict = map_dict:from_list([{<<"a">>, 0}, - {<<"b">>, 1}, - {<<"c">>, 2}, - {<<"d">>, 3}]), - Add = fun(_, V, Acc) -> V + Acc end, - expect:equal(map_dict:fold(Dict, 0, Add), 6), - Concat = fun(K, _, Acc) -> str:append(Acc, K) end, - expect:equal(map_dict:fold(Dict, <<"">>, Concat), <<"abcd">>), - expect:equal(map_dict:fold(map_dict:from_list([]), 0, Add), 0). diff --git a/gen/test/order_test.erl b/gen/test/order_test.erl deleted file mode 100644 index 6559bd8..0000000 --- a/gen/test/order_test.erl +++ /dev/null @@ -1,47 +0,0 @@ --module(order_test). --compile(no_auto_import). - --export([reverse_test/0, to_int_test/0, compare_test/0, max_test/0, min_test/0]). - -reverse_test() -> - expect:equal(order:reverse(lt), gt), - expect:equal(order:reverse(eq), eq), - expect:equal(order:reverse(gt), lt). - -to_int_test() -> - expect:equal(order:to_int(lt), -1), - expect:equal(order:to_int(eq), 0), - expect:equal(order:to_int(gt), 1). - -compare_test() -> - expect:equal(order:compare(lt, lt), eq), - expect:equal(order:compare(lt, eq), lt), - expect:equal(order:compare(lt, gt), lt), - expect:equal(order:compare(eq, lt), gt), - expect:equal(order:compare(eq, eq), eq), - expect:equal(order:compare(eq, gt), lt), - expect:equal(order:compare(gt, lt), gt), - expect:equal(order:compare(gt, eq), gt), - expect:equal(order:compare(gt, gt), eq). - -max_test() -> - expect:equal(order:max(lt, lt), lt), - expect:equal(order:max(lt, eq), eq), - expect:equal(order:max(lt, gt), gt), - expect:equal(order:max(eq, lt), eq), - expect:equal(order:max(eq, eq), eq), - expect:equal(order:max(eq, gt), gt), - expect:equal(order:max(gt, lt), gt), - expect:equal(order:max(gt, eq), gt), - expect:equal(order:max(gt, gt), gt). - -min_test() -> - expect:equal(order:min(lt, lt), lt), - expect:equal(order:min(lt, eq), lt), - expect:equal(order:min(lt, gt), lt), - expect:equal(order:min(eq, lt), lt), - expect:equal(order:min(eq, eq), eq), - expect:equal(order:min(eq, gt), eq), - expect:equal(order:min(gt, lt), lt), - expect:equal(order:min(gt, eq), eq), - expect:equal(order:min(gt, gt), gt). diff --git a/gen/test/result_test.erl b/gen/test/result_test.erl deleted file mode 100644 index 090a744..0000000 --- a/gen/test/result_test.erl +++ /dev/null @@ -1,39 +0,0 @@ --module(result_test). --compile(no_auto_import). - --export([is_ok_test/0, is_error_test/0, map_test/0, map_error_test/0, flatten_test/0, then_test/0, unwrap_test/0]). - -is_ok_test() -> - expect:true(result:is_ok({ok, 1})), - expect:false(result:is_ok({error, 1})). - -is_error_test() -> - expect:false(result:is_error({ok, 1})), - expect:true(result:is_error({error, 1})). - -map_test() -> - expect:equal(result:map({ok, 1}, fun(X) -> X + 1 end), {ok, 2}), - expect:equal(result:map({ok, 1}, fun(_) -> <<"2">> end), {ok, <<"2">>}), - expect:equal(result:map({error, 1}, fun(X) -> X + 1 end), {error, 1}). - -map_error_test() -> - expect:equal(result:map_error({ok, 1}, fun(X) -> X + 1 end), {ok, 1}), - expect:equal(result:map_error({error, 1}, fun(X) -> X + 1 end), {error, 2}). - -flatten_test() -> - expect:equal(result:flatten({ok, {ok, 1}}), {ok, 1}), - expect:equal(result:flatten({ok, {error, 1}}), {error, 1}), - expect:equal(result:flatten({error, 1}), {error, 1}), - expect:equal(result:flatten({error, {error, 1}}), {error, {error, 1}}). - -then_test() -> - expect:equal(result:then({error, 1}, fun(X) -> {ok, X + 1} end), - {error, 1}), - expect:equal(result:then({ok, 1}, fun(X) -> {ok, X + 1} end), {ok, 2}), - expect:equal(result:then({ok, 1}, fun(_) -> {ok, <<"type change">>} end), - {ok, <<"type change">>}), - expect:equal(result:then({ok, 1}, fun(_) -> {error, 1} end), {error, 1}). - -unwrap_test() -> - expect:equal(result:unwrap({ok, 1}, 50), 1), - expect:equal(result:unwrap({error, <<"nope">>}, 50), 50). diff --git a/gen/test/std@any_test.erl b/gen/test/std@any_test.erl new file mode 100644 index 0000000..3164919 --- /dev/null +++ b/gen/test/std@any_test.erl @@ -0,0 +1,110 @@ +-module(std@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]). + +string_test() -> + std@expect:equal(std@any:string(std@any:from(<<"">>)), {ok, <<"">>}), + std@expect:equal(std@any:string(std@any:from(<<"Hello">>)), + {ok, <<"Hello">>}), + std@expect:equal(std@any:string(std@any:from(1)), + {error, <<"Expected a String, got `1`">>}), + std@expect:equal(std@any:string(std@any:from([])), + {error, <<"Expected a String, got `[]`">>}). + +int_test() -> + std@expect:equal(std@any:int(std@any:from(1)), {ok, 1}), + std@expect:equal(std@any:int(std@any:from(2)), {ok, 2}), + std@expect:equal(std@any:int(std@any:from(1.0)), + {error, <<"Expected an Int, got `1.0`">>}), + std@expect:equal(std@any:int(std@any:from([])), + {error, <<"Expected an Int, got `[]`">>}). + +float_test() -> + std@expect:equal(std@any:float(std@any:from(1.0)), {ok, 1.0}), + std@expect:equal(std@any:float(std@any:from(2.2)), {ok, 2.2}), + std@expect:equal(std@any:float(std@any:from(1)), + {error, <<"Expected a Float, got `1`">>}), + std@expect:equal(std@any:float(std@any:from([])), + {error, <<"Expected a Float, got `[]`">>}). + +thunk_test() -> + std@expect:is_ok(std@any:thunk(std@any:from(fun() -> 1 end))), + std@expect:equal(std@result:map(std@any:thunk(std@any:from(fun() -> 1 end)), + fun(F) -> F() end), + {ok, std@any:from(1)}), + std@expect:is_error(std@any:thunk(std@any:from(fun(X) -> X end))), + std@expect:is_error(std@any:thunk(std@any:from(1))), + std@expect:is_error(std@any:thunk(std@any:from([]))). + +bool_test() -> + std@expect:equal(std@any:bool(std@any:from(true)), {ok, true}), + std@expect:equal(std@any:bool(std@any:from(false)), {ok, false}), + std@expect:equal(std@any:bool(std@any:from(1)), + {error, <<"Expected a Bool, got `1`">>}), + std@expect:equal(std@any:bool(std@any:from([])), + {error, <<"Expected a Bool, got `[]`">>}). + +atom_test() -> + std@expect:equal(std@any:atom(std@any:from(std@atom:create_from_string(<<"">>))), + {ok, std@atom:create_from_string(<<"">>)}), + std@expect:equal(std@any:atom(std@any:from(std@atom:create_from_string(<<"ok">>))), + {ok, std@atom:create_from_string(<<"ok">>)}), + std@expect:is_error(std@any:atom(std@any:from(1))), + std@expect:is_error(std@any:atom(std@any:from([]))). + +list_test() -> + std@expect:equal(std@any:list(std@any:from([]), fun std@any:string/1), + {ok, []}), + std@expect:equal(std@any:list(std@any:from([]), fun std@any:int/1), + {ok, []}), + std@expect:equal(std@any:list(std@any:from([1, 2, 3]), fun std@any:int/1), + {ok, [1, 2, 3]}), + std@expect:equal(std@any:list(std@any:from([[1], [2], [3]]), + fun(Capture1) -> + std@any:list(Capture1, fun std@any:int/1) + end), + {ok, [[1], [2], [3]]}), + std@expect:is_error(std@any:list(std@any:from(1), fun std@any:string/1)), + std@expect:is_error(std@any:list(std@any:from(1.0), fun std@any:int/1)), + std@expect:is_error(std@any:list(std@any:from([<<"">>]), + fun std@any:int/1)), + std@expect:is_error(std@any:list(std@any:from([std@any:from(1), + std@any:from(<<"not an int">>)]), + fun std@any:int/1)). + +tuple_test() -> + std@expect:equal(std@any:tuple(std@any:from({1, []})), + {ok, {std@any:from(1), std@any:from([])}}), + std@expect:equal(std@any:tuple(std@any:from({<<"ok">>, <<"ok">>})), + {ok, {std@any:from(<<"ok">>), std@any:from(<<"ok">>)}}), + std@expect:is_error(std@any:tuple(std@any:from({1}))), + std@expect:is_error(std@any:tuple(std@any:from({1, 2, 3}))), + std@expect:equal(std@result:then(std@result:then(std@any:tuple(std@any:from({1, + 2.0})), + fun(X) -> + std@result:map(std@any:int(std@tuple:first(X)), + fun(F) -> + {F, + std@tuple:second(X)} + end) + end), + fun(X) -> + std@result:map(std@any:float(std@tuple:second(X)), + fun(F) -> + {std@tuple:first(X), + F} + end) + end), + {ok, {1, 2.0}}). + +field_test() -> + {ok, OkAtom} = std@atom:from_string(<<"ok">>), + std@expect:equal(std@any:field(std@any:from(#{}#{ok => 1}), OkAtom), + {ok, std@any:from(1)}), + std@expect:equal(std@any:field(std@any:from(#{}#{ok => 3}#{earlier => 2}), + OkAtom), + {ok, std@any:from(3)}), + std@expect:is_error(std@any:field(std@any:from(#{}), OkAtom)), + std@expect:is_error(std@any:field(std@any:from(1), OkAtom)), + std@expect:is_error(std@any:field(std@any:from([]), [])). diff --git a/gen/test/std@atom_test.erl b/gen/test/std@atom_test.erl new file mode 100644 index 0000000..20629d9 --- /dev/null +++ b/gen/test/std@atom_test.erl @@ -0,0 +1,24 @@ +-module(std@atom_test). +-compile(no_auto_import). + +-export([from_string_test/0, create_from_string_test/0, to_string_test/0]). + +from_string_test() -> + std@expect:is_ok(std@atom:from_string(<<"ok">>)), + std@expect:is_ok(std@atom:from_string(<<"expect">>)), + std@expect:is_error(std@atom:from_string(<<"this is not an atom we have seen before">>)). + +create_from_string_test() -> + std@expect:equal({ok, std@atom:create_from_string(<<"ok">>)}, + std@atom:from_string(<<"ok">>)), + std@expect:equal({ok, std@atom:create_from_string(<<"expect">>)}, + std@atom:from_string(<<"expect">>)), + std@expect:equal({ok, + std@atom:create_from_string(<<"this is another atom we have not seen before">>)}, + std@atom:from_string(<<"this is another atom we have not seen before">>)). + +to_string_test() -> + std@expect:equal(std@atom:to_string(std@atom:create_from_string(<<"ok">>)), + <<"ok">>), + std@expect:equal(std@atom:to_string(std@atom:create_from_string(<<"expect">>)), + <<"expect">>). diff --git a/gen/test/std@bool_test.erl b/gen/test/std@bool_test.erl new file mode 100644 index 0000000..0679cb1 --- /dev/null +++ b/gen/test/std@bool_test.erl @@ -0,0 +1,30 @@ +-module(std@bool_test). +-compile(no_auto_import). + +-export([negate_test/0, compare_test/0, max_test/0, min_test/0, to_int_test/0]). + +negate_test() -> + std@expect:false(std@bool:negate(true)), + std@expect:true(std@bool:negate(false)). + +compare_test() -> + std@expect:equal(std@bool:compare(true, true), eq), + std@expect:equal(std@bool:compare(true, false), gt), + std@expect:equal(std@bool:compare(false, false), eq), + std@expect:equal(std@bool:compare(false, true), lt). + +max_test() -> + std@expect:equal(std@bool:max(true, true), true), + std@expect:equal(std@bool:max(true, false), true), + std@expect:equal(std@bool:max(false, false), false), + std@expect:equal(std@bool:max(false, true), true). + +min_test() -> + std@expect:equal(std@bool:min(true, true), true), + std@expect:equal(std@bool:min(true, false), false), + std@expect:equal(std@bool:min(false, false), false), + std@expect:equal(std@bool:min(false, true), false). + +to_int_test() -> + std@expect:equal(std@bool:to_int(true), 1), + std@expect:equal(std@bool:to_int(false), 0). diff --git a/gen/test/std@float_test.erl b/gen/test/std@float_test.erl new file mode 100644 index 0000000..9136643 --- /dev/null +++ b/gen/test/std@float_test.erl @@ -0,0 +1,42 @@ +-module(std@float_test). +-compile(no_auto_import). + +-export([parse_test/0, to_string_test/0, ceiling_test/0, floor_test/0, round_test/0, truncate_test/0]). + +parse_test() -> + std@expect:equal(std@float:parse(<<"1.23">>), {ok, 1.23}), + std@expect:equal(std@float:parse(<<"5.0">>), {ok, 5.0}), + std@expect:equal(std@float:parse(<<"0.123456789">>), {ok, 0.123456789}), + std@expect:is_error(std@float:parse(<<"">>)), + std@expect:is_error(std@float:parse(<<"what">>)), + std@expect:is_error(std@float:parse(<<"1">>)). + +to_string_test() -> + std@expect:equal(std@float:to_string(123.0), <<"123.0">>), + std@expect:equal(std@float:to_string(-8.1), <<"-8.1">>). + +ceiling_test() -> + std@expect:equal(std@float:ceiling(8.1), 9.0), + std@expect:equal(std@float:ceiling(-8.1), -8.0), + std@expect:equal(std@float:ceiling(-8.0), -8.0). + +floor_test() -> + std@expect:equal(std@float:floor(8.1), 8.0), + std@expect:equal(std@float:floor(-8.1), -9.0), + std@expect:equal(std@float:floor(-8.0), -8.0). + +round_test() -> + std@expect:equal(std@float:round(8.1), 8), + std@expect:equal(std@float:round(8.4), 8), + std@expect:equal(std@float:round(8.499), 8), + std@expect:equal(std@float:round(8.5), 9), + std@expect:equal(std@float:round(-8.1), -8), + std@expect:equal(std@float:round(-7.5), -8). + +truncate_test() -> + std@expect:equal(std@float:truncate(8.1), 8), + std@expect:equal(std@float:truncate(8.4), 8), + std@expect:equal(std@float:truncate(8.499), 8), + std@expect:equal(std@float:truncate(8.5), 8), + std@expect:equal(std@float:truncate(-8.1), -8), + std@expect:equal(std@float:truncate(-7.5), -7). diff --git a/gen/test/http_test.erl b/gen/test/std@http_test.erl index 306f916..14e2b40 100644 --- a/gen/test/http_test.erl +++ b/gen/test/std@http_test.erl @@ -1,4 +1,4 @@ --module(http_test). +-module(std@http_test). -compile(no_auto_import). -export([]). diff --git a/gen/test/std@int_test.erl b/gen/test/std@int_test.erl new file mode 100644 index 0000000..9aa68f3 --- /dev/null +++ b/gen/test/std@int_test.erl @@ -0,0 +1,29 @@ +-module(std@int_test). +-compile(no_auto_import). + +-export([to_string/0, parse/0, to_base_string/0, compare_test/0]). + +to_string() -> + std@expect:equal(std@int:to_string(123), <<"123">>), + std@expect:equal(std@int:to_string(-123), <<"-123">>), + std@expect:equal(std@int:to_string(123), <<"123">>). + +parse() -> + std@expect:equal(std@int:parse(<<"123">>), {ok, 123}), + std@expect:equal(std@int:parse(<<"-123">>), {ok, -123}), + std@expect:equal(std@int:parse(<<"0123">>), {ok, 123}), + std@expect:is_error(std@int:parse(<<"">>)), + std@expect:is_error(std@int:parse(<<"what">>)), + std@expect:is_error(std@int:parse(<<"1.23">>)). + +to_base_string() -> + std@expect:equal(std@int:to_base_string(100, 16), <<"64">>), + std@expect:equal(std@int:to_base_string(-100, 16), <<"-64">>). + +compare_test() -> + std@expect:equal(std@int:compare(0, 0), eq), + std@expect:equal(std@int:compare(1, 1), eq), + std@expect:equal(std@int:compare(0, 1), lt), + std@expect:equal(std@int:compare(-2, -1), lt), + std@expect:equal(std@int:compare(2, 1), gt), + std@expect:equal(std@int:compare(-1, -2), gt). diff --git a/gen/test/std@iodata_test.erl b/gen/test/std@iodata_test.erl new file mode 100644 index 0000000..cdfe81f --- /dev/null +++ b/gen/test/std@iodata_test.erl @@ -0,0 +1,57 @@ +-module(std@iodata_test). +-compile(no_auto_import). + +-export([iodata_test/0, lowercase_test/0, uppercase_test/0, split_test/0, is_equal_test/0, is_empty_test/0]). + +iodata_test() -> + Data = std@iodata:prepend(std@iodata:append(std@iodata:append(std@iodata:new(<<"ello">>), + <<",">>), + <<" world!">>), + <<"H">>), + std@expect:equal(std@iodata:to_string(Data), <<"Hello, world!">>), + std@expect:equal(std@iodata:byte_size(Data), 13), + Data1 = std@iodata:prepend_iodata(std@iodata:append_iodata(std@iodata:append_iodata(std@iodata:new(<<"ello">>), + std@iodata:new(<<",">>)), + std@iodata:concat([std@iodata:new(<<" wo">>), + std@iodata:new(<<"rld!">>)])), + std@iodata:new(<<"H">>)), + std@expect:equal(std@iodata:to_string(Data1), <<"Hello, world!">>), + std@expect:equal(std@iodata:byte_size(Data1), 13). + +lowercase_test() -> + std@expect:equal(std@iodata:to_string(std@iodata:lowercase(std@iodata:from_strings([<<"Gleam">>, + <<"Gleam">>]))), + <<"gleamgleam">>). + +uppercase_test() -> + std@expect:equal(std@iodata:to_string(std@iodata:uppercase(std@iodata:from_strings([<<"Gleam">>, + <<"Gleam">>]))), + <<"GLEAMGLEAM">>). + +split_test() -> + std@expect:equal(std@iodata:split(std@iodata:new(<<"Gleam,Erlang,Elixir">>), + <<",">>), + [std@iodata:new(<<"Gleam">>), + std@iodata:new(<<"Erlang">>), + std@iodata:new(<<"Elixir">>)]), + std@expect:equal(std@iodata:split(std@iodata:from_strings([<<"Gleam, Erl">>, + <<"ang,Elixir">>]), + <<", ">>), + [std@iodata:new(<<"Gleam">>), + std@iodata:from_strings([<<"Erl">>, <<"ang,Elixir">>])]). + +is_equal_test() -> + std@expect:true(std@iodata:is_equal(std@iodata:new(<<"12">>), + std@iodata:from_strings([<<"1">>, + <<"2">>]))), + std@expect:true(std@iodata:is_equal(std@iodata:new(<<"12">>), + std@iodata:new(<<"12">>))), + std@expect:false(std@iodata:is_equal(std@iodata:new(<<"12">>), + std@iodata:new(<<"2">>))). + +is_empty_test() -> + std@expect:true(std@iodata:is_empty(std@iodata:new(<<"">>))), + std@expect:false(std@iodata:is_empty(std@iodata:new(<<"12">>))), + std@expect:true(std@iodata:is_empty(std@iodata:from_strings([]))), + std@expect:true(std@iodata:is_empty(std@iodata:from_strings([<<"">>, + <<"">>]))). diff --git a/gen/test/std@list_test.erl b/gen/test/std@list_test.erl new file mode 100644 index 0000000..d5dc281 --- /dev/null +++ b/gen/test/std@list_test.erl @@ -0,0 +1,196 @@ +-module(std@list_test). +-compile(no_auto_import). + +-export([length_test/0, reverse_test/0, is_empty_test/0, contains_test/0, head_test/0, tail_test/0, filter_test/0, map_test/0, traverse_test/0, drop_test/0, take_test/0, new_test/0, append_test/0, flatten_test/0, fold_test/0, fold_right_test/0, find_test/0, all_test/0, any_test/0, zip_test/0, strict_zip_test/0, intersperse_test/0, at_test/0, unique_test/0, sort_test/0, index_map_test/0, range_test/0, repeat_test/0, split_test/0, split_while_test/0]). + +length_test() -> + std@expect:equal(std@list:length([]), 0), + std@expect:equal(std@list:length([1]), 1), + std@expect:equal(std@list:length([1, 1]), 2), + std@expect:equal(std@list:length([1, 1, 1]), 3). + +reverse_test() -> + std@expect:equal(std@list:reverse([]), []), + std@expect:equal(std@list:reverse([1, 2, 3, 4, 5]), [5, 4, 3, 2, 1]). + +is_empty_test() -> + std@expect:true(std@list:is_empty([])), + std@expect:false(std@list:is_empty([1])). + +contains_test() -> + std@expect:true(std@list:contains([0, 4, 5, 1], 1)), + std@expect:false(std@list:contains([0, 4, 5, 7], 1)), + std@expect:false(std@list:contains([], 1)). + +head_test() -> + std@expect:equal(std@list:head([0, 4, 5, 7]), {ok, 0}), + std@expect:is_error(std@list:head([])). + +tail_test() -> + std@expect:equal(std@list:tail([0, 4, 5, 7]), {ok, [4, 5, 7]}), + std@expect:equal(std@list:tail([0]), {ok, []}), + std@expect:is_error(std@list:tail([])). + +filter_test() -> + std@expect:equal(std@list:filter([], fun(_) -> true end), []), + std@expect:equal(std@list:filter([0, 4, 5, 7, 3], fun(_) -> true end), + [0, 4, 5, 7, 3]), + std@expect:equal(std@list:filter([0, 4, 5, 7, 3], fun(X) -> X > 4 end), + [5, 7]), + std@expect:equal(std@list:filter([0, 4, 5, 7, 3], fun(X) -> X < 4 end), + [0, 3]). + +map_test() -> + std@expect:equal(std@list:map([], fun(X) -> X * 2 end), []), + std@expect:equal(std@list:map([0, 4, 5, 7, 3], fun(X) -> X * 2 end), + [0, 8, 10, 14, 6]). + +traverse_test() -> + Fun = fun(X) -> case X =:= 6 orelse X =:= 5 orelse X =:= 4 of + true -> + {ok, X * 2}; + + false -> + {error, X} + end end, + std@expect:equal(std@list:traverse([5, 6, 5, 6], Fun), + {ok, [10, 12, 10, 12]}), + std@expect:equal(std@list:traverse([4, 6, 5, 7, 3], Fun), {error, 7}). + +drop_test() -> + std@expect:equal(std@list:drop([], 5), []), + std@expect:equal(std@list:drop([1, 2, 3, 4, 5, 6, 7, 8], 5), [6, 7, 8]). + +take_test() -> + std@expect:equal(std@list:take([], 5), []), + std@expect:equal(std@list:take([1, 2, 3, 4, 5, 6, 7, 8], 5), + [1, 2, 3, 4, 5]). + +new_test() -> + std@expect:equal(std@list:new(), []). + +append_test() -> + std@expect:equal(std@list:append([1], [2, 3]), [1, 2, 3]). + +flatten_test() -> + std@expect:equal(std@list:flatten([]), []), + std@expect:equal(std@list:flatten([[]]), []), + std@expect:equal(std@list:flatten([[], [], []]), []), + std@expect:equal(std@list:flatten([[1, 2], [], [3, 4]]), [1, 2, 3, 4]). + +fold_test() -> + std@expect:equal(std@list:fold([1, 2, 3], [], fun(X, Acc) -> [X | Acc] end), + [3, 2, 1]). + +fold_right_test() -> + std@expect:equal(std@list:fold_right([1, 2, 3], + [], + fun(X, Acc) -> [X | Acc] end), + [1, 2, 3]). + +find_test() -> + F = fun(X) -> case X of + 2 -> + {ok, 4}; + + _ -> + {error, 0} + end end, + std@expect:equal(std@list:find([1, 2, 3], F), {ok, 4}), + std@expect:equal(std@list:find([1, 3, 2], F), {ok, 4}), + std@expect:is_error(std@list:find([1, 3], F)). + +all_test() -> + std@expect:equal(std@list:all([1, 2, 3, 4, 5], fun(X) -> X > 0 end), true), + std@expect:equal(std@list:all([1, 2, 3, 4, 5], fun(X) -> X < 0 end), false), + std@expect:equal(std@list:all([], fun(_) -> false end), true). + +any_test() -> + std@expect:equal(std@list:any([1, 2, 3, 4, 5], fun(X) -> X =:= 2 end), + true), + std@expect:equal(std@list:any([1, 2, 3, 4, 5], fun(X) -> X < 0 end), false), + std@expect:equal(std@list:any([], fun(_) -> false end), false). + +zip_test() -> + std@expect:equal(std@list:zip([], [1, 2, 3]), []), + std@expect:equal(std@list:zip([1, 2], []), []), + std@expect:equal(std@list:zip([1, 2, 3], [4, 5, 6]), + [{1, 4}, {2, 5}, {3, 6}]), + std@expect:equal(std@list:zip([5, 6], [1, 2, 3]), [{5, 1}, {6, 2}]), + std@expect:equal(std@list:zip([5, 6, 7], [1, 2]), [{5, 1}, {6, 2}]). + +strict_zip_test() -> + std@expect:is_error(std@list:strict_zip([], [1, 2, 3])), + std@expect:is_error(std@list:strict_zip([1, 2], [])), + std@expect:equal(std@list:strict_zip([1, 2, 3], [4, 5, 6]), + {ok, [{1, 4}, {2, 5}, {3, 6}]}), + std@expect:is_error(std@list:strict_zip([5, 6], [1, 2, 3])), + std@expect:is_error(std@list:strict_zip([5, 6, 7], [1, 2])). + +intersperse_test() -> + std@expect:equal(std@list:intersperse([1, 2, 3], 4), [1, 4, 2, 4, 3]), + std@expect:equal(std@list:intersperse([], 2), []). + +at_test() -> + std@expect:equal(std@list:at([1, 2, 3], 2), {ok, 3}), + std@expect:is_error(std@list:at([1, 2, 3], 5)), + std@expect:is_error(std@list:at([], 0)), + std@expect:is_error(std@list:at([1, 2, 3, 4, 5, 6], -1)). + +unique_test() -> + std@expect:equal(std@list:unique([1, 1, 2, 3, 4, 4, 4, 5, 6]), + [1, 2, 3, 4, 5, 6]), + std@expect:equal(std@list:unique([7, 1, 45, 6, 2, 47, 2, 7, 5]), + [7, 1, 45, 6, 2, 47, 5]), + std@expect:equal(std@list:unique([3, 4, 5]), [3, 4, 5]), + std@expect:equal(std@list:unique([]), []). + +sort_test() -> + std@expect:equal(std@list:sort([4, 3, 6, 5, 4]), [3, 4, 4, 5, 6]), + std@expect:equal(std@list:sort([]), []), + std@expect:equal(std@list:sort([{1, 2}, {4, 5}, {3, 2}]), + [{1, 2}, {3, 2}, {4, 5}]). + +index_map_test() -> + std@expect:equal(std@list:index_map([3, 4, 5], fun(I, X) -> {I, X} end), + [{0, 3}, {1, 4}, {2, 5}]), + F = fun(I, X) -> std@string:append(X, std@int:to_string(I)) end, + std@expect:equal(std@list:index_map([<<"a">>, <<"b">>, <<"c">>], F), + [<<"a0">>, <<"b1">>, <<"c2">>]). + +range_test() -> + std@expect:equal(std@list:range(0, 0), []), + std@expect:equal(std@list:range(1, 1), []), + std@expect:equal(std@list:range(-1, -1), []), + std@expect:equal(std@list:range(0, 1), [0]), + std@expect:equal(std@list:range(0, 5), [0, 1, 2, 3, 4]), + std@expect:equal(std@list:range(1, -5), [1, 0, -1, -2, -3, -4]). + +repeat_test() -> + std@expect:equal(std@list:repeat(1, -10), []), + std@expect:equal(std@list:repeat(1, 0), []), + std@expect:equal(std@list:repeat(2, 3), [2, 2, 2]), + std@expect:equal(std@list:repeat(<<"x">>, 5), + [<<"x">>, <<"x">>, <<"x">>, <<"x">>, <<"x">>]). + +split_test() -> + std@expect:equal(std@list:split([], 0), {[], []}), + std@expect:equal(std@list:split([0, 1, 2, 3, 4], 0), {[], [0, 1, 2, 3, 4]}), + std@expect:equal(std@list:split([0, 1, 2, 3, 4], -2), + {[], [0, 1, 2, 3, 4]}), + std@expect:equal(std@list:split([0, 1, 2, 3, 4], 1), {[0], [1, 2, 3, 4]}), + std@expect:equal(std@list:split([0, 1, 2, 3, 4], 3), {[0, 1, 2], [3, 4]}), + std@expect:equal(std@list:split([0, 1, 2, 3, 4], 9), {[0, 1, 2, 3, 4], []}). + +split_while_test() -> + std@expect:equal(std@list:split_while([], fun(X) -> X =< 5 end), {[], []}), + std@expect:equal(std@list:split_while([1, 2, 3, 4, 5], fun(X) -> X =< 5 end), + {[1, 2, 3, 4, 5], []}), + std@expect:equal(std@list:split_while([1, 2, 3, 4, 5], + fun(X) -> X =:= 2 end), + {[], [1, 2, 3, 4, 5]}), + std@expect:equal(std@list:split_while([1, 2, 3, 4, 5], fun(X) -> X =< 3 end), + {[1, 2, 3], [4, 5]}), + std@expect:equal(std@list:split_while([1, 2, 3, 4, 5], + fun(X) -> X =< -3 end), + {[], [1, 2, 3, 4, 5]}). diff --git a/gen/test/std@map_dict_test.erl b/gen/test/std@map_dict_test.erl new file mode 100644 index 0000000..dc9b85f --- /dev/null +++ b/gen/test/std@map_dict_test.erl @@ -0,0 +1,133 @@ +-module(std@map_dict_test). +-compile(no_auto_import). + +-export([from_list_test/0, has_key_test/0, new_test/0, fetch_test/0, put_test/0, map_values_test/0, keys_test/0, values_test/0, take_test/0, drop_test/0, merge_test/0, delete_test/0, update_test/0, fold_test/0]). + +from_list_test() -> + std@expect:equal(std@map_dict:size(std@map_dict:from_list([{4, 0}, {1, 0}])), + 2). + +has_key_test() -> + std@expect:false(std@map_dict:has_key(std@map_dict:from_list([]), 1)), + std@expect:true(std@map_dict:has_key(std@map_dict:from_list([{1, 0}]), 1)), + std@expect:true(std@map_dict:has_key(std@map_dict:from_list([{4, 0}, + {1, 0}]), + 1)), + std@expect:false(std@map_dict:has_key(std@map_dict:from_list([{4, 0}, + {1, 0}]), + 0)). + +new_test() -> + std@expect:equal(std@map_dict:size(std@map_dict:new()), 0), + std@expect:equal(std@map_dict:to_list(std@map_dict:new()), []). + +fetch_test() -> + Proplist = [{4, 0}, {1, 1}], + M = std@map_dict:from_list(Proplist), + std@expect:equal(std@map_dict:fetch(M, 4), {ok, 0}), + std@expect:equal(std@map_dict:fetch(M, 1), {ok, 1}), + std@expect:is_error(std@map_dict:fetch(M, 2)). + +put_test() -> + std@expect:equal(std@map_dict:put(std@map_dict:put(std@map_dict:put(std@map_dict:new(), + <<"a">>, + 0), + <<"b">>, + 1), + <<"c">>, + 2), + std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}])). + +map_values_test() -> + std@expect:equal(std@map_dict:map_values(std@map_dict:from_list([{1, 0}, + {2, 1}, + {3, 2}]), + fun(K, V) -> K + V end), + std@map_dict:from_list([{1, 1}, {2, 3}, {3, 5}])). + +keys_test() -> + std@expect:equal(std@map_dict:keys(std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}])), + [<<"a">>, <<"b">>, <<"c">>]). + +values_test() -> + std@expect:equal(std@map_dict:values(std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}])), + [0, 1, 2]). + +take_test() -> + std@expect:equal(std@map_dict:take(std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}]), + [<<"a">>, <<"b">>, <<"d">>]), + std@map_dict:from_list([{<<"a">>, 0}, {<<"b">>, 1}])). + +drop_test() -> + std@expect:equal(std@map_dict:drop(std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}]), + [<<"a">>, <<"b">>, <<"d">>]), + std@map_dict:from_list([{<<"c">>, 2}])). + +merge_test() -> + A = std@map_dict:from_list([{<<"a">>, 2}, {<<"c">>, 4}, {<<"d">>, 3}]), + B = std@map_dict:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]), + std@expect:equal(std@map_dict:merge(A, B), + std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}, + {<<"d">>, 3}])), + std@expect:equal(std@map_dict:merge(B, A), + std@map_dict:from_list([{<<"a">>, 2}, + {<<"b">>, 1}, + {<<"c">>, 4}, + {<<"d">>, 3}])). + +delete_test() -> + std@expect:equal(std@map_dict:delete(std@map_dict:delete(std@map_dict:from_list([{<<"a">>, + 0}, + {<<"b">>, + 1}, + {<<"c">>, + 2}]), + <<"a">>), + <<"d">>), + std@map_dict:from_list([{<<"b">>, 1}, {<<"c">>, 2}])). + +update_test() -> + Dict = std@map_dict:from_list([{<<"a">>, 0}, {<<"b">>, 1}, {<<"c">>, 2}]), + IncOrZero = fun(X) -> case X of + {ok, I} -> + I + 1; + + {error, _} -> + 0 + end end, + std@expect:equal(std@map_dict:update(Dict, <<"a">>, IncOrZero), + std@map_dict:from_list([{<<"a">>, 1}, + {<<"b">>, 1}, + {<<"c">>, 2}])), + std@expect:equal(std@map_dict:update(Dict, <<"b">>, IncOrZero), + std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 2}, + {<<"c">>, 2}])), + std@expect:equal(std@map_dict:update(Dict, <<"z">>, IncOrZero), + std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}, + {<<"z">>, 0}])). + +fold_test() -> + Dict = std@map_dict:from_list([{<<"a">>, 0}, + {<<"b">>, 1}, + {<<"c">>, 2}, + {<<"d">>, 3}]), + Add = fun(_, V, Acc) -> V + Acc end, + std@expect:equal(std@map_dict:fold(Dict, 0, Add), 6), + Concat = fun(K, _, Acc) -> std@string:append(Acc, K) end, + std@expect:equal(std@map_dict:fold(Dict, <<"">>, Concat), <<"abcd">>), + std@expect:equal(std@map_dict:fold(std@map_dict:from_list([]), 0, Add), 0). diff --git a/gen/test/std@order_test.erl b/gen/test/std@order_test.erl new file mode 100644 index 0000000..f702ff9 --- /dev/null +++ b/gen/test/std@order_test.erl @@ -0,0 +1,47 @@ +-module(std@order_test). +-compile(no_auto_import). + +-export([reverse_test/0, to_int_test/0, compare_test/0, max_test/0, min_test/0]). + +reverse_test() -> + std@expect:equal(std@order:reverse(lt), gt), + std@expect:equal(std@order:reverse(eq), eq), + std@expect:equal(std@order:reverse(gt), lt). + +to_int_test() -> + std@expect:equal(std@order:to_int(lt), -1), + std@expect:equal(std@order:to_int(eq), 0), + std@expect:equal(std@order:to_int(gt), 1). + +compare_test() -> + std@expect:equal(std@order:compare(lt, lt), eq), + std@expect:equal(std@order:compare(lt, eq), lt), + std@expect:equal(std@order:compare(lt, gt), lt), + std@expect:equal(std@order:compare(eq, lt), gt), + std@expect:equal(std@order:compare(eq, eq), eq), + std@expect:equal(std@order:compare(eq, gt), lt), + std@expect:equal(std@order:compare(gt, lt), gt), + std@expect:equal(std@order:compare(gt, eq), gt), + std@expect:equal(std@order:compare(gt, gt), eq). + +max_test() -> + std@expect:equal(std@order:max(lt, lt), lt), + std@expect:equal(std@order:max(lt, eq), eq), + std@expect:equal(std@order:max(lt, gt), gt), + std@expect:equal(std@order:max(eq, lt), eq), + std@expect:equal(std@order:max(eq, eq), eq), + std@expect:equal(std@order:max(eq, gt), gt), + std@expect:equal(std@order:max(gt, lt), gt), + std@expect:equal(std@order:max(gt, eq), gt), + std@expect:equal(std@order:max(gt, gt), gt). + +min_test() -> + std@expect:equal(std@order:min(lt, lt), lt), + std@expect:equal(std@order:min(lt, eq), lt), + std@expect:equal(std@order:min(lt, gt), lt), + std@expect:equal(std@order:min(eq, lt), lt), + std@expect:equal(std@order:min(eq, eq), eq), + std@expect:equal(std@order:min(eq, gt), eq), + std@expect:equal(std@order:min(gt, lt), lt), + std@expect:equal(std@order:min(gt, eq), eq), + std@expect:equal(std@order:min(gt, gt), gt). diff --git a/gen/test/std@result_test.erl b/gen/test/std@result_test.erl new file mode 100644 index 0000000..941f1ee --- /dev/null +++ b/gen/test/std@result_test.erl @@ -0,0 +1,47 @@ +-module(std@result_test). +-compile(no_auto_import). + +-export([is_ok_test/0, is_error_test/0, map_test/0, map_error_test/0, flatten_test/0, then_test/0, unwrap_test/0]). + +is_ok_test() -> + std@expect:true(std@result:is_ok({ok, 1})), + std@expect:false(std@result:is_ok({error, 1})). + +is_error_test() -> + std@expect:false(std@result:is_error({ok, 1})), + std@expect:true(std@result:is_error({error, 1})). + +map_test() -> + std@expect:equal(std@result:map({ok, 1}, fun(X) -> X + 1 end), {ok, 2}), + std@expect:equal(std@result:map({ok, 1}, fun(_) -> <<"2">> end), + {ok, <<"2">>}), + std@expect:equal(std@result:map({error, 1}, fun(X) -> X + 1 end), + {error, 1}). + +map_error_test() -> + std@expect:equal(std@result:map_error({ok, 1}, fun(X) -> X + 1 end), + {ok, 1}), + std@expect:equal(std@result:map_error({error, 1}, fun(X) -> X + 1 end), + {error, 2}). + +flatten_test() -> + std@expect:equal(std@result:flatten({ok, {ok, 1}}), {ok, 1}), + std@expect:equal(std@result:flatten({ok, {error, 1}}), {error, 1}), + std@expect:equal(std@result:flatten({error, 1}), {error, 1}), + std@expect:equal(std@result:flatten({error, {error, 1}}), + {error, {error, 1}}). + +then_test() -> + std@expect:equal(std@result:then({error, 1}, fun(X) -> {ok, X + 1} end), + {error, 1}), + std@expect:equal(std@result:then({ok, 1}, fun(X) -> {ok, X + 1} end), + {ok, 2}), + std@expect:equal(std@result:then({ok, 1}, + fun(_) -> {ok, <<"type change">>} end), + {ok, <<"type change">>}), + std@expect:equal(std@result:then({ok, 1}, fun(_) -> {error, 1} end), + {error, 1}). + +unwrap_test() -> + std@expect:equal(std@result:unwrap({ok, 1}, 50), 1), + std@expect:equal(std@result:unwrap({error, <<"nope">>}, 50), 50). diff --git a/gen/test/std@string_test.erl b/gen/test/std@string_test.erl new file mode 100644 index 0000000..b0cc46e --- /dev/null +++ b/gen/test/std@string_test.erl @@ -0,0 +1,33 @@ +-module(std@string_test). +-compile(no_auto_import). + +-export([length_test/0, lowercase_test/0, uppercase_test/0, reverse_test/0, split_test/0, replace_test/0, append_test/0]). + +length_test() -> + std@expect:equal(std@string:length(<<"ß↑e̊">>), 3), + std@expect:equal(std@string:length(<<"Gleam">>), 5), + std@expect:equal(std@string:length(<<"">>), 0). + +lowercase_test() -> + std@expect:equal(std@string:lowercase(<<"Gleam">>), <<"gleam">>). + +uppercase_test() -> + std@expect:equal(std@string:uppercase(<<"Gleam">>), <<"GLEAM">>). + +reverse_test() -> + std@expect:equal(std@string:reverse(<<"Gleam">>), <<"maelG">>). + +split_test() -> + std@expect:equal(std@string:split(<<"Gleam,Erlang,Elixir">>, <<",">>), + [<<"Gleam">>, <<"Erlang">>, <<"Elixir">>]), + std@expect:equal(std@string:split(<<"Gleam, Erlang,Elixir">>, <<", ">>), + [<<"Gleam">>, <<"Erlang,Elixir">>]). + +replace_test() -> + std@expect:equal(std@string:replace(<<"Gleam,Erlang,Elixir">>, + <<",">>, + <<"++">>), + <<"Gleam++Erlang++Elixir">>). + +append_test() -> + std@expect:equal(std@string:append(<<"Test">>, <<" Me">>), <<"Test Me">>). diff --git a/gen/test/std@tuple_test.erl b/gen/test/std@tuple_test.erl new file mode 100644 index 0000000..a401daf --- /dev/null +++ b/gen/test/std@tuple_test.erl @@ -0,0 +1,23 @@ +-module(std@tuple_test). +-compile(no_auto_import). + +-export([new_test/0, first_test/0, second_test/0, swap_test/0, fetch_test/0]). + +new_test() -> + std@expect:equal(std@tuple:new(1, 2), {1, 2}), + std@expect:equal(std@tuple:new(2, <<"3">>), {2, <<"3">>}). + +first_test() -> + std@expect:equal(std@tuple:first({1, 2}), 1). + +second_test() -> + std@expect:equal(std@tuple:second({1, 2}), 2). + +swap_test() -> + std@expect:equal(std@tuple:swap({1, <<"2">>}), {<<"2">>, 1}). + +fetch_test() -> + Proplist = [{0, <<"1">>}, {1, <<"2">>}], + std@expect:equal(std@tuple:fetch(Proplist, 0), {ok, <<"1">>}), + std@expect:equal(std@tuple:fetch(Proplist, 1), {ok, <<"2">>}), + std@expect:is_error(std@tuple:fetch(Proplist, 2)). diff --git a/gen/test/str_test.erl b/gen/test/str_test.erl deleted file mode 100644 index f6a16a3..0000000 --- a/gen/test/str_test.erl +++ /dev/null @@ -1,31 +0,0 @@ --module(str_test). --compile(no_auto_import). - --export([length_test/0, lowercase_test/0, uppercase_test/0, reverse_test/0, split_test/0, replace_test/0, append_test/0]). - -length_test() -> - expect:equal(str:length(<<"ß↑e̊">>), 3), - expect:equal(str:length(<<"Gleam">>), 5), - expect:equal(str:length(<<"">>), 0). - -lowercase_test() -> - expect:equal(str:lowercase(<<"Gleam">>), <<"gleam">>). - -uppercase_test() -> - expect:equal(str:uppercase(<<"Gleam">>), <<"GLEAM">>). - -reverse_test() -> - expect:equal(str:reverse(<<"Gleam">>), <<"maelG">>). - -split_test() -> - expect:equal(str:split(<<"Gleam,Erlang,Elixir">>, <<",">>), - [<<"Gleam">>, <<"Erlang">>, <<"Elixir">>]), - expect:equal(str:split(<<"Gleam, Erlang,Elixir">>, <<", ">>), - [<<"Gleam">>, <<"Erlang,Elixir">>]). - -replace_test() -> - expect:equal(str:replace(<<"Gleam,Erlang,Elixir">>, <<",">>, <<"++">>), - <<"Gleam++Erlang++Elixir">>). - -append_test() -> - expect:equal(str:append(<<"Test">>, <<" Me">>), <<"Test Me">>). diff --git a/gen/test/tuple_test.erl b/gen/test/tuple_test.erl deleted file mode 100644 index 2f6a1ce..0000000 --- a/gen/test/tuple_test.erl +++ /dev/null @@ -1,23 +0,0 @@ --module(tuple_test). --compile(no_auto_import). - --export([new_test/0, first_test/0, second_test/0, swap_test/0, fetch_test/0]). - -new_test() -> - expect:equal(tuple:new(1, 2), {1, 2}), - expect:equal(tuple:new(2, <<"3">>), {2, <<"3">>}). - -first_test() -> - expect:equal(tuple:first({1, 2}), 1). - -second_test() -> - expect:equal(tuple:second({1, 2}), 2). - -swap_test() -> - expect:equal(tuple:swap({1, <<"2">>}), {<<"2">>, 1}). - -fetch_test() -> - Proplist = [{0, <<"1">>}, {1, <<"2">>}], - expect:equal(tuple:fetch(Proplist, 0), {ok, <<"1">>}), - expect:equal(tuple:fetch(Proplist, 1), {ok, <<"2">>}), - expect:is_error(tuple:fetch(Proplist, 2)). |