aboutsummaryrefslogtreecommitdiff
path: root/src/gleam__stdlib.erl
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2019-03-17 14:34:07 +0000
committerLouis Pilfold <louis@lpil.uk>2019-03-17 14:34:07 +0000
commit00ff9767dc61e698aac791b43704cfce1ab33600 (patch)
tree257392f879a3524b04043e5385ca1ba871aa6908 /src/gleam__stdlib.erl
parentde6dca34edf5ab52bc7eab02745c59d8c0dd777d (diff)
downloadgleam_stdlib-00ff9767dc61e698aac791b43704cfce1ab33600.tar.gz
gleam_stdlib-00ff9767dc61e698aac791b43704cfce1ab33600.zip
stdlib atom
Diffstat (limited to 'src/gleam__stdlib.erl')
-rw-r--r--src/gleam__stdlib.erl18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/gleam__stdlib.erl b/src/gleam__stdlib.erl
index 25abb25..24668a7 100644
--- a/src/gleam__stdlib.erl
+++ b/src/gleam__stdlib.erl
@@ -1,13 +1,16 @@
-module(gleam__stdlib).
-include_lib("eunit/include/eunit.hrl").
--export([expect_equal/2, expect_not_equal/2, expect_true/1, expect_false/1, map_fetch/2,
- iodata_append/2, iodata_prepend/2, identity/1]).
+-export([expect_equal/2, expect_not_equal/2, expect_true/1, expect_false/1, expect_is_ok/1,
+ expect_is_error/1, atom_from_string/1, atom_create_from_string/1, atom_to_string/1,
+ map_fetch/2, iodata_append/2, iodata_prepend/2, identity/1]).
expect_equal(A, Expected) -> ?assertEqual(Expected, A).
expect_not_equal(A, Expected) -> ?assertNotEqual(Expected, A).
expect_true(A) -> ?assert(A).
expect_false(A) -> ?assertNot(A).
+expect_is_ok(A) -> ?assertMatch({ok, _}, A).
+expect_is_error(A) -> ?assertMatch({error, _}, A).
map_fetch(Map, Key) ->
case maps:find(Key, Map) of
@@ -15,6 +18,17 @@ map_fetch(Map, Key) ->
OkFound -> OkFound
end.
+atom_create_from_string(S) ->
+ binary_to_atom(S, utf8).
+
+atom_to_string(S) ->
+ atom_to_binary(S, utf8).
+
+atom_from_string(S) ->
+ try {ok, binary_to_existing_atom(S, utf8)} catch
+ error:badarg -> {error, atom_not_loaded}
+ end.
+
iodata_append(Iodata, String) -> [Iodata, String].
iodata_prepend(Iodata, String) -> [String, Iodata].