From 7ee650e7ebb7403aeb982c7c609a9679c89a5f46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 4 Nov 2024 15:22:53 +0100 Subject: [PATCH] Add more tests --- lib/compiler/test/zlc_SUITE.erl | 40 +++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/compiler/test/zlc_SUITE.erl b/lib/compiler/test/zlc_SUITE.erl index 7fbb9f9b34cd..5fd001f88ed5 100644 --- a/lib/compiler/test/zlc_SUITE.erl +++ b/lib/compiler/test/zlc_SUITE.erl @@ -27,6 +27,7 @@ strict_list/1,strict_binary/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}, @@ -203,6 +204,8 @@ cartesian(Config) when is_list(Config) -> ok. strict_list(Config) when is_list(Config) -> + Seq100 = lists:seq(1, 100), + [2,3,4] = [X+Y || X <:- [1,2,3] && Y <- [1,1,1]], [3,4] = [X+Y || X <:- [1,2,3] && Y <:- [1,1,1], X > 1], @@ -218,13 +221,14 @@ strict_list(Config) when is_list(Config) -> [15] = strict_list_mixed_2([{i,3}], #{{k,4} => {v,3}}), [15] = strict_list_mixed_2([{i,0},{i,3}], #{{a,0} => {a,0}, {k,4} => {v,3}}), - SimpleMap = #{{k,1} => {v,2}}, - %% How should a bad match of map generator be presented? - %% Maybe like this: {badmatches,{{a,3},{{k,1},{v,2}}}} + ?assertEqual([I * 3*I + 7*I || I <- Seq100], + strict_list_mixed_2([{i,I} || I <- Seq100], + #{{k,3*I} => {v,7*I} || I <- Seq100})), + + SimpleMap = #{{k,1} => {v,2}}, {'EXIT',{{bad_generators,{[{a,3}],{{k,1},{v,2},none}}},_}} = catch strict_list_mixed_2([{a,3}], SimpleMap), - {'EXIT',{{bad_generators,{[],{{k,1},{v,2},none}}},_}} = catch strict_list_mixed_2([], SimpleMap), @@ -279,20 +283,48 @@ strict_list_strict_4(List, Bin) -> [A || {i,A} <:- List && <<42:8>> <:= Bin]. strict_binary(Config) when is_list(Config) -> + Seq100 = lists:seq(1, 100), + <<2,4,6>> = << <<(X+Y)>> || X <:- [1,2,3] && <> <= <<1,2,3>>>>, <<2,4>> = << <<(X+Y)>> || <> <:= <<1,2,3>> && {X, Y} <- [{1,1},{2,2},{2,3}]>>, <<2,24>> = << <<(X*Y*Z)>> || X := Y <:- #{1 => 2, 3 => 4} && <> <:= <<1,2>> >>, <<>> = strict_binary_1(#{}, <<>>), <<24:64>> = strict_binary_1(#{2 => {val,3}}, <<4:8>>), + ?assertEqual(<< <<(5*I * 3*I * I):64>> || I <- Seq100 >>, + strict_binary_1(maps:iterator(#{5*I => {val,3*I} || I <- Seq100}, ordered), + list_to_binary(Seq100))), {'EXIT',{{bad_generators,{none,<<42:8>>}},_}} = catch strict_binary_1(#{}, <<42:8>>), {'EXIT',{{bad_generators,{none,<<42:7>>}},_}} = catch strict_binary_1(#{}, <<42:7>>), {'EXIT',{{bad_generators,{none,<<0:4>>}},_}} = catch strict_binary_1(#{2 => {val,3}}, <<0,0:4>>), + + <<>> = strict_binary_mixed_1(<<>>, #{}, #{}), + <<>> = strict_binary_mixed_1(<<1:2>>, #{}, #{}), + <<999:64>> = strict_binary_mixed_1(<<1:1>>, #{0 => {v,0}}, #{1 => {v,999}}), + ?assertEqual(<< <> || I <- Seq100>>, + strict_binary_mixed_1(<<0:100>>, + #{I => {v,I} || I <- Seq100}, + #{I => {v,-I} || I <- Seq100})), + ?assertEqual(<< <<-I:64>> || I <- Seq100>>, + strict_binary_mixed_1(<<-1:100>>, + #{I => {v,I} || I <- Seq100}, + #{I => {v,-I} || I <- Seq100})), + {'EXIT',{{bad_generators,{<<0:1>>,{0,0,none},{0,{v,7},none}}},_}} = + catch strict_binary_mixed_1(<<0:1>>, #{0 => 0}, #{0 => {v,7}}), + ok. strict_binary_1(Map, Bin) -> << <<(X*Y*Z):64>> || X := {val,Y} <:- Map && <> <:= Bin >>. +strict_binary_mixed_1(Bin, MapA0, MapB0) -> + MapA = maps:iterator(MapA0, ordered), + MapB = maps:iterator(MapB0, ordered), + < <>; + 1 -> <> + end || <> <= Bin && _ := {v,V1} <:- MapA && _ := {v,V2} <- MapB>>. + nomatch(Config) when is_list(Config) -> [] = do_nomatch_1([], []), [] = do_nomatch_1([1], [a]),