aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gleam_stdlib.erl6
-rw-r--r--test/gleam/string_test.gleam7
2 files changed, 13 insertions, 0 deletions
diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl
index c6b5130..7414439 100644
--- a/src/gleam_stdlib.erl
+++ b/src/gleam_stdlib.erl
@@ -373,6 +373,12 @@ inspect(false) ->
"False";
inspect(nil) ->
"Nil";
+inspect(Data) when is_map(Data) ->
+ Fields = [
+ [<<"#(">>, inspect(Key), <<", ">>, inspect(Value), <<")">>]
+ || {Key, Value} <- maps:to_list(Data)
+ ],
+ ["map.from_list([", lists:join(", ", Fields), "])"];
inspect(Atom) when is_atom(Atom) ->
Binary = erlang:atom_to_binary(Atom),
case inspect_maybe_gleam_atom(Binary, none, <<>>) of
diff --git a/test/gleam/string_test.gleam b/test/gleam/string_test.gleam
index e1e2fcd..19341d0 100644
--- a/test/gleam/string_test.gleam
+++ b/test/gleam/string_test.gleam
@@ -1,4 +1,5 @@
import gleam/option.{None, Some}
+import gleam/map
import gleam/order
import gleam/should
import gleam/string
@@ -1086,3 +1087,9 @@ pub fn byte_size_test() {
let assert 8 = string.byte_size("👩🏾")
let assert 15 = string.byte_size("👩🏾‍🦰")
}
+
+pub fn inspect_map_test() {
+ map.from_list([#("a", 1), #("b", 2)])
+ |> string.inspect
+ |> should.equal("map.from_list([#(\"a\", 1), #(\"b\", 2)])")
+}