aboutsummaryrefslogtreecommitdiff
path: root/tests/regex/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/regex/driver.cxx')
-rw-r--r--tests/regex/driver.cxx43
1 files changed, 20 insertions, 23 deletions
diff --git a/tests/regex/driver.cxx b/tests/regex/driver.cxx
index f78a100..f8363e1 100644
--- a/tests/regex/driver.cxx
+++ b/tests/regex/driver.cxx
@@ -1,33 +1,23 @@
// file : tests/regex/driver.cxx -*- C++ -*-
// license : MIT; see accompanying LICENSE file
-#include <cassert>
-
-#ifndef __cpp_lib_modules_ts
+#include <regex>
#include <string>
+#include <utility> // pair
#include <iostream>
+#include <stdexcept> // invalid_argument
#include <exception>
-#endif
-// Other includes.
+#include <libbutl/regex.hxx>
+#include <libbutl/utility.hxx> // operator<<(ostream, exception)
-#ifdef __cpp_modules_ts
-#ifdef __cpp_lib_modules_ts
-import std.core;
-import std.io;
-import std.regex; // @@ MOD TODO: shouldn't be necessary (re-export).
-#endif
-import butl.regex;
-import butl.utility; // operator<<(ostream, exception)
-#else
-#include <libbutl/regex.mxx>
-#include <libbutl/utility.mxx>
-#endif
+#undef NDEBUG
+#include <cassert>
using namespace std;
using namespace butl;
-// Usage: argv[0] [-ffo] [-fnc] [-m] <string> <regex> <format>
+// Usage: argv[0] [-ffo] [-fnc] [-m] <string> "/<regex>/<format>/"
//
// Perform substitution of matched substrings with formatted replacement
// strings using regex_replace_*() functions. If the string matches the regex
@@ -66,11 +56,13 @@ try
break;
}
- assert (i + 3 == argc);
+ assert (i + 2 == argc);
+
+ string s (argv[i++]);
+ pair<regex, string> rf (regex_replace_parse (argv[i]));
- string s (argv[i++]);
- regex re (argv[i++]);
- string fmt (argv[i]);
+ const regex& re (rf.first);
+ const string& fmt (rf.second);
auto r (match
? regex_replace_match (s, re, fmt)
@@ -86,8 +78,13 @@ catch (const regex_error& e)
cerr << "invalid regex" << e << endl; // Print sanitized.
return 2;
}
-catch (const exception& e)
+catch (const invalid_argument& e)
{
cerr << e << endl;
return 2;
}
+catch (const exception&)
+{
+ assert (false);
+ return 2;
+}