diff --git a/lib/compiler/test/zlc_SUITE.erl b/lib/compiler/test/zlc_SUITE.erl index 5fd001f88ed5..587ae9a02af0 100644 --- a/lib/compiler/test/zlc_SUITE.erl +++ b/lib/compiler/test/zlc_SUITE.erl @@ -90,9 +90,12 @@ zipwith4(F, As, Bs, Cs, Ds) -> dot(Xs, Ys) -> lists:sum([X*Y || X <- Xs && Y <- Ys]). -ifelse(Tests, Xs, Ys) -> % Simulate R's ifelse(,,) - [ case T of true -> X ; false -> Y end - || T <- Tests && X <- Xs && Y <- Ys +ifelse(Tests, Xs, Ys) -> + %% Simulate R's ifelse(,,) + [case T of + true -> X; + false -> Y + end || T <- Tests && X <- Xs && Y <- Ys ]. mixed_zlc(Config) when is_list(Config) -> @@ -171,17 +174,21 @@ filter_pattern(Config) when is_list(Config) -> [] = do_filter_pat_1([], []), [] = do_filter_pat_1([a], [a]), [] = do_filter_pat_1([{ok,a}], [{error,e}]), + [] = do_filter_pat_2([], []), [] = do_filter_pat_2([a], [b]), [] = do_filter_pat_2([{a,1}], [{b,1}]), [{1,7}] = do_filter_pat_2([{a,1}], [{a,7}]), [{1,7},{10,20}] = do_filter_pat_2([{a,1},{b,9},{x,10}], [{a,7},{wrong,8},{x,20}]), + ok. + do_filter_pat_1(L1, L2) -> Res = [{A,B} || {ok,A} <- L1 && {ok,B} <- L2], Res = [{A,B} || {{ok,A},{ok,B}} <- lists:zip(L1,L2)], Res. + do_filter_pat_2(L1, L2) -> Res = [{A,B} || {Same,A} <- L1 && {Same,B} <- L2], Res = [{A,B} || {{Same,A},{Same,B}} <- lists:zip(L1,L2)], @@ -245,21 +252,48 @@ strict_list(Config) when is_list(Config) -> [] = strict_list_strict_2([], [], <<>>), [5,23] = strict_list_strict_2([{i,1},{i,2}], [{i,2},{i,7}], <<3,9>>), + ?assertEqual([2*I * 3*I + I || I <- Seq100], + strict_list_strict_2([{i,2*I} || I <- Seq100], + [{i,3*I} || I <- Seq100], + list_to_binary(Seq100))), {'EXIT',{{bad_generators,{[{i,2}],[{i,7}],<<9:7>>}},_}} = catch strict_list_strict_2([{i,1},{i,2}], [{i,2},{i,7}], <<3,9:7>>), - {'EXIT',{{bad_generators,{[],[],[]}},_}} = catch strict_list_strict_2([], [], []), + {'EXIT',{{bad_generators,{[],[],[]}},_}} = + catch strict_list_strict_2([], [], []), {'EXIT',{{bad_generators,{[{i,0}],[],<<>>}},_}} = catch strict_list_strict_2([{i,0}], [], <<>>), - {'EXIT',{{bad_generators,{[a],[],<<>>}},_}} = - catch strict_list_strict_2([a], [], <<>>), + {'EXIT',{{bad_generators,{[{i,0}],[{bad,5}],<<99>>}},_}} = + catch strict_list_strict_2([{i,0}], [{bad,5}], <<99>>), + {'EXIT',{{bad_generators,{[{i,20}],[{i,21}],<<42:7>>}},_}} = + catch strict_list_strict_2([{i,20}], [{i,21}], <<42:7>>), [] = strict_list_strict_3([], <<>>), [45] = strict_list_strict_3([{i,42}], <<3>>), - {'EXIT',{{bad_generators,{[],<<0:7>>}},_}} = catch strict_list_strict_3([], <<0:7>>), + {'EXIT',{{bad_generators,{[],<<2>>}},_}} = + catch strict_list_strict_3([{i,1}], <<1,2>>), + {'EXIT',{{bad_generators,{[],<<0:7>>}},_}} = + catch strict_list_strict_3([], <<0:7>>), + {'EXIT',{{bad_generators,{[{i,1}],<<0:7>>}},_}} = + catch strict_list_strict_3([{i,1}], <<0:7>>), + [] = strict_list_strict_4([], <<>>), [100] = strict_list_strict_4([{i,100}], <<42>>), - {'EXIT',{{bad_generators,{[{i,100}],<<0>>}},_}} = catch strict_list_strict_4([{i,100}], <<0>>), - {'EXIT',{{bad_generators,{[{i,100}],<<>>}},_}} = catch strict_list_strict_4([{i,100}], <<>>), + {'EXIT',{{bad_generators,{[{i,100}],<<0>>}},_}} = + catch strict_list_strict_4([{i,100}], <<0>>), + {'EXIT',{{bad_generators,{[{i,100}],<<>>}},_}} = + catch strict_list_strict_4([{i,100}], <<>>), + {'EXIT',{{bad_generators,{[{i,100}],<<0:8,1:1>>}},_}} = + catch strict_list_strict_4([{i,100}], <<0:8,1:1>>), + + NaN = <<-1:64/float>>, + [] = strict_list_5(<<>>, <<>>), + [3.14] = strict_list_5(<<0:1,1:1>>, <<32,0.0:32/float, 64,3.14:64/float>>), + {'EXIT',{{bad_generators,{<<0:1,1:1>>, + <<117,-1:117/signed,32,17.0:32/float>>}},_}} = + catch strict_list_5(<<0:1,1:1>>, <<117,-1:117, 32,17.0:32/float>>), + %% FIXME: The following succeeds when it shouldn't. + {'EXIT',{{bad_generators,{<<0:1>>,<<64,NaN/binary>>}},_}} = + catch strict_list_5(<<1:1,0:1>>, <<32,42.0:32/float, 64,NaN/binary>>), ok. @@ -282,6 +316,11 @@ strict_list_strict_3(List, Bin) -> strict_list_strict_4(List, Bin) -> [A || {i,A} <:- List && <<42:8>> <:= Bin]. +strict_list_5(Wanted, Floats) -> + Res = [F || <> <:= Wanted && <> <:= Floats, W =:= 1], + Res = [F || <<1:1>> <= Wanted && <> <:= Floats], + Res. + strict_binary(Config) when is_list(Config) -> Seq100 = lists:seq(1, 100), @@ -312,11 +351,22 @@ strict_binary(Config) when is_list(Config) -> {'EXIT',{{bad_generators,{<<0:1>>,{0,0,none},{0,{v,7},none}}},_}} = catch strict_binary_mixed_1(<<0:1>>, #{0 => 0}, #{0 => {v,7}}), + Island = ~"skärgårdsö", + IslandSeq = lists:seq(1, length([C || <> <= Island])), + ?assertEqual(<< <> || + {I,C} <:- lists:zip(IslandSeq, [C || <> <= Island]) >>, + strict_binary_utf8(IslandSeq, Island)), + {'EXIT',{{bad_generators,{[4,5,6,7,8],<<16#ff,16#ff,"def">>}},_}} = + catch strict_binary_utf8(lists:seq(1, 8), <<"abc",16#ff,16#ff,"def">>), + ok. strict_binary_1(Map, Bin) -> << <<(X*Y*Z):64>> || X := {val,Y} <:- Map && <> <:= Bin >>. +strict_binary_utf8(List, Bin) -> + << <> || I <:- List && <> <:= Bin >>. + strict_binary_mixed_1(Bin, MapA0, MapB0) -> MapA = maps:iterator(MapA0, ordered), MapB = maps:iterator(MapB0, ordered),