aboutsummaryrefslogtreecommitdiff
path: root/tests/function/regex/testscript
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-08-30 13:18:50 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-08-30 23:00:29 +0300
commit32df5529f791760161a027a1a7408bc92976a3cd (patch)
tree170064adddd321c080d89a0bf85255db6d644f7f /tests/function/regex/testscript
parent909bbc79fd2dc1d3a36e3109ba32a22e162b2b7f (diff)
Add $regex.split(), $regex.merge() and $regex.apply() functions
Diffstat (limited to 'tests/function/regex/testscript')
-rw-r--r--tests/function/regex/testscript96
1 files changed, 96 insertions, 0 deletions
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.
+ :
+ $* <<EOI >'|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.
+ :
+ $* <<EOI >'|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.
+ :
+ $* <<EOI >' '
+ print $regex.split('abc def', '(\S+)', '')
+ EOI
+
+ : include-options
+ :
+ {
+ : quoted
+ :
+ $* <<EOI >'|-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.
+ :
+ $* <<EOI >'|-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
+ :
+ $* <<EOI >'xbc cbx'
+ print $regex.apply(abc cba, 'a', 'x')
+ EOI
+
+ : omit-empty
+ :
+ $* <<EOI >'bc cb'
+ print $regex.apply(abc a cba, 'a', '')
+ EOI
+}
+
+: merge
+:
+{
+ : all-parts
+ :
+ $* <<EOI >'xbccbx'
+ print $regex.merge(abc cba, 'a', 'x')
+ EOI
+
+ : omit-empty
+ :
+ $* <<EOI >'bccb'
+ print $regex.merge(abc a cba, 'a', '')
+ EOI
+
+ : delim
+ :
+ $* <<EOI >'xbc-cbx'
+ print $regex.merge(abc cba, 'a', 'x', '-')
+ EOI
+
+ : string-delim
+ :
+ $* <<EOI >'xbc-cbx'
+ print $regex.merge(abc cba, 'a', 'x', [string] '-')
+ EOI
+}