aboutsummaryrefslogtreecommitdiff
path: root/tests/regex
diff options
context:
space:
mode:
Diffstat (limited to 'tests/regex')
-rw-r--r--tests/regex/driver.cxx14
-rw-r--r--tests/regex/testscript11
2 files changed, 21 insertions, 4 deletions
diff --git a/tests/regex/driver.cxx b/tests/regex/driver.cxx
index 0f6a385..fb41ba2 100644
--- a/tests/regex/driver.cxx
+++ b/tests/regex/driver.cxx
@@ -28,10 +28,10 @@ import butl.utility; // operator<<(ostream, exception)
using namespace std;
using namespace butl;
-// Usage: argv[0] [-ffo] [-fnc] <string> <regex> <format>
+// Usage: argv[0] [-ffo] [-fnc] [-m] <string> <regex> <format>
//
// Perform substitution of matched substrings with formatted replacement
-// strings using regex_replace_ex() function. If the string matches the regex
+// strings using regex_replace_*() functions. If the string matches the regex
// then print the replacement to STDOUT and exit with zero code. Exit with
// code one if it doesn't match, and with code two on failure (print error
// description to STDERR).
@@ -42,6 +42,9 @@ using namespace butl;
// -fnc
// Use format_no_copy replacement flag.
//
+// -m
+// Match the entire string, rather than its sub-strings.
+//
int
main (int argc, const char* argv[])
try
@@ -49,6 +52,7 @@ try
regex_constants::match_flag_type fl (regex_constants::match_default);
int i (1);
+ bool match (false);
for (; i != argc; ++i)
{
string op (argv[i]);
@@ -57,6 +61,8 @@ try
fl |= regex_constants::format_first_only;
else if (op == "-fnc")
fl |= regex_constants::format_no_copy;
+ else if (op == "-m")
+ match = true;
else
break;
}
@@ -67,7 +73,9 @@ try
regex re (argv[i++]);
string fmt (argv[i]);
- auto r (regex_replace_ex (s, re, fmt, fl));
+ auto r (match
+ ? regex_replace_match (s, re, fmt)
+ : regex_replace_search (s, re, fmt, fl));
if (r.second)
cout << r.first << endl;
diff --git a/tests/regex/testscript b/tests/regex/testscript
index 4b03e45..d431756 100644
--- a/tests/regex/testscript
+++ b/tests/regex/testscript
@@ -2,7 +2,7 @@
# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
-: match
+: replace-search
:
{
$* abcbd b x >axcxd : all
@@ -58,3 +58,12 @@
$* xay a '\lVZ' >xvZy
}
}
+
+: replace-match
+:
+{
+ test.options += -m
+
+ $* abc 'a(b)c' 'x\1y' >xby : match
+ $* abcd 'a(b)c' 'x\1yd' == 1 : no-match
+}