From 9a3a8d1915c8a3666984d6603606af856dfd8c41 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 26 Jun 2017 22:23:43 +0300 Subject: Add support for regex function family --- tests/function/regex/buildfile | 5 + tests/function/regex/testscript | 255 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 260 insertions(+) create mode 100644 tests/function/regex/buildfile create mode 100644 tests/function/regex/testscript (limited to 'tests/function') diff --git a/tests/function/regex/buildfile b/tests/function/regex/buildfile new file mode 100644 index 0000000..fbac223 --- /dev/null +++ b/tests/function/regex/buildfile @@ -0,0 +1,5 @@ +# file : tests/function/regex/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +./: test{testscript} $b diff --git a/tests/function/regex/testscript b/tests/function/regex/testscript new file mode 100644 index 0000000..deeefa5 --- /dev/null +++ b/tests/function/regex/testscript @@ -0,0 +1,255 @@ +# file : tests/function/regex/testscript +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include ../../common.test + +: 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 + : + $* <'error: invalid argument: invalid string value: multiple names' != 0 + print $regex.replace(foo.cxx bar.cxx, '([^.]*)', '\1.o') + EOI + + : null + : + $* <'error: invalid argument: null value' != 0 + print $regex.replace([null], '([^.]*)', '\1.o') + EOI + + : null-regex + : + $* <'error: invalid argument: null value' != 0 + print $regex.replace(foo.cxx, [null], '\1.o') + EOI + } + + : 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 + : + $* <"error: invalid argument: invalid flag 'unknown'" != 0 + print $regex.replace("foo.cxx", '(f[^.]*).*', '\1.o', unknown) + EOI + } + + : invalid-regex + : + $* <'print $regex.replace(a, "[", b)' 2>>~/EOE/ != 0 + /error: invalid argument: invalid regex '\['.*/ + EOE +} + +: 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 + : + $* <'' + 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 + : + $* <'' + print $regex.match(" 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 + : + $* <'' + print $regex.search(" bar", '([^\s]+)\s+([^\s]+)', return_match) + EOI + } + } +} -- cgit v1.1