diff options
Diffstat (limited to 'lib/stdlib/test/binary_module_SUITE.erl')
| -rw-r--r-- | lib/stdlib/test/binary_module_SUITE.erl | 142 | 
1 files changed, 89 insertions, 53 deletions
| diff --git a/lib/stdlib/test/binary_module_SUITE.erl b/lib/stdlib/test/binary_module_SUITE.erl index 32cec0db6f..70c946bdb9 100644 --- a/lib/stdlib/test/binary_module_SUITE.erl +++ b/lib/stdlib/test/binary_module_SUITE.erl @@ -3,16 +3,17 @@  %%  %% Copyright Ericsson AB 1997-2014. All Rights Reserved.  %% -%% The contents of this file are subject to the Erlang Public License, -%% Version 1.1, (the "License"); you may not use this file except in -%% compliance with the License. You should have received a copy of the -%% Erlang Public License along with this software. If not, it can be -%% retrieved online at http://www.erlang.org/. +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at  %% -%% Software distributed under the License is distributed on an "AS IS" -%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See -%% the License for the specific language governing rights and limitations -%% under the License. +%%     http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License.  %%  %% %CopyrightEnd%  %% @@ -506,12 +507,35 @@ do_interesting(Module) ->      ?line [<<1,2,3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>,  					   [<<4,5>>,<<7>>,<<8>>],  					   [global,trim]), +    ?line [<<1,2,3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, +					   [<<4,5>>,<<7>>,<<8>>], +					   [global,trim_all]),      ?line [<<1,2,3,4,5,6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>,  					       [<<4,5>>,<<7>>,<<8>>],  					       [global,trim,{scope,{0,4}}]),      ?line [<<1,2,3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>,  					       [<<4,5>>,<<7>>,<<8>>],  					       [global,trim,{scope,{0,5}}]), + +    ?line [<<>>,<<>>,<<3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, +					   [<<1>>,<<2>>,<<4,5>>], +					   [global,trim]), +    ?line [<<3>>,<<6,7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, +					   [<<1>>,<<2>>,<<4,5>>], +					   [global,trim_all]), + +    ?line [<<1,2,3>>,<<>>,<<7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, +					   [<<4,5>>,<<6>>], +					   [global,trim]), +    ?line [<<1,2,3>>,<<7,8>>] = Module:split(<<1,2,3,4,5,6,7,8>>, +					   [<<4,5>>,<<6>>], +					   [global,trim_all]), +    ?line [<<>>,<<>>,<<3>>,<<>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, +					   [<<1>>,<<2>>,<<4>>,<<5>>,<<7>>,<<8>>], +					   [global,trim]), +    ?line [<<3>>,<<6>>] = Module:split(<<1,2,3,4,5,6,7,8>>, +					   [<<1>>,<<2>>,<<4>>,<<5>>,<<7>>,<<8>>], +					   [global,trim_all]),      ?line badarg = ?MASK_ERROR(  		      Module:replace(<<1,2,3,4,5,6,7,8>>,  				     [<<4,5>>,<<7>>,<<8>>],<<99>>, @@ -970,43 +994,51 @@ random_parts(X,N) ->  random_ref_comp(doc) ->      ["Test pseudorandomly generated cases against reference imlementation"];  random_ref_comp(Config) when is_list(Config) -> -    ?line put(success_counter,0), -    ?line random:seed({1271,769940,559934}), -    ?line do_random_match_comp(5000,{1,40},{30,1000}), +    put(success_counter,0), +    random:seed({1271,769940,559934}), +    Nr = {1,40}, +    Hr = {30,1000}, +    I1 = 1500, +    I2 = 5, +    do_random_match_comp(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_match_comp2(5000,{1,40},{30,1000}), +    do_random_match_comp2(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_match_comp3(5000,{1,40},{30,1000}), +    do_random_match_comp3(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_match_comp4(5000,{1,40},{30,1000}), +    do_random_match_comp4(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_matches_comp(5000,{1,40},{30,1000}), +    do_random_matches_comp(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_matches_comp2(5000,{1,40},{30,1000}), +    do_random_matches_comp2(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_matches_comp3(5,{1,40},{30,1000}), -    ?line erts_debug:set_internal_state(available_internal_state,true), -    ?line io:format("oldlimit: ~p~n",[ erts_debug:set_internal_state(binary_loop_limit,100)]), -    ?line do_random_match_comp(5000,{1,40},{30,1000}), -    ?line do_random_matches_comp3(5,{1,40},{30,1000}), -    ?line io:format("limit was: ~p~n",[ erts_debug:set_internal_state(binary_loop_limit,default)]), -    ?line erts_debug:set_internal_state(available_internal_state,false), +    do_random_matches_comp3(I2,Nr,Hr), +    erts_debug:set_internal_state(available_internal_state,true), +    io:format("oldlimit: ~p~n",[ erts_debug:set_internal_state(binary_loop_limit,100)]), +    do_random_match_comp(I1,Nr,Hr), +    do_random_matches_comp3(I2,Nr,Hr), +    io:format("limit was: ~p~n",[ erts_debug:set_internal_state(binary_loop_limit,default)]), +    erts_debug:set_internal_state(available_internal_state,false),      ok.  random_ref_sr_comp(doc) ->      ["Test pseudorandomly generated cases against reference imlementation of split and replace"];  random_ref_sr_comp(Config) when is_list(Config) -> -    ?line put(success_counter,0), -    ?line random:seed({1271,769940,559934}), -    ?line do_random_split_comp(5000,{1,40},{30,1000}), +    put(success_counter,0), +    random:seed({1271,769940,559934}), +    Nr = {1,40}, +    Hr = {30,1000}, +    I1 = 1500, +    do_random_split_comp(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_replace_comp(5000,{1,40},{30,1000}), +    do_random_replace_comp(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_split_comp2(5000,{1,40},{30,1000}), +    do_random_split_comp2(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]), -    ?line do_random_replace_comp2(5000,{1,40},{30,1000}), +    do_random_replace_comp2(I1,Nr,Hr),      io:format("Number of successes: ~p~n",[get(success_counter)]),      ok. +  random_ref_fla_comp(doc) ->      ["Test pseudorandomly generated cases against reference imlementation of split and replace"];  random_ref_fla_comp(Config) when is_list(Config) -> @@ -1107,7 +1139,9 @@ do_random_matches_comp3(N,NeedleRange,HaystackRange) ->      Needles = [random_substring(NeedleRange,Haystack) ||  		  _ <- lists:duplicate(NumNeedles,a)],      RefRes = binref:matches(Haystack,Needles), -    true = do_matches_comp_loop(10000,Needles,Haystack, RefRes), +    RefRes = binary:matches(Haystack,Needles), +    Compiled = binary:compile_pattern(Needles), +    true = do_matches_comp_loop(10000,Compiled,Haystack, RefRes),      do_random_matches_comp3(N-1,NeedleRange,HaystackRange).  do_matches_comp_loop(0,_,_,_) -> @@ -1137,9 +1171,8 @@ do_matches_comp2(N,H,A) ->      end.  do_matches_comp(N,H) ->      A = ?MASK_ERROR(binref:matches(H,N)), -    B = ?MASK_ERROR(binref:matches(H,binref:compile_pattern(N))), -    C = ?MASK_ERROR(binary:matches(H,N)), -    D = ?MASK_ERROR(binary:matches(make_unaligned(H), +    B = ?MASK_ERROR(binary:matches(H,N)), +    C = ?MASK_ERROR(binary:matches(make_unaligned(H),  				   binary:compile_pattern([make_unaligned2(X) || X <- N]))),      if  	A =/= nomatch -> @@ -1147,14 +1180,14 @@ do_matches_comp(N,H) ->  	true ->  	    ok      end, -    case {(A =:= B), (B =:= C),(C =:= D)} of -	{true,true,true} -> +    case {(A =:= B), (B =:= C)} of +	{true,true} ->  	    true;  	_ ->  	    io:format("Failed to match ~p (needle) against ~s (haystack)~n",  		      [N,H]), -	    io:format("A:~p,~nB:~p,~n,C:~p,~n,D:~p.~n", -		      [A,B,C,D]), +	    io:format("A:~p,~nB:~p,~n,C:~p,~n", +		      [A,B,C]),  	    exit(mismatch)      end. @@ -1196,46 +1229,44 @@ do_random_match_comp4(N,NeedleRange,HaystackRange) ->  do_match_comp(N,H) ->      A = ?MASK_ERROR(binref:match(H,N)), -    B = ?MASK_ERROR(binref:match(H,binref:compile_pattern([N]))), -    C = ?MASK_ERROR(binary:match(make_unaligned(H),N)), -    D = ?MASK_ERROR(binary:match(H,binary:compile_pattern([N]))), -    E = ?MASK_ERROR(binary:match(H,binary:compile_pattern(make_unaligned(N)))), +    B = ?MASK_ERROR(binary:match(make_unaligned(H),N)), +    C = ?MASK_ERROR(binary:match(H,binary:compile_pattern([N]))), +    D = ?MASK_ERROR(binary:match(H,binary:compile_pattern(make_unaligned(N)))),      if  	A =/= nomatch ->  	    put(success_counter,get(success_counter)+1);  	true ->  	    ok      end, -    case {(A =:= B), (B =:= C),(C =:= D),(D =:= E)} of -	{true,true,true,true} -> +    case {(A =:= B), (B =:= C),(C =:= D)} of +	{true,true,true} ->  	    true;  	_ ->  	    io:format("Failed to match ~s (needle) against ~s (haystack)~n",  		      [N,H]), -	    io:format("A:~p,~nB:~p,~n,C:~p,~n,D:~p,E:~p.~n", -		      [A,B,C,D,E]), +	    io:format("A:~p,~nB:~p,~n,C:~p,~n,D:~p.~n", +		      [A,B,C,D]),  	    exit(mismatch)      end.  do_match_comp3(N,H) ->      A = ?MASK_ERROR(binref:match(H,N)), -    B = ?MASK_ERROR(binref:match(H,binref:compile_pattern(N))), -    C = ?MASK_ERROR(binary:match(H,N)), -    D = ?MASK_ERROR(binary:match(H,binary:compile_pattern(N))), +    B = ?MASK_ERROR(binary:match(H,N)), +    C = ?MASK_ERROR(binary:match(H,binary:compile_pattern(N))),      if  	A =/= nomatch ->  	    put(success_counter,get(success_counter)+1);  	true ->  	    ok      end, -    case {(A =:= B), (B =:= C),(C =:= D)} of -	{true,true,true} -> +    case {(A =:= B),(B =:= C)} of +	{true,true} ->  	    true;  	_ ->  	    io:format("Failed to match ~s (needle) against ~s (haystack)~n",  		      [N,H]), -	    io:format("A:~p,~nB:~p,~n,C:~p,~n,D:~p.~n", -		      [A,B,C,D]), +	    io:format("A:~p,~nB:~p,~n,C:~p.~n", +		      [A,B,C]),  	    exit(mismatch)      end. @@ -1247,6 +1278,8 @@ do_random_split_comp(N,NeedleRange,HaystackRange) ->      true = do_split_comp(Needle,Haystack,[]),      true = do_split_comp(Needle,Haystack,[global]),      true = do_split_comp(Needle,Haystack,[global,trim]), +    true = do_split_comp(Needle,Haystack,[global,trim_all]), +    true = do_split_comp(Needle,Haystack,[global,trim,trim_all]),      do_random_split_comp(N-1,NeedleRange,HaystackRange).  do_random_split_comp2(0,_,_) ->      ok; @@ -1257,6 +1290,9 @@ do_random_split_comp2(N,NeedleRange,HaystackRange) ->  		  _ <- lists:duplicate(NumNeedles,a)],      true = do_split_comp(Needles,Haystack,[]),      true = do_split_comp(Needles,Haystack,[global]), +    true = do_split_comp(Needles,Haystack,[global,trim]), +    true = do_split_comp(Needles,Haystack,[global,trim_all]), +    true = do_split_comp(Needles,Haystack,[global,trim,trim_all]),      do_random_split_comp2(N-1,NeedleRange,HaystackRange).  do_split_comp(N,H,Opts) -> | 
