diff options
Diffstat (limited to 'lib/stdlib/test/re_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/re_SUITE.erl | 456 |
1 files changed, 228 insertions, 228 deletions
diff --git a/lib/stdlib/test/re_SUITE.erl b/lib/stdlib/test/re_SUITE.erl index bcf40063f1..7458aec13e 100644 --- a/lib/stdlib/test/re_SUITE.erl +++ b/lib/stdlib/test/re_SUITE.erl @@ -72,195 +72,195 @@ pcre(Config) when is_list(Config) -> %% Test all documented compile options. compile_options(Config) when is_list(Config) -> - ?line ok = ctest("ABDabcdABCD","abcd",[],true,{match,[{3,4}]}), - ?line ok = ctest("ABDabcdABCD","abcd",[anchored],true,nomatch), - ?line ok = ctest("ABDabcdABCD",".*abcd",[anchored],true,{match,[{0,7}]}), - ?line ok = ctest("ABCabcdABC","ABCD",[],true,nomatch), - ?line ok = ctest("ABCabcdABC","ABCD",[caseless],true,{match,[{3,4}]}), - ?line ok = ctest("abcdABC\n","ABC$",[],true,{match,[{4,3}]}), - ?line ok = ctest("abcdABC\n","ABC$",[dollar_endonly],true,nomatch), - ?line ok = ctest("abcdABC\n","ABC.",[],true,nomatch), - ?line ok = ctest("abcdABC\n","ABC.",[dotall],true,{match,[{4,4}]}), - ?line ok = ctest("abcdABCD","ABC .",[],true,nomatch), - ?line ok = ctest("abcdABCD","ABC .",[extended],true,{match,[{4,4}]}), - ?line ok = ctest("abcd\nABCD","ABC",[],true,{match,[{5,3}]}), - ?line ok = ctest("abcd\nABCD","ABC",[firstline],true,nomatch), - ?line ok = ctest("abcd\nABCD","^ABC",[],true,nomatch), - ?line ok = ctest("abcd\nABCD","^ABC",[multiline],true,{match,[{5,3}]}), - ?line ok = ctest("abcdABCD","(ABC)",[],true,{match,[{4,3},{4,3}]}), - ?line ok = ctest("abcdABCD","(ABC)",[no_auto_capture],true,{match,[{4,3}]}), - ?line ok = ctest(notused,"(?<FOO>ABC)|(?<FOO>DEF)",[],false,notused), - ?line ok = ctest("abcdABCD","(?<FOO>ABC)|(?<FOO>DEF)",[dupnames],true,{match,[{4,3},{4,3}]}), - ?line ok = ctest("abcdABCDabcABCD","abcd.*D",[],true,{match,[{0,15}]}), - ?line ok = ctest("abcdABCDabcABCD","abcd.*D",[ungreedy],true,{match,[{0,8}]}), - ?line ok = ctest("abcdABCabcABC\nD","abcd.*D",[],true,nomatch), - ?line ok = ctest("abcdABCabcABC\nD","abcd.*D",[{newline,cr}],true,{match,[{0,15}]}), - ?line ok = ctest("abcdABCabcABC\rD","abcd.*D",[],true,{match,[{0,15}]}), - ?line ok = ctest("abcdABCabcABC\rD","abcd.*D",[{newline,lf}],true,{match,[{0,15}]}), - ?line ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,lf}],true,nomatch), - ?line ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,cr}],true,nomatch), - ?line ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,crlf}],true,{match,[{7,4}]}), - - ?line ok = ctest("abcdABCabcd\r","abcd$",[{newline,crlf}],true,nomatch), - ?line ok = ctest("abcdABCabcd\n","abcd$",[{newline,crlf}],true,nomatch), - ?line ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - - ?line ok = ctest("abcdABCabcd\r","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - ?line ok = ctest("abcdABCabcd\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + ok = ctest("ABDabcdABCD","abcd",[],true,{match,[{3,4}]}), + ok = ctest("ABDabcdABCD","abcd",[anchored],true,nomatch), + ok = ctest("ABDabcdABCD",".*abcd",[anchored],true,{match,[{0,7}]}), + ok = ctest("ABCabcdABC","ABCD",[],true,nomatch), + ok = ctest("ABCabcdABC","ABCD",[caseless],true,{match,[{3,4}]}), + ok = ctest("abcdABC\n","ABC$",[],true,{match,[{4,3}]}), + ok = ctest("abcdABC\n","ABC$",[dollar_endonly],true,nomatch), + ok = ctest("abcdABC\n","ABC.",[],true,nomatch), + ok = ctest("abcdABC\n","ABC.",[dotall],true,{match,[{4,4}]}), + ok = ctest("abcdABCD","ABC .",[],true,nomatch), + ok = ctest("abcdABCD","ABC .",[extended],true,{match,[{4,4}]}), + ok = ctest("abcd\nABCD","ABC",[],true,{match,[{5,3}]}), + ok = ctest("abcd\nABCD","ABC",[firstline],true,nomatch), + ok = ctest("abcd\nABCD","^ABC",[],true,nomatch), + ok = ctest("abcd\nABCD","^ABC",[multiline],true,{match,[{5,3}]}), + ok = ctest("abcdABCD","(ABC)",[],true,{match,[{4,3},{4,3}]}), + ok = ctest("abcdABCD","(ABC)",[no_auto_capture],true,{match,[{4,3}]}), + ok = ctest(notused,"(?<FOO>ABC)|(?<FOO>DEF)",[],false,notused), + ok = ctest("abcdABCD","(?<FOO>ABC)|(?<FOO>DEF)",[dupnames],true,{match,[{4,3},{4,3}]}), + ok = ctest("abcdABCDabcABCD","abcd.*D",[],true,{match,[{0,15}]}), + ok = ctest("abcdABCDabcABCD","abcd.*D",[ungreedy],true,{match,[{0,8}]}), + ok = ctest("abcdABCabcABC\nD","abcd.*D",[],true,nomatch), + ok = ctest("abcdABCabcABC\nD","abcd.*D",[{newline,cr}],true,{match,[{0,15}]}), + ok = ctest("abcdABCabcABC\rD","abcd.*D",[],true,{match,[{0,15}]}), + ok = ctest("abcdABCabcABC\rD","abcd.*D",[{newline,lf}],true,{match,[{0,15}]}), + ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,lf}],true,nomatch), + ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,cr}],true,nomatch), + ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,crlf}],true,{match,[{7,4}]}), + + ok = ctest("abcdABCabcd\r","abcd$",[{newline,crlf}],true,nomatch), + ok = ctest("abcdABCabcd\n","abcd$",[{newline,crlf}],true,nomatch), + ok = ctest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + + ok = ctest("abcdABCabcd\r","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + ok = ctest("abcdABCabcd\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), ok. %% Test all documented run specific options. run_options(Config) when is_list(Config) -> - ?line rtest("ABCabcdABC","abc",[],[],true), - ?line rtest("ABCabcdABC","abc",[anchored],[],false), + rtest("ABCabcdABC","abc",[],[],true), + rtest("ABCabcdABC","abc",[anchored],[],false), %% Anchored in run overrides unanchored in compilation - ?line rtest("ABCabcdABC","abc",[],[anchored],false), - - ?line rtest("","a?b?",[],[],true), - ?line rtest("","a?b?",[],[notempty],false), - - ?line rtest("abc","^a",[],[],true), - ?line rtest("abc","^a",[],[notbol],false), - ?line rtest("ab\nc","^a",[multiline],[],true), - ?line rtest("ab\nc","^a",[multiline],[notbol],false), - ?line rtest("ab\nc","^c",[multiline],[notbol],true), - - ?line rtest("abc","c$",[],[],true), - ?line rtest("abc","c$",[],[noteol],false), - - ?line rtest("ab\nc","b$",[multiline],[],true), - ?line rtest("ab\nc","c$",[multiline],[],true), - ?line rtest("ab\nc","b$",[multiline],[noteol],true), - ?line rtest("ab\nc","c$",[multiline],[noteol],false), - - ?line rtest("abc","ab",[],[{offset,0}],true), - ?line rtest("abc","ab",[],[{offset,1}],false), - - ?line rtest("abcdABCabcABC\nD","abcd.*D",[],[],false), - ?line rtest("abcdABCabcABC\nD","abcd.*D",[],[{newline,cr}],true), - ?line rtest("abcdABCabcABC\rD","abcd.*D",[],[],true), - ?line rtest("abcdABCabcABC\rD","abcd.*D",[{newline,cr}],[{newline,lf}],true), - ?line rtest("abcdABCabcd\r\n","abcd$",[],[{newline,lf}],false), - ?line rtest("abcdABCabcd\r\n","abcd$",[],[{newline,cr}],false), - ?line rtest("abcdABCabcd\r\n","abcd$",[],[{newline,crlf}],true), - - ?line rtest("abcdABCabcd\r","abcd$",[],[{newline,crlf}],false), - ?line rtest("abcdABCabcd\n","abcd$",[],[{newline,crlf}],false), - ?line rtest("abcdABCabcd\r\n","abcd$",[],[{newline,anycrlf}],true), - - ?line rtest("abcdABCabcd\r","abcd$",[],[{newline,anycrlf}],true), - ?line rtest("abcdABCabcd\n","abcd$",[],[{newline,anycrlf}],true), - - ?line {ok,MP} = re:compile(".*(abcd).*"), - ?line {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[]), - ?line {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all}]), - ?line {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all,index}]), - ?line {match,["ABCabcdABC","abcd"]} = re:run("ABCabcdABC",MP,[{capture,all,list}]), - ?line {match,[<<"ABCabcdABC">>,<<"abcd">>]} = re:run("ABCabcdABC",MP,[{capture,all,binary}]), - ?line {match,[{0,10}]} = re:run("ABCabcdABC",MP,[{capture,first}]), - ?line {match,[{0,10}]} = re:run("ABCabcdABC",MP,[{capture,first,index}]), ?line {match,["ABCabcdABC"]} = re:run("ABCabcdABC",MP,[{capture,first,list}]), - ?line {match,[<<"ABCabcdABC">>]} = re:run("ABCabcdABC",MP,[{capture,first,binary}]), - - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all_but_first}]), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,index}]), - ?line {match,["abcd"]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,list}]), - ?line {match,[<<"abcd">>]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,binary}]), - - ?line match = re:run("ABCabcdABC",MP,[{capture,none}]), - ?line match = re:run("ABCabcdABC",MP,[{capture,none,index}]), - ?line match = re:run("ABCabcdABC",MP,[{capture,none,list}]), - ?line match = re:run("ABCabcdABC",MP,[{capture,none,binary}]), - - ?line {ok,MP2} = re:compile(".*(?<FOO>abcd).*"), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,[1]}]), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,['FOO']}]), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"]}]), - ?line {match,["abcd"]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"],list}]), - ?line {match,[<<"abcd">>]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"],binary}]), - - ?line {match,[{-1,0}]} = re:run("ABCabcdABC",MP2,[{capture,[200]}]), - ?line {match,[{-1,0}]} = re:run("ABCabcdABC",MP2,[{capture,['BAR']}]), - ?line {match,[""]} = re:run("ABCabcdABC",MP2,[{capture,[200],list}]), - ?line {match,[""]} = re:run("ABCabcdABC",MP2,[{capture,['BAR'],list}]), - ?line {match,[<<>>]} = re:run("ABCabcdABC",MP2,[{capture,[200],binary}]), - ?line {match,[<<>>]} = re:run("ABCabcdABC",MP2,[{capture,['BAR'],binary}]), - - ?line {ok, MP3} = re:compile(".*((?<FOO>abdd)|a(..d)).*"), - ?line {match,[{0,10},{3,4},{-1,0},{4,3}]} = re:run("ABCabcdABC",MP3,[]), - ?line {match,[{0,10},{3,4},{-1,0},{4,3}]} = re:run("ABCabcdABC",MP3,[{capture,all,index}]), - ?line {match,[<<"ABCabcdABC">>,<<"abcd">>,<<>>,<<"bcd">>]} = re:run("ABCabcdABC",MP3,[{capture,all,binary}]), - ?line {match,["ABCabcdABC","abcd",[],"bcd"]} = re:run("ABCabcdABC",MP3,[{capture,all,list}]), + rtest("ABCabcdABC","abc",[],[anchored],false), + + rtest("","a?b?",[],[],true), + rtest("","a?b?",[],[notempty],false), + + rtest("abc","^a",[],[],true), + rtest("abc","^a",[],[notbol],false), + rtest("ab\nc","^a",[multiline],[],true), + rtest("ab\nc","^a",[multiline],[notbol],false), + rtest("ab\nc","^c",[multiline],[notbol],true), + + rtest("abc","c$",[],[],true), + rtest("abc","c$",[],[noteol],false), + + rtest("ab\nc","b$",[multiline],[],true), + rtest("ab\nc","c$",[multiline],[],true), + rtest("ab\nc","b$",[multiline],[noteol],true), + rtest("ab\nc","c$",[multiline],[noteol],false), + + rtest("abc","ab",[],[{offset,0}],true), + rtest("abc","ab",[],[{offset,1}],false), + + rtest("abcdABCabcABC\nD","abcd.*D",[],[],false), + rtest("abcdABCabcABC\nD","abcd.*D",[],[{newline,cr}],true), + rtest("abcdABCabcABC\rD","abcd.*D",[],[],true), + rtest("abcdABCabcABC\rD","abcd.*D",[{newline,cr}],[{newline,lf}],true), + rtest("abcdABCabcd\r\n","abcd$",[],[{newline,lf}],false), + rtest("abcdABCabcd\r\n","abcd$",[],[{newline,cr}],false), + rtest("abcdABCabcd\r\n","abcd$",[],[{newline,crlf}],true), + + rtest("abcdABCabcd\r","abcd$",[],[{newline,crlf}],false), + rtest("abcdABCabcd\n","abcd$",[],[{newline,crlf}],false), + rtest("abcdABCabcd\r\n","abcd$",[],[{newline,anycrlf}],true), + + rtest("abcdABCabcd\r","abcd$",[],[{newline,anycrlf}],true), + rtest("abcdABCabcd\n","abcd$",[],[{newline,anycrlf}],true), + + {ok,MP} = re:compile(".*(abcd).*"), + {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[]), + {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all}]), + {match,[{0,10},{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all,index}]), + {match,["ABCabcdABC","abcd"]} = re:run("ABCabcdABC",MP,[{capture,all,list}]), + {match,[<<"ABCabcdABC">>,<<"abcd">>]} = re:run("ABCabcdABC",MP,[{capture,all,binary}]), + {match,[{0,10}]} = re:run("ABCabcdABC",MP,[{capture,first}]), + {match,[{0,10}]} = re:run("ABCabcdABC",MP,[{capture,first,index}]), ?line {match,["ABCabcdABC"]} = re:run("ABCabcdABC",MP,[{capture,first,list}]), + {match,[<<"ABCabcdABC">>]} = re:run("ABCabcdABC",MP,[{capture,first,binary}]), + + {match,[{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all_but_first}]), + {match,[{3,4}]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,index}]), + {match,["abcd"]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,list}]), + {match,[<<"abcd">>]} = re:run("ABCabcdABC",MP,[{capture,all_but_first,binary}]), + + match = re:run("ABCabcdABC",MP,[{capture,none}]), + match = re:run("ABCabcdABC",MP,[{capture,none,index}]), + match = re:run("ABCabcdABC",MP,[{capture,none,list}]), + match = re:run("ABCabcdABC",MP,[{capture,none,binary}]), + + {ok,MP2} = re:compile(".*(?<FOO>abcd).*"), + {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,[1]}]), + {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,['FOO']}]), + {match,[{3,4}]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"]}]), + {match,["abcd"]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"],list}]), + {match,[<<"abcd">>]} = re:run("ABCabcdABC",MP2,[{capture,["FOO"],binary}]), + + {match,[{-1,0}]} = re:run("ABCabcdABC",MP2,[{capture,[200]}]), + {match,[{-1,0}]} = re:run("ABCabcdABC",MP2,[{capture,['BAR']}]), + {match,[""]} = re:run("ABCabcdABC",MP2,[{capture,[200],list}]), + {match,[""]} = re:run("ABCabcdABC",MP2,[{capture,['BAR'],list}]), + {match,[<<>>]} = re:run("ABCabcdABC",MP2,[{capture,[200],binary}]), + {match,[<<>>]} = re:run("ABCabcdABC",MP2,[{capture,['BAR'],binary}]), + + {ok, MP3} = re:compile(".*((?<FOO>abdd)|a(..d)).*"), + {match,[{0,10},{3,4},{-1,0},{4,3}]} = re:run("ABCabcdABC",MP3,[]), + {match,[{0,10},{3,4},{-1,0},{4,3}]} = re:run("ABCabcdABC",MP3,[{capture,all,index}]), + {match,[<<"ABCabcdABC">>,<<"abcd">>,<<>>,<<"bcd">>]} = re:run("ABCabcdABC",MP3,[{capture,all,binary}]), + {match,["ABCabcdABC","abcd",[],"bcd"]} = re:run("ABCabcdABC",MP3,[{capture,all,list}]), ok. - - + + %% Test compile options given directly to run. combined_options(Config) when is_list(Config) -> - ?line ok = crtest("ABDabcdABCD","abcd",[],true,{match,[{3,4}]}), - ?line ok = crtest("ABDabcdABCD","abcd",[anchored],true,nomatch), - ?line ok = crtest("ABDabcdABCD",".*abcd",[anchored],true,{match,[{0,7}]}), - ?line ok = crtest("ABCabcdABC","ABCD",[],true,nomatch), - ?line ok = crtest("ABCabcdABC","ABCD",[caseless],true,{match,[{3,4}]}), - ?line ok = crtest("abcdABC\n","ABC$",[],true,{match,[{4,3}]}), - ?line ok = crtest("abcdABC\n","ABC$",[dollar_endonly],true,nomatch), - ?line ok = crtest("abcdABC\n","ABC.",[],true,nomatch), - ?line ok = crtest("abcdABC\n","ABC.",[dotall],true,{match,[{4,4}]}), - ?line ok = crtest("abcdABCD","ABC .",[],true,nomatch), - ?line ok = crtest("abcdABCD","ABC .",[extended],true,{match,[{4,4}]}), - ?line ok = crtest("abcd\nABCD","ABC",[],true,{match,[{5,3}]}), - ?line ok = crtest("abcd\nABCD","ABC",[firstline],true,nomatch), - ?line ok = crtest("abcd\nABCD","^ABC",[],true,nomatch), - ?line ok = crtest("abcd\nABCD","^ABC",[multiline],true,{match,[{5,3}]}), - ?line ok = crtest("abcdABCD","(ABC)",[],true,{match,[{4,3},{4,3}]}), - ?line ok = crtest("abcdABCD","(ABC)",[no_auto_capture],true,{match,[{4,3}]}), - ?line ok = crtest(notused,"(?<FOO>ABC)|(?<FOO>DEF)",[],false,notused), - ?line ok = crtest("abcdABCD","(?<FOO>ABC)|(?<FOO>DEF)",[dupnames],true,{match,[{4,3},{4,3}]}), - ?line ok = crtest("abcdABCDabcABCD","abcd.*D",[],true,{match,[{0,15}]}), - ?line ok = crtest("abcdABCDabcABCD","abcd.*D",[ungreedy],true,{match,[{0,8}]}), - ?line ok = ctest("abcdABCabcABC\nD","abcd.*D",[],true,nomatch), - ?line ok = crtest("abcdABCabcABC\nD","abcd.*D",[{newline,cr}],true,{match,[{0,15}]}), - ?line ok = crtest("abcdABCabcABC\rD","abcd.*D",[],true,{match,[{0,15}]}), - ?line ok = crtest("abcdABCabcABC\rD","abcd.*D",[{newline,lf}],true,{match,[{0,15}]}), - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,lf}],true,nomatch), - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,cr}],true,nomatch), - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,crlf}],true,{match,[{7,4}]}), - - ?line ok = crtest("abcdABCabcd\r","abcd$",[{newline,crlf}],true,nomatch), - ?line ok = crtest("abcdABCabcd\n","abcd$",[{newline,crlf}],true,nomatch), - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - - ?line ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - ?line ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), - - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), - - ?line ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), - - ?line ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), - - ?line ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), - - ?line ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), - ?line ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), - + ok = crtest("ABDabcdABCD","abcd",[],true,{match,[{3,4}]}), + ok = crtest("ABDabcdABCD","abcd",[anchored],true,nomatch), + ok = crtest("ABDabcdABCD",".*abcd",[anchored],true,{match,[{0,7}]}), + ok = crtest("ABCabcdABC","ABCD",[],true,nomatch), + ok = crtest("ABCabcdABC","ABCD",[caseless],true,{match,[{3,4}]}), + ok = crtest("abcdABC\n","ABC$",[],true,{match,[{4,3}]}), + ok = crtest("abcdABC\n","ABC$",[dollar_endonly],true,nomatch), + ok = crtest("abcdABC\n","ABC.",[],true,nomatch), + ok = crtest("abcdABC\n","ABC.",[dotall],true,{match,[{4,4}]}), + ok = crtest("abcdABCD","ABC .",[],true,nomatch), + ok = crtest("abcdABCD","ABC .",[extended],true,{match,[{4,4}]}), + ok = crtest("abcd\nABCD","ABC",[],true,{match,[{5,3}]}), + ok = crtest("abcd\nABCD","ABC",[firstline],true,nomatch), + ok = crtest("abcd\nABCD","^ABC",[],true,nomatch), + ok = crtest("abcd\nABCD","^ABC",[multiline],true,{match,[{5,3}]}), + ok = crtest("abcdABCD","(ABC)",[],true,{match,[{4,3},{4,3}]}), + ok = crtest("abcdABCD","(ABC)",[no_auto_capture],true,{match,[{4,3}]}), + ok = crtest(notused,"(?<FOO>ABC)|(?<FOO>DEF)",[],false,notused), + ok = crtest("abcdABCD","(?<FOO>ABC)|(?<FOO>DEF)",[dupnames],true,{match,[{4,3},{4,3}]}), + ok = crtest("abcdABCDabcABCD","abcd.*D",[],true,{match,[{0,15}]}), + ok = crtest("abcdABCDabcABCD","abcd.*D",[ungreedy],true,{match,[{0,8}]}), + ok = ctest("abcdABCabcABC\nD","abcd.*D",[],true,nomatch), + ok = crtest("abcdABCabcABC\nD","abcd.*D",[{newline,cr}],true,{match,[{0,15}]}), + ok = crtest("abcdABCabcABC\rD","abcd.*D",[],true,{match,[{0,15}]}), + ok = crtest("abcdABCabcABC\rD","abcd.*D",[{newline,lf}],true,{match,[{0,15}]}), + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,lf}],true,nomatch), + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,cr}],true,nomatch), + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,crlf}],true,{match,[{7,4}]}), + + ok = crtest("abcdABCabcd\r","abcd$",[{newline,crlf}],true,nomatch), + ok = crtest("abcdABCabcd\n","abcd$",[{newline,crlf}],true,nomatch), + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + + ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf}],true,{match,[{7,4}]}), + + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), + + ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), + + ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf},{capture,all,list}],true,{match,["abcd"]}), + + ok = crtest("abcdABCabcd\r\n","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), + + ok = crtest("abcdABCabcd\r","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), + ok = crtest("abcdABCabcd\n","abcd$",[{newline,anycrlf},{capture,all,binary}],true,{match,[<<"abcd">>]}), + %% Check that unique run-options fail in compile only case: - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},{capture,all,binary}])), - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},{offset,3}])), - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},notempty])), - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},notbol])), - ?line {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},noteol])), - - - ?line {match,_} = re:run("abcdABCabcd\r\n","abcd$",[{newline,crlf}]), - ?line nomatch = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf}]), - ?line {match,_} = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf},multiline]), - ?line nomatch = re:run("abcdABCabcd\r\nefgh","efgh$",[{newline,crlf},multiline,noteol]), - ?line {match,_} = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf},multiline,noteol]), - ?line {match,_} = re:run("abcdABCabcd\r\nefgh","^abcd",[{newline,crlf},multiline,noteol]), - ?line nomatch = re:run("abcdABCabcd\r\nefgh","^abcd",[{newline,crlf},multiline,notbol]), - ?line {match,_} = re:run("abcdABCabcd\r\nefgh","^efgh",[{newline,crlf},multiline,notbol]), - ?line {match,_} = re:run("ABC\nD","[a-z]*",[{newline,crlf}]), - ?line nomatch = re:run("ABC\nD","[a-z]*",[{newline,crlf},notempty]), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},{capture,all,binary}])), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},{offset,3}])), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},notempty])), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},notbol])), + {'EXIT',{badarg,_}} = (catch re:compile("abcd$",[{newline,anycrlf},noteol])), + + + {match,_} = re:run("abcdABCabcd\r\n","abcd$",[{newline,crlf}]), + nomatch = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf}]), + {match,_} = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf},multiline]), + nomatch = re:run("abcdABCabcd\r\nefgh","efgh$",[{newline,crlf},multiline,noteol]), + {match,_} = re:run("abcdABCabcd\r\nefgh","abcd$",[{newline,crlf},multiline,noteol]), + {match,_} = re:run("abcdABCabcd\r\nefgh","^abcd",[{newline,crlf},multiline,noteol]), + nomatch = re:run("abcdABCabcd\r\nefgh","^abcd",[{newline,crlf},multiline,notbol]), + {match,_} = re:run("abcdABCabcd\r\nefgh","^efgh",[{newline,crlf},multiline,notbol]), + {match,_} = re:run("ABC\nD","[a-z]*",[{newline,crlf}]), + nomatch = re:run("ABC\nD","[a-z]*",[{newline,crlf},notempty]), ok. %% Test replace with autogenerated erlang module. @@ -270,36 +270,36 @@ replace_autogen(Config) when is_list(Config) -> %% Test capture options together with global searching. global_capture(Config) when is_list(Config) -> - ?line {match,[{3,4}]} = re:run("ABCabcdABC",".*(?<FOO>abcd).*",[{capture,[1]}]), - ?line {match,[{10,4}]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[{capture,[1]}]), - ?line {match,[[{10,4}]]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[global,{capture,[1]}]), - ?line {match,[{3,4}]} = re:run("ABCabcdABC",".*(?<FOO>abcd).*",[{capture,['FOO']}]), - ?line {match,[{10,4}]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[{capture,['FOO']}]), - ?line {match,[[{10,4}]]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[global,{capture,['FOO']}]), - ?line {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global]), - ?line {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all}]), - ?line {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all,index}]), - ?line {match,[[{3,4}],[{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,first}]), - ?line {match,[[{3,4}],[{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all_but_first}]), - ?line {match,[[<<"bcd">>],[<<"bcd">>]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all_but_first,binary}]), - ?line {match,[["bcd"],["bcd"]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all_but_first,list}]), - ?line {match,[["abcd","bcd"],["abcd","bcd"]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,list}]), - ?line {match,[[<<"abcd">>,<<"bcd">>],[<<"abcd">>,<<"bcd">>]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,binary}]), - ?line {match,[[{3,4},{4,3}],[{10,4},{11,3}]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,index}]), - ?line match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,index}]), - ?line match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,binary}]), - ?line match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,list}]), - ?line {match,[[<<195,133,98,99,100>>,<<"bcd">>],[<<"abcd">>,<<"bcd">>]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,binary},unicode]), - ?line {match,[["Åbcd","bcd"],["abcd","bcd"]]} = re:run(<<"ABC",8#303,8#205,"bcdABCabcdA">>,".(?<FOO>bcd)",[global,{capture,all,list},unicode]), - ?line {match,[["Åbcd","bcd"],["abcd","bcd"]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,list},unicode]), - ?line {match,[[{3,5},{5,3}],[{11,4},{12,3}]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,index},unicode]), + {match,[{3,4}]} = re:run("ABCabcdABC",".*(?<FOO>abcd).*",[{capture,[1]}]), + {match,[{10,4}]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[{capture,[1]}]), + {match,[[{10,4}]]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[global,{capture,[1]}]), + {match,[{3,4}]} = re:run("ABCabcdABC",".*(?<FOO>abcd).*",[{capture,['FOO']}]), + {match,[{10,4}]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[{capture,['FOO']}]), + {match,[[{10,4}]]} = re:run("ABCabcdABCabcdA",".*(?<FOO>abcd).*",[global,{capture,['FOO']}]), + {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global]), + {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all}]), + {match,[[{3,4},{3,4}],[{10,4},{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all,index}]), + {match,[[{3,4}],[{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,first}]), + {match,[[{3,4}],[{10,4}]]} = re:run("ABCabcdABCabcdA","(?<FOO>abcd)",[global,{capture,all_but_first}]), + {match,[[<<"bcd">>],[<<"bcd">>]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all_but_first,binary}]), + {match,[["bcd"],["bcd"]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all_but_first,list}]), + {match,[["abcd","bcd"],["abcd","bcd"]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,list}]), + {match,[[<<"abcd">>,<<"bcd">>],[<<"abcd">>,<<"bcd">>]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,binary}]), + {match,[[{3,4},{4,3}],[{10,4},{11,3}]]} = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,all,index}]), + match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,index}]), + match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,binary}]), + match = re:run("ABCabcdABCabcdA","a(?<FOO>bcd)",[global,{capture,none,list}]), + {match,[[<<195,133,98,99,100>>,<<"bcd">>],[<<"abcd">>,<<"bcd">>]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,binary},unicode]), + {match,[["Åbcd","bcd"],["abcd","bcd"]]} = re:run(<<"ABC",8#303,8#205,"bcdABCabcdA">>,".(?<FOO>bcd)",[global,{capture,all,list},unicode]), + {match,[["Åbcd","bcd"],["abcd","bcd"]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,list},unicode]), + {match,[[{3,5},{5,3}],[{11,4},{12,3}]]} = re:run("ABCÅbcdABCabcdA",".(?<FOO>bcd)",[global,{capture,all,index},unicode]), ok. %% Test replace with different input types. replace_input_types(Config) when is_list(Config) -> - ?line <<"abcd">> = re:replace("abcd","Z","X",[{return,binary},unicode]), - ?line <<"abcd">> = re:replace("abcd","\x{400}","X",[{return,binary},unicode]), - ?line <<"a",208,128,"cd">> = re:replace(<<"abcd">>,"b","\x{400}",[{return,binary},unicode]), + <<"abcd">> = re:replace("abcd","Z","X",[{return,binary},unicode]), + <<"abcd">> = re:replace("abcd","\x{400}","X",[{return,binary},unicode]), + <<"a",208,128,"cd">> = re:replace(<<"abcd">>,"b","\x{400}",[{return,binary},unicode]), ok. %% Test return options of replace together with global searching. @@ -421,7 +421,7 @@ split_options(Config) when is_list(Config) -> %% Parts 0 is equal to no parts specification (implicit strip) ok = splittest("a b c d","( *)",[{parts,0},{return,list}],["a"," ","b"," ","c"," ","d"]), ok. - + join([]) -> []; join([A]) -> [A]; join([H|T]) -> [H,<<":">>|join(T)]. @@ -429,12 +429,12 @@ join([H|T]) -> [H,<<":">>|join(T)]. %% Some special cases of split that are easy to get wrong. split_specials(Config) when is_list(Config) -> %% More or less just to remember these icky cases - ?line <<"::abd:f">> = + <<"::abd:f">> = iolist_to_binary(join(re:split("abdf","^(?!(ab)de|x)(abd)(f)",[trim]))), - ?line <<":abc2xyzabc3">> = + <<":abc2xyzabc3">> = iolist_to_binary(join(re:split("abc1abc2xyzabc3","\\Aabc.",[trim]))), ok. - + %% Test that errors are handled correctly by the erlang code. error_handling(_Config) -> @@ -445,7 +445,7 @@ error_handling(_Config) -> false -> error_handling() end. - + error_handling() -> %% This test checks the exception tuples manufactured in the erlang %% code to hide the trapping from the user at least when it comes to errors @@ -601,7 +601,7 @@ error_handling() -> {?MODULE,error_handling,0,_} | _]}} = (catch re:split("apa","(p",[banana])), ok. - + %% Fix as in http://vcs.pcre.org/viewvc?revision=360&view=revision pcre_cve_2008_2371(Config) when is_list(Config) -> %% Make sure it doesn't crash the emulator. @@ -612,7 +612,7 @@ pcre_cve_2008_2371(Config) when is_list(Config) -> %% http://vcs.pcre.org/viewvc/code/trunk/pcre_compile.c?r1=504&r2=505&view=patch pcre_compile_workspace_overflow(Config) when is_list(Config) -> N = 819, - ?line {error,{"internal error: overran compiling workspace",799}} = + {error,{"internal error: overran compiling workspace",799}} = re:compile([lists:duplicate(N, $(), lists:duplicate(N, $))]), ok. @@ -634,9 +634,9 @@ re_infinite_loop(Config) when is_list(Config) -> %% Check for nasty bug where accented graphemes can make PCRE back %% past beginning of subject. re_backwards_accented(Config) when is_list(Config) -> - ?line match = re:run(<<65,204,128,65,204,128,97,98,99>>, - <<"\\X?abc">>, - [unicode,{capture,none}]), + match = re:run(<<65,204,128,65,204,128,97,98,99>>, + <<"\\X?abc">>, + [unicode,{capture,none}]), ok. %% Check correct handling of dupnames option to re. @@ -673,9 +673,9 @@ opt_dupnames(Config) when is_list(Config) -> "(?<DN>Sat)(?:urday)?", [dupnames, {capture, ['Skrap','DN','Skrap2'],index}]), {match,[{-1,0},{0,3},{-1,0}]} = re:run("Wednesday","(?<Skrap>.)(?<DN>Mon|Fri|Sun)(?:day)?(?<Skrap2>.)|" - "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" - "(?<DN>Sat)(?:urday)?", - [dupnames, {capture, ['Skrap','DN','Skrap2'],index}]), + "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" + "(?<DN>Sat)(?:urday)?", + [dupnames, {capture, ['Skrap','DN','Skrap2'],index}]), nomatch = re:run("Wednsday","(?<Skrap>.)(?<DN>Mon|Fri|Sun)(?:day)?(?<Skrap2>.)|" "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" "(?<DN>Sat)(?:urday)?", @@ -735,10 +735,10 @@ opt_all_names(Config) when is_list(Config) -> "(?<DN>Sat)(?:urday)?", [dupnames, {capture, all_names,index}]), {match,[{0,3},{-1,0},{-1,0}]} = re:run("Wednesday","(?<Skrap>.)(?<DN>Mon|Fri|Sun)(?:day)?(?<Skrap2>.)|" - "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" - "(?<DN>Sat)(?:urday)?", - [dupnames, {capture, all_names,index}]), - + "(?<DN>Tue)(?:sday)?|(?<DN>Wed)nesday|(?<DN>Thu)(?:rsday)?|" + "(?<DN>Sat)(?:urday)?", + [dupnames, {capture, all_names,index}]), + _ = [ begin {match,[{0,3}]} = re:run(Day, @@ -777,7 +777,7 @@ opt_all_names(Config) when is_list(Config) -> {match,[[<<>>,<<>>,<<"C">>], [<<>>,<<>>,<<"C">>], [<<>>,<<>>,<<"C">>]]} = re:run("CCC","(?<A>A)|(?<B>B)|(?<C>C)", - [global,{capture, all_names, binary}]), + [global,{capture, all_names, binary}]), {match,[[<<"C">>,<<>>], [<<>>,<<"B">>], [<<"C">>,<<>>]]} = re:run("CBC","(?<A>A)|(?<B>B)|(?<A>C)", @@ -837,7 +837,7 @@ opt_never_utf(Config) when is_list(Config) -> opt_ucp(Config) when is_list(Config) -> {match,[{0,1}]} = re:run([$a],"\\w",[unicode]), {match,[{0,2}]} = re:run([229],"\\w",[unicode]), % Latin1 works without UCP, as we have a default - %% Latin1 table + %% Latin1 table nomatch = re:run([1024],"\\w",[unicode]), % Latin1 word characters only, 1024 is not latin1 {match,[{0,2}]} = re:run([1024],"\\w",[unicode,ucp]), % Any Unicode word character works with 'ucp' ok. @@ -849,12 +849,12 @@ match_limit(Config) when is_list(Config) -> nomatch = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit_recursion,10}]), nomatch = re:run("aaaaaaaaaaaaaz","(a+)*zz",[report_errors]), {error,match_limit} = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit,3000}, - report_errors]), + report_errors]), {error,match_limit_recursion} = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit_recursion,10}, report_errors]), {error,match_limit} = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit,3000}, - report_errors,global]), + report_errors,global]), {error,match_limit_recursion} = re:run("aaaaaaaaaaaaaz","(a+)*zz",[{match_limit_recursion,10}, report_errors,global]), @@ -867,9 +867,9 @@ match_limit(Config) when is_list(Config) -> "aaaaaaaaaaaaaz" = re:replace("aaaaaaaaaaaaaz","(a+)*zz","!", [{match_limit,3000},{return,list}]), {'EXIT', {badarg,_}} = (catch re:replace("aaaaaaaaaaaaaz","(a+)*zz","!", - [{match_limit_recursion,-1},{return,list}])), + [{match_limit_recursion,-1},{return,list}])), {'EXIT', {badarg,_}} = (catch re:replace("aaaaaaaaaaaaaz","(a+)*zz","!", - [{match_limit,-1},{return,list}])), + [{match_limit,-1},{return,list}])), {'EXIT', {badarg,_}} = (catch re:run("aaaaaaaaaaaaaz","(a+)*zz", [{match_limit_recursion,-1}, report_errors,global])), |