# file : tests/function/regex/testscript # license : MIT; see accompanying LICENSE file .include ../../common.testscript : replace : { : arg-types : { : untyped-string-string : $* <'foo.o' print $regex.replace('foo.cxx', [string] '(^[^.]*).*', [string] '\1.o') EOI : string-untyped-string : $* <'foo.o' print $regex.replace([string] 'foo.cxx', '(^[^.]*).*', [string] '\1.o') EOI : bool-string-untyped : $* <'true.o' print $regex.replace('a' == "a", [string] '(^[^.]*).*', '\1.o') EOI : uint64-untyped-string : $* <'1.o' print $regex.replace([uint64] 01, '(^[^.]*).*', [string] '\1.o') EOI : path-untyped-untyped : $* <'foo.o' print $regex.replace([path] 'foo.cxx', '(^[^.]*).*', '\1.o') EOI : multiple-names : $* <>EOE != 0 print $regex.replace(foo.cxx bar.cxx, '([^.]*)', '\1.o') EOI error: invalid argument: invalid string value: multiple names :1:8: info: while calling regex.replace(, , ) EOE : null : $* <>EOE != 0 print $regex.replace([null], '([^.]*)', '\1.o') EOI error: invalid argument: null value :1:8: info: while calling regex.replace(, , ) EOE : null-regex : $* <>EOE != 0 print $regex.replace(foo.cxx, [null], '\1.o') EOI error: invalid argument: null value :1:8: info: while calling regex.replace(, , ) EOE } : no-subs : $* <'xbcxbc' print $regex.replace('abcabc', 'a', 'x') EOI : no-match : $* <'abcabc' print $regex.replace('abcabc', 'd', 'x') EOI : flags : { : icase : $* <'Foo.o' print $regex.replace("Foo.cxx", '(f[^.]*).*', '\1.o', icase) EOI : format_first-only : $* <'foo.o' print $regex.replace('foo.cxx', '([^.]*).*', '\1.o', format_first_only) EOI : format_no_copy : { : all-matches : $* <'xx' print $regex.replace('abcabc', 'a', 'x', format_no_copy) EOI : first-only : $* <'x' print $regex.replace('abcabc', 'a', 'x', format_no_copy format_first_only) EOI } : unknown : $* <>EOE != 0 print $regex.replace("foo.cxx", '(f[^.]*).*', '\1.o', unknown) EOI error: invalid argument: invalid flag 'unknown' :1:8: info: while calling regex.replace(, , , ) EOE } : invalid-regex : $* <'print $regex.replace(a, "[", b)' 2>>~/EOE/ != 0 /error: invalid argument: invalid regex '\['.*/ :1:8: info: while calling regex.replace(, , ) EOE } : replace_lines : { : untyped : { : return-list : { : non-null-fmt : $* <'foo.hxx bar.txt' v = "foo.cxx bar.txt" print $regex.replace_lines($v, '(.*)\.cxx', '\1.hxx') EOI : no-copy : $* <'foo.hxx' v = "foo.cxx bar.txt" print $regex.replace_lines($v, '(.*)\.cxx', '\1.hxx', format_no_copy) EOI : null-fmt : $* <'bar.txt' v = "foo.cxx bar.txt" print $regex.replace_lines($v, '(.*)\.cxx', [null]) EOI } : return-lines : : Note that print adds the trailing newline the value it prints. : { : non-null-fmt : $* <>EOO v = "foo.cxx bar.txt" print $regex.replace_lines($v, '(.*)\.cxx', '\1.hxx', return_lines) EOI foo.hxx bar.txt EOO : no-copy : $* <'bar.hxx' v = "foo.cxx bar.txt" print $regex.replace_lines($v, \ '(.*)\.txt', '\1.hxx', \ format_no_copy return_lines) EOI : null-fmt : $* <'bar.txt' v = "foo.cxx bar.txt" print $regex.replace_lines($v, '(.*)\.cxx', [null], return_lines) EOI } } : strings : { : return-list : $* <'foo.hxx bar.txt' v = [string] "foo.cxx bar.txt" print $regex.replace_lines($v, [string] '(.*)\.cxx', [string] '\1.hxx') EOI : return-lines : $* <>EOO v = [string] "foo.cxx bar.txt" print $regex.replace_lines($v, [string] '(.*)\.cxx', [string] '\1.hxx', return_lines) EOI foo.hxx bar.txt EOO } } : match : { : arg-types : { : untyped-string : $* <'true' print $regex.match('foo.cxx', [string] '(^[^.]*).*') EOI : untyped-untyped : $* <'true' print $regex.match('foo.cxx', '(^[^.]*).*') EOI } : flags : { : none : $* <'false' print $regex.match("Foo.cxx", '(f[^.]*).*') EOI : icase : $* <'true' print $regex.match("Foo.cxx", '(f[^.]*).*', icase) EOI : return_subs : { : success : $* <'foo bar' print $regex.match("foo bar", '([^\s]*)\s+([^\s]*)', return_subs) EOI : no-subexpr : $* <'' print $regex.match("foo bar", '(?:[^\s]*)\s+(?:[^\s]*)', return_subs) EOI : failure : $* <'[null]' print $regex.match(" bar", '([^\s]+)\s+([^\s]+)', return_subs) EOI } } } : search : { : arg-types : { : untyped-string : $* <'true' print $regex.search('.foo.cxx', [string] '([^.]*)') EOI : untyped-untyped : $* <'true' print $regex.search('.foo.cxx', '([^.]*)') EOI } : flags : { : none : $* <'false' print $regex.match("Foo.cxx", '(f[^.]*).*') EOI : icase : $* <'true' print $regex.match("Foo.cxx", '(f[^.]*).*', icase) EOI : return_subs : { : success : $* <'foo bar' print $regex.search(" foo bar baz", '([^\s]+)\s+([^\s]+)', return_subs) EOI : no-subexpr : $* <'' print $regex.search("foo bar ba", '(?:[^\s]+)\s+(?:[^\s]+)', return_subs) EOI : failure : $* <'[null]' print $regex.search(" bar", '([^\s]+)\s+([^\s]+)', return_subs) EOI } : return_match : { : success : $* <'foo bar' print $regex.search(" foo bar baz", '([^\s]+)\s+([^\s]+)', return_match) EOI : subs : $* <'foo bar foo bar' print $regex.search(" foo bar baz", '([^\s]+)\s+([^\s]+)', return_match return_subs) EOI : failure : $* <'[null]' print $regex.search(" bar", '([^\s]+)\s+([^\s]+)', return_match) EOI } } : empty-substring : : Note that regex_search() ignores the match_not_null flag for older : versions of libstdc++ and libc++. : if (($cxx.id != 'gcc' || $cxx.version.major >= 7) && \ ($cxx.id != 'clang' || $cxx.version.major >= 6)) { : empty : $* <'true' print $regex.search('', '.*') EOI : match : $* <'true' print $regex.search('a', 'a*') EOI : no-match : $* <'false' print $regex.search('aa', 'b*') EOI } } : split : { : all-parts : : Note that 3 parts a printed here ('|abc|', ' ' and '|def|'), separated by : the space character. : $* <'|abc| |def|' print $regex.split('abc def', '(\S+)', '|\1|') EOI : no-copy : : Note that 2 parts a printed here ('|abc|' and '|def|'), separated by the : space character. : $* <'|abc| |def|' print $regex.split('abc def', '(\S+)', '|\1|', format_no_copy) EOI : unmatched : : Note that only unmatched part is printed here (' '). Empty replacements are : omitted. : $* <' ' print $regex.split('abc def', '(\S+)', '') EOI : include-options : { : quoted : $* <'|-Ic:/dir 1| |-IC:/dir2| |-IC:/dir3| |-IC:/dir4| ||' opts = '"-Ic:/dir 1" "-IC:/dir2" "-IC:/dir3" "-IC:/dir4" ""' print $regex.split($opts, ' *"([^"]*)" *', '|\1|') EOI : quoted-unquoted : : Note that one of the two captures (\1\2) is always empty as they are : alternative ones. : $* <'|-Ic:/dir 1| |-IC:/dir2| |-IC:/dir3| |-IC:/dir4| ||' opts = '"-Ic:/dir 1" -IC:/dir2 "-IC:/dir3" "-IC:/dir4" ""' print $regex.split($opts, '"([^"]*)"|([^" ]+)', '|\1\2|', format_no_copy) EOI } } : apply : { : all-parts : $* <'xbc cbx' print $regex.apply(abc cba, 'a', 'x') EOI : omit-empty : $* <'bc cb' print $regex.apply(abc a cba, 'a', '') EOI } : find-match : { : match : { : string : $* <'true' print $regex.find_match(-g -O3, [string] '-O[23]') EOI : untyped : $* <'true' print $regex.find_match(-g -O3, '-O[23]') EOI : strings : $* <'true' print $regex.find_match([strings] -g -O3, '-O[23]') EOI : nomatch : $* <'false' print $regex.find_match(-g -O1, '-O[23]') EOI } : flags : { : icase : $* <'true' print $regex.find_match(Foo.cxx, 'f[^.]+.*', icase) EOI } } : filter-match : { : match : { : string : $* <'-O2 -O3' print $regex.filter_match(-g -O2 -O3, [string] '-O[23]') EOI : untyped : $* <'-O2 -O3' print $regex.filter_match(-g -O2 -O3, '-O[23]') EOI : strings : $* <'-O2 -O3' print $regex.filter_match([strings] -g -O2 -O3, '-O[23]') EOI : nomatch : $* <'' print $regex.filter_match(-g -O1, '-O[23]') EOI } : filter-out : { : untyped : $* <'-g' print $regex.filter_out_match(-g -O2 -O3, '-O[23]') EOI : all-match : $* <'' print $regex.filter_out_match(-O2 -O3, '-O[23]') EOI } : flags : { : icase : $* <'Foo.cxx' print $regex.filter_match(Foo.cxx, 'f[^.]+.*', icase) EOI } } : find-search : { : match : { : string : $* <'true' print $regex.find_search(-g -O3, [string] '-O') EOI : untyped : $* <'true' print $regex.find_search(-g -O3, '-O') EOI : strings : $* <'true' print $regex.find_search([strings] -g -O3, '-O') EOI : nomatch : $* <'false' print $regex.find_search(-g, '-O') EOI } : flags : { : icase : $* <'true' print $regex.find_search(Foo.cxx, 'f', icase) EOI } : empty-substring : : Note that regex_search() ignores the match_not_null flag for older : versions of libstdc++ and libc++. : if (($cxx.id != 'gcc' || $cxx.version.major >= 7) && \ ($cxx.id != 'clang' || $cxx.version.major >= 6)) { : empty : $* <'true' print $regex.find_search('', '.*') EOI : match : $* <'true' print $regex.find_search('a', 'a*') EOI : no-match : $* <'false' print $regex.find_search('aa', 'b*') EOI } } : filter-search : { : match : { : string : $* <'-O2 -O3' print $regex.filter_search(-g -O2 -O3, [string] '-O') EOI : untyped : $* <'-O2 -O3' print $regex.filter_search(-g -O2 -O3, '-O') EOI : strings : $* <'-O2 -O3' print $regex.filter_search([strings] -g -O2 -O3, '-O') EOI : nomatch : $* <'' print $regex.filter_search(-g, '-O') EOI : empty-substring : : Note that regex_search() ignores the match_not_null flag for older : versions of libstdc++ and libc++. : if (($cxx.id != 'gcc' || $cxx.version.major >= 7) && \ ($cxx.id != 'clang' || $cxx.version.major >= 6)) { : empty : $* <'{}' print $regex.filter_search('', '.*') EOI : match : $* <'a' print $regex.filter_search('a', 'a*') EOI : no-match : $* <'' print $regex.filter_search('aa', 'b*') EOI } } : filter-out : { : untyped : $* <'-g' print $regex.filter_out_search(-g -O2 -O3, '-O') EOI : all-match : $* <'' print $regex.filter_out_search(-O2 -O3, '-O') EOI } : flags : { : icase : $* <'Foo.cxx' print $regex.filter_search(Foo.cxx, 'f', icase) EOI } } : merge : { : all-parts : $* <'xbccbx' print $regex.merge(abc cba, 'a', 'x') EOI : omit-empty : $* <'bccb' print $regex.merge(abc a cba, 'a', '') EOI : delim : $* <'xbc-cbx' print $regex.merge(abc cba, 'a', 'x', '-') EOI : string-delim : $* <'xbc-cbx' print $regex.merge(abc cba, 'a', 'x', [string] '-') EOI }