aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-04-25 10:34:26 +0200
committerBjörn Gustavsson <[email protected]>2018-04-25 10:34:26 +0200
commit3682b7dab5a67843e54f0a93cc00a08b235c20c7 (patch)
treeba8c5d7d660c3ab387e2d250cf520e1b784cf3d9 /lib/compiler/test
parent0e669ed13e20d5d68aa617aacd807eca7268d070 (diff)
parentad72c0d37ffb214cac874f51ac29fe2cdb47a2a4 (diff)
downloadotp-3682b7dab5a67843e54f0a93cc00a08b235c20c7.tar.gz
otp-3682b7dab5a67843e54f0a93cc00a08b235c20c7.tar.bz2
otp-3682b7dab5a67843e54f0a93cc00a08b235c20c7.zip
Merge branch 'map-get-bif' of git://github.com/michalmuskala/otp
* 'map-get-bif' of git://github.com/michalmuskala/otp: Introduce map_get guard-safe function OTP-15037
Diffstat (limited to 'lib/compiler/test')
-rw-r--r--lib/compiler/test/map_SUITE.erl24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/compiler/test/map_SUITE.erl b/lib/compiler/test/map_SUITE.erl
index 3146c31c21..e98c295da6 100644
--- a/lib/compiler/test/map_SUITE.erl
+++ b/lib/compiler/test/map_SUITE.erl
@@ -36,7 +36,7 @@
t_guard_fun/1,
t_list_comprehension/1,
t_map_sort_literals/1,
- t_map_size/1,
+ t_map_size/1, t_map_get/1,
t_build_and_match_aliasing/1,
t_is_map/1,
@@ -91,7 +91,7 @@ all() ->
t_guard_receive, t_guard_receive_large,
t_guard_fun, t_list_comprehension,
t_map_sort_literals,
- t_map_size,
+ t_map_size, t_map_get,
t_build_and_match_aliasing,
t_is_map,
@@ -691,6 +691,26 @@ t_map_size(Config) when is_list(Config) ->
map_is_size(M,N) when map_size(M) =:= N -> true;
map_is_size(_,_) -> false.
+t_map_get(Config) when is_list(Config) ->
+ 1 = map_get(a, id(#{a=>1})),
+
+ {'EXIT',{{badkey,a},_}} = (catch map_get(a, #{})),
+ {'EXIT',{{badkey,a},_}} = (catch map_get(a, #{b=>1})),
+
+ M = #{"a"=>1, "b" => 2},
+ true = check_map_value(M, "a", 1),
+ false = check_map_value(M, "b", 1),
+ true = check_map_value(M#{"c"=>2}, "c", 2),
+ false = check_map_value(M#{"a"=>5}, "a", 1),
+
+ {'EXIT',{{badmap,[]},_}} = (catch map_get(a, [])),
+ {'EXIT',{{badmap,<<1,2,3>>},_}} = (catch map_get(a, <<1,2,3>>)),
+ {'EXIT',{{badmap,1},_}} = (catch map_get(a, 1)),
+ ok.
+
+check_map_value(Map, Key, Value) when map_get(Key, Map) =:= Value -> true;
+check_map_value(_, _, _) -> false.
+
t_is_map(Config) when is_list(Config) ->
true = is_map(#{}),
true = is_map(#{a=>1}),