Skip to content

Commit

Permalink
stdlib: Add doctests to maps
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi committed Jan 23, 2025
1 parent 998dfa1 commit 160684e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/stdlib/src/maps.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ _Example:_
```erlang
> Key = 1337,
Map = #{42 => value_two,1337 => "value one","a" => 1},
maps:get(Key,Map).
maps:get(Key, Map).
"value one"
```
""".
Expand Down Expand Up @@ -1042,7 +1042,7 @@ _Example:_
```erlang
> Map = #{a => 1, b => 2, c => 3}.
#{a => 1,b => 2,c => 3}
> I = maps:iterator(Map), ok.
> I = maps:iterator(Map, ordered), ok.
ok
> {K1, V1, I1} = maps:next(I), {K1, V1}.
{a,1}
Expand Down Expand Up @@ -1145,7 +1145,7 @@ _Examples:_
```erlang
> EvenOdd = fun(X) -> case X rem 2 of 0 -> even; 1 -> odd end end,
maps:groups_from_list(EvenOdd, [1, 2, 3]).
maps:groups_from_list(EvenOdd, [1, 2, 3]).
#{even => [2], odd => [1, 3]}
> maps:groups_from_list(fun erlang:length/1, ["ant", "buffalo", "cat", "dingo"]).
#{3 => ["ant", "cat"], 5 => ["dingo"], 7 => ["buffalo"]}
Expand Down Expand Up @@ -1195,8 +1195,8 @@ _Examples:_
```erlang
> EvenOdd = fun(X) -> case X rem 2 of 0 -> even; 1 -> odd end end,
> Square = fun(X) -> X * X end,
> maps:groups_from_list(EvenOdd, Square, [1, 2, 3]).
Square = fun(X) -> X * X end,
maps:groups_from_list(EvenOdd, Square, [1, 2, 3]).
#{even => [4], odd => [1, 9]}
> maps:groups_from_list(
fun erlang:length/1,
Expand Down
7 changes: 5 additions & 2 deletions lib/stdlib/test/maps_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
t_with_2/1,t_without_2/1,
t_intersect/1, t_intersect_with/1,
t_merge_with/1, t_from_keys/1,
error_info/1,
error_info/1, doctests/1,
t_from_list_kill_process/1,
t_from_keys_kill_process/1,
t_values_kill_process/1,
Expand Down Expand Up @@ -65,7 +65,7 @@ all() ->
t_with_2,t_without_2,
t_intersect, t_intersect_with,
t_merge_with, t_from_keys,
error_info,
error_info, doctests,
t_from_list_kill_process,
t_from_keys_kill_process,
t_values_kill_process,
Expand Down Expand Up @@ -1064,4 +1064,7 @@ error_info(_Config) ->
],
error_info_lib:test_error_info(maps, L).

doctests(_Config) ->
shell_docs:test(maps, []).

id(I) -> I.

0 comments on commit 160684e

Please sign in to comment.