From 8286ac511144e4f17d34eac9affb97e50646344a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 23 Jul 2014 15:25:44 +0200 Subject: Imported Upstream version 4.0.0 --- libcutl/tests/re/driver.cxx | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 libcutl/tests/re/driver.cxx (limited to 'libcutl/tests/re/driver.cxx') diff --git a/libcutl/tests/re/driver.cxx b/libcutl/tests/re/driver.cxx new file mode 100644 index 0000000..4b070dd --- /dev/null +++ b/libcutl/tests/re/driver.cxx @@ -0,0 +1,83 @@ +// file : tests/re/driver.cxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#include +#include +#include + +#include + +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; + } +} -- cgit v1.2.3