From 32df5529f791760161a027a1a7408bc92976a3cd Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 30 Aug 2017 13:18:50 +0300 Subject: Add $regex.split(), $regex.merge() and $regex.apply() functions --- tests/function/regex/testscript | 96 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'tests/function') diff --git a/tests/function/regex/testscript b/tests/function/regex/testscript index deeefa5..6cce873 100644 --- a/tests/function/regex/testscript +++ b/tests/function/regex/testscript @@ -253,3 +253,99 @@ } } } + +: 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 +} + +: 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 +} -- cgit v1.1