diff options
author | Björn-Egil Dahlberg <[email protected]> | 2014-03-26 14:19:55 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-03-26 14:19:55 +0100 |
commit | c5e3c774bd12cc15a04dd9880cad6eb66d2541be (patch) | |
tree | f2794368409e9af8854cd6a87c5c1e90c64ab97b /lib/compiler/test/map_SUITE.erl | |
parent | dbd429512ba3fe2db4dcca1a8d9357d173718e63 (diff) | |
parent | 2d95280094fa6429081a9b9df3c73705819e2461 (diff) | |
download | otp-c5e3c774bd12cc15a04dd9880cad6eb66d2541be.tar.gz otp-c5e3c774bd12cc15a04dd9880cad6eb66d2541be.tar.bz2 otp-c5e3c774bd12cc15a04dd9880cad6eb66d2541be.zip |
Merge branch 'egil/maps-compiler-coverage'
* egil/maps-compiler-coverage:
compiler: Do not evaluate map expressions with bad keys
compiler: Throw 'nomatch' on matching with bad binary keys
compiler: Variable keys are not allowed in Maps
compiler: Strengthen Maps warnings tests
compiler: map_pair cannot be a type clause in v3_life
compiler: Remove redudant code in v3_codegen
compiler: Test deep map structure
compiler: Remove redundant clause in v3_codegen
compiler: Cover #{ [] => Var } in testcase
Diffstat (limited to 'lib/compiler/test/map_SUITE.erl')
-rw-r--r-- | lib/compiler/test/map_SUITE.erl | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/compiler/test/map_SUITE.erl b/lib/compiler/test/map_SUITE.erl index 90eae6fb4f..cc018e4305 100644 --- a/lib/compiler/test/map_SUITE.erl +++ b/lib/compiler/test/map_SUITE.erl @@ -40,6 +40,8 @@ t_build_and_match_over_alloc/1, t_build_and_match_empty_val/1, t_build_and_match_val/1, + t_build_and_match_nil/1, + t_build_and_match_structure/1, %% errors in 17.0-rc1 t_update_values/1, @@ -68,6 +70,8 @@ all() -> [ t_build_and_match_over_alloc, t_build_and_match_empty_val, t_build_and_match_val, + t_build_and_match_nil, + t_build_and_match_structure, %% errors in 17.0-rc1 t_update_values, @@ -118,6 +122,7 @@ t_build_and_match_literals(Config) when is_list(Config) -> {'EXIT',{{badmatch,_},_}} = (catch (#{x:=3} = id({a,b,c}))), {'EXIT',{{badmatch,_},_}} = (catch (#{x:=3} = id(#{y=>3}))), {'EXIT',{{badmatch,_},_}} = (catch (#{x:=3} = id(#{x=>"three"}))), + {'EXIT',{badarg,_}} = (catch id(#{<<0:258>> =>"three"})), ok. t_build_and_match_aliasing(Config) when is_list(Config) -> @@ -234,7 +239,8 @@ t_update_assoc(Config) when is_list(Config) -> %% Errors cases. BadMap = id(badmap), {'EXIT',{badarg,_}} = (catch BadMap#{nonexisting=>val}), - + {'EXIT',{badarg,_}} = (catch <<>>#{nonexisting=>val}), + {'EXIT',{badarg,_}} = (catch M0#{<<0:257>> => val}), %% limitation ok. t_update_exact(Config) when is_list(Config) -> @@ -262,6 +268,8 @@ t_update_exact(Config) when is_list(Config) -> {'EXIT',{badarg,_}} = (catch M0#{1.0:=v,1.0=>v2}), {'EXIT',{badarg,_}} = (catch M0#{42.0:=v,42:=v2}), {'EXIT',{badarg,_}} = (catch M0#{42=>v1,42.0:=v2,42:=v3}), + {'EXIT',{badarg,_}} = (catch <<>>#{nonexisting:=val}), + {'EXIT',{badarg,_}} = (catch M0#{<<0:257>> := val}), %% limitation ok. t_update_values(Config) when is_list(Config) -> @@ -561,6 +569,32 @@ t_build_and_match_val(Config) when is_list(Config) -> test_server:fail({no_match, Other}) end. +t_build_and_match_nil(Config) when is_list(Config) -> + %% literals removed the coverage + V1 = id(cookie), + V2 = id(cake), + V3 = id(crisps), + + #{ [] := V1, "treat" := V2, {your,treat} := V3 } = id(#{ + {your,treat} => V3, + "treat" => V2, + [] => V1 }), + #{ [] := V3, [] := V3 } = id(#{ [] => V1, [] => V3 }), + ok. + +t_build_and_match_structure(Config) when is_list(Config) -> + V2 = id("it"), + S = id([42,{"hi", "=)", #{ "a" => 42, any => any, val => "get_" ++ V2}}]), + + %% match deep map values + V2 = case S of + [42,{"hi",_, #{ "a" := 42, val := "get_" ++ V1, any := _ }}] -> V1 + end, + %% match deep map + ok = case S of + [42,{"hi",_, #{ }}] -> ok + end, + ok. %% Use this function to avoid compile-time evaluation of an expression. id(I) -> I. |