aboutsummaryrefslogtreecommitdiff
path: root/tests/re/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/re/driver.cxx')
-rw-r--r--tests/re/driver.cxx84
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/re/driver.cxx b/tests/re/driver.cxx
new file mode 100644
index 0000000..4f5683d
--- /dev/null
+++ b/tests/re/driver.cxx
@@ -0,0 +1,84 @@
+// file : tests/re/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <string>
+#include <cassert>
+#include <iostream>
+
+#include <cutl/re.hxx>
+
+using namespace cutl::re;
+
+int
+main ()
+{
+ // empty() and str().
+ //
+ {
+ regex r;
+ assert (r.empty ());
+ r = "['`]foo([^ ]*)bar['`]";
+ assert (!r.empty ());
+ assert (r.str () == "['`]foo([^ ]*)bar['`]");
+ }
+
+ // Error handling.
+ //
+ try
+ {
+ regex r ("['`]foo([^ ]*bar['`]");
+ assert (false);
+ }
+ catch (format const& e)
+ {
+ assert (e.regex () == "['`]foo([^ ]*bar['`]");
+ assert (!e.description ().empty ());
+ //std::cerr << e.description () << std::endl;
+ }
+
+ // match(), search(), and replace().
+ //
+ {
+ regex r ("['`]foo([^ ]*)bar['`]");
+
+ assert (r.match ("'foofoxbar'"));
+ assert (!r.match ("'foof xbar'"));
+
+ assert (r.search ("prefix 'foofoxbar' suffix"));
+ assert (!r.search ("prefix 'foof xbar' suffix"));
+
+ assert (r.replace ("'foofoxbar'", "\\u$1") == "Fox");
+ }
+
+ // regexsub
+ //
+ {
+ regexsub r ("/['`]foo([^ ]*)bar['`]/\\u$1/");
+
+ assert (r.replace ("'foofoxbar'") == "Fox");
+ }
+
+ // regexsub escaping
+ //
+ {
+ regexsub r ("#a\\#\\\\\\\\#a?\\\\\\\\#");
+
+ assert (r.replace ("a#\\") == "a?\\");
+ }
+
+ // regexsub error handling.
+ //
+ try
+ {
+ regexsub r ("/['`]foo([^ ]*)bar['`]#\\u$1/");
+ assert (false);
+ }
+ catch (format const& e)
+ {
+ assert (e.regex () == "/['`]foo([^ ]*)bar['`]#\\u$1/");
+ assert (!e.description ().empty ());
+ //std::cerr << e.description () << std::endl;
+ }
+}