aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2018-01-15 14:31:53 +0100
committerBjörn Gustavsson <[email protected]>2018-01-15 14:31:53 +0100
commitfd30cdac0f62c70336330d94ac944bb110932cc2 (patch)
tree8038543b870dffc766a9508130ba65ab2a071874 /lib
parent43902ae7e7c03f174e4f1c2620f9d1b73a56ec65 (diff)
parenta0933c17ff0743fbd284856cdfd2f50ac511f8f5 (diff)
downloadotp-fd30cdac0f62c70336330d94ac944bb110932cc2.tar.gz
otp-fd30cdac0f62c70336330d94ac944bb110932cc2.tar.bz2
otp-fd30cdac0f62c70336330d94ac944bb110932cc2.zip
Merge branch 'bjorn/compiler/cuddle-with-tests'
* bjorn/compiler/cuddle-with-tests: beam_match_SUITE: Eliminate warnings for unused variables bs_match_SUITE: Add tests case written when walking into a dead end
Diffstat (limited to 'lib')
-rw-r--r--lib/compiler/test/bs_match_SUITE.erl68
1 files changed, 61 insertions, 7 deletions
diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl
index 7e1a432511..7557d6d57b 100644
--- a/lib/compiler/test/bs_match_SUITE.erl
+++ b/lib/compiler/test/bs_match_SUITE.erl
@@ -40,7 +40,7 @@
map_and_binary/1,unsafe_branch_caching/1,
bad_literals/1,good_literals/1,constant_propagation/1,
parse_xml/1,get_payload/1,escape/1,num_slots_different/1,
- check_bitstring_list/1,guard/1]).
+ beam_bsm/1,guard/1,is_ascii/1]).
-export([coverage_id/1,coverage_external_ignore/2]).
@@ -73,7 +73,7 @@ groups() ->
map_and_binary,unsafe_branch_caching,
bad_literals,good_literals,constant_propagation,parse_xml,
get_payload,escape,num_slots_different,
- check_bitstring_list,guard]}].
+ beam_bsm,guard,is_ascii]}].
init_per_suite(Config) ->
@@ -801,7 +801,7 @@ multiple_uses_cmp(<<_:16>>, <<_:16>>) -> false.
first_after(Data, Offset) ->
case byte_size(Data) > Offset of
false ->
- {First, Rest} = {ok, ok},
+ {_First, _Rest} = {ok, ok},
ok;
true ->
<<_:Offset/binary, Rest/binary>> = Data,
@@ -1515,7 +1515,7 @@ is_next_char_whitespace(<<C/utf8,_/binary>>) ->
{this_hdr = 17,
ext_hdr_opts}).
-get_payload(Config) ->
+get_payload(_Config) ->
<<3445:48>> = do_get_payload(#ext_header{ext_hdr_opts = <<3445:48>>}),
{'EXIT',_} = (catch do_get_payload(#ext_header{})),
ok.
@@ -1574,10 +1574,22 @@ lgettext(<<"de">>, <<"navigation">>, <<"Results">>) ->
lgettext(<<"de">>, <<"navigation">>, <<"Resources">>) ->
{ok, <<"Ressourcen">>}.
-%% Cover more code in beam_bsm.
-check_bitstring_list(_Config) ->
+%% Test more code in beam_bsm.
+beam_bsm(_Config) ->
true = check_bitstring_list(<<1:1,0:1,1:1,1:1>>, [1,0,1,1]),
false = check_bitstring_list(<<1:1,0:1,1:1,1:1>>, [0]),
+
+ true = bsm_validate_scheme(<<>>),
+ true = bsm_validate_scheme(<<5,10>>),
+ false = bsm_validate_scheme(<<5,10,11,12>>),
+ true = bsm_validate_scheme([]),
+ true = bsm_validate_scheme([5,10]),
+ false = bsm_validate_scheme([5,6,7]),
+
+ <<1,2,3>> = bsm_must_save_and_not_save(<<1,2,3>>, []),
+ D = fun(N) -> 2*N end,
+ [2,4|<<3>>] = bsm_must_save_and_not_save(<<1,2,3>>, [D,D]),
+
ok.
check_bitstring_list(<<H:1,T1/bitstring>>, [H|T2]) ->
@@ -1587,8 +1599,32 @@ check_bitstring_list(<<>>, []) ->
check_bitstring_list(_, _) ->
false.
+bsm_validate_scheme([]) -> true;
+bsm_validate_scheme([H|T]) ->
+ case bsm_is_scheme(H) of
+ true -> bsm_validate_scheme(T);
+ false -> false
+ end;
+bsm_validate_scheme(<<>>) -> true;
+bsm_validate_scheme(<<H, Rest/binary>>) ->
+ case bsm_is_scheme(H) of
+ true -> bsm_validate_scheme(Rest);
+ false -> false
+ end.
+
+bsm_is_scheme(Int) ->
+ Int rem 5 =:= 0.
+
+%% NOT OPTIMIZED: different control paths use different positions in the binary
+bsm_must_save_and_not_save(Bin, []) ->
+ Bin;
+bsm_must_save_and_not_save(<<H,T/binary>>, [F|Fs]) ->
+ [F(H)|bsm_must_save_and_not_save(T, Fs)];
+bsm_must_save_and_not_save(<<>>, []) ->
+ [].
+
guard(_Config) ->
- Tuple = id({a,b}),
+ _Tuple = id({a,b}),
ok = guard_1(<<1,2,3>>, {1,2,3}),
ok = guard_2(<<42>>, #{}),
ok.
@@ -1601,6 +1637,24 @@ guard_1(<<A,B,C>>, Tuple) when Tuple =:= {A,B,C} ->
guard_2(<<_>>, Healing) when Healing#{[] => Healing} =:= #{[] => #{}} ->
ok.
+is_ascii(_Config) ->
+ true = do_is_ascii(<<>>),
+ true = do_is_ascii(<<"string">>),
+ false = do_is_ascii(<<1024/utf8>>),
+ {'EXIT',{function_clause,_}} = (catch do_is_ascii(<<$A,0:3>>)),
+ {'EXIT',{function_clause,_}} = (catch do_is_ascii(<<16#80,0:3>>)),
+ ok.
+
+do_is_ascii(<<>>) ->
+ true;
+do_is_ascii(<<C,_/binary>>) when C >= 16#80 ->
+ %% This clause must fail to match if the size of the argument in
+ %% bits is not divisible by 8. Beware of unsafe optimizations.
+ false;
+do_is_ascii(<<_, T/binary>>) ->
+ do_is_ascii(T).
+
+
check(F, R) ->
R = F().