diff options
author | Kostis Sagonas <[email protected]> | 2014-04-29 12:14:19 +0200 |
---|---|---|
committer | Kostis Sagonas <[email protected]> | 2014-04-29 12:14:19 +0200 |
commit | f6d5234c391a0ba834337c3e92ee5fb377834a32 (patch) | |
tree | b046b684620ca9eab0e3f880a7ee34c1e6397d17 /lib/hipe/test/maps_SUITE_data/maps_has_map_fields.erl | |
parent | 5a43eb383bdeb604fd8a891ffe34610c3fe6208b (diff) | |
download | otp-f6d5234c391a0ba834337c3e92ee5fb377834a32.tar.gz otp-f6d5234c391a0ba834337c3e92ee5fb377834a32.tar.bz2 otp-f6d5234c391a0ba834337c3e92ee5fb377834a32.zip |
Add five new test files for maps in the HiPE test suite
Diffstat (limited to 'lib/hipe/test/maps_SUITE_data/maps_has_map_fields.erl')
-rw-r--r-- | lib/hipe/test/maps_SUITE_data/maps_has_map_fields.erl | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/hipe/test/maps_SUITE_data/maps_has_map_fields.erl b/lib/hipe/test/maps_SUITE_data/maps_has_map_fields.erl new file mode 100644 index 0000000000..61653aa519 --- /dev/null +++ b/lib/hipe/test/maps_SUITE_data/maps_has_map_fields.erl @@ -0,0 +1,46 @@ +%% -*- erlang-indent-level: 2 -*- +%%------------------------------------------------------------------------- +-module(maps_has_map_fields). + +-export([test/0]). + +test() -> + false = has_a_field(#{}), + false = has_a_field(#{b => 2}), + true = has_a_field(#{a => 3}), + true = has_a_field(#{b => c, a => false}), + + false = has_a_b_field(#{a => true}), + false = has_a_b_field(#{b => a}), + true = has_a_b_field(#{a => 1, b => 2}), + true = has_a_b_field(#{b => 3, a => 4}), + + false = has_binary_field(#{}), + false = has_binary_field(#{#{} => yay}), + true = has_binary_field(#{<<"true">> => false}), + + false = has_binary_but_no_map_field(#{}), + false = has_map_but_no_binary_field(#{}), + false = has_binary_but_no_map_field(#{#{} => 1}), + false = has_map_but_no_binary_field(#{<<"true">> => true}), + true = has_binary_but_no_map_field(#{<<"true">> => false}), + true = has_map_but_no_binary_field(#{#{} => 1}), + false = has_binary_but_no_map_field(#{<<"true">> => true, #{} => 1}), + false = has_map_but_no_binary_field(#{<<"true">> => true, #{} => 1}), + ok. + +has_a_field(#{a := _}) -> true; +has_a_field(#{}) -> false. + +has_a_b_field(#{a := _, b := _}) -> true; +has_a_b_field(#{}) -> false. + +has_binary_field(#{<<"true">> := _}) -> true; +has_binary_field(#{}) -> false. + +has_map_but_no_binary_field(#{<<"true">> := _}) -> false; +has_map_but_no_binary_field(#{} = M) -> maps:is_key(#{}, M). + +has_binary_but_no_map_field(#{<<"true">> := _} = M) -> + not maps:is_key(#{}, M); +has_binary_but_no_map_field(#{}) -> false. |