aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/28_regex
diff options
context:
space:
mode:
authorTim Shen <timshen91@gmail.com>2013-09-14 14:23:44 +0000
committerTim Shen <timshen@gcc.gnu.org>2013-09-14 14:23:44 +0000
commit7b86458e38ee3c88ca4e222c85ef6fa883267315 (patch)
treee9e7682ad565de0099407469cf75a3455639b6f2 /libstdc++-v3/testsuite/28_regex
parent492d1e0ac5c5bae22a29c0e436b50603052f2c29 (diff)
downloadgcc-7b86458e38ee3c88ca4e222c85ef6fa883267315.zip
gcc-7b86458e38ee3c88ca4e222c85ef6fa883267315.tar.gz
gcc-7b86458e38ee3c88ca4e222c85ef6fa883267315.tar.bz2
regex.h (regex_match<>, [...]): Change regex_executor caller.
2013-09-14 Tim Shen <timshen91@gmail.com> * include/bits/regex.h (regex_match<>, regex_search<>): Change regex_executor caller. Now use their return value instead of checking __m[0].matched to find out if it's successful. (regex_search<>): Move the search logic to regex_executor. * include/bits/regex_automaton.h: Add some new _Opcode. Refactor _NFA::_M_insert_*. * include/bits/regex_automaton.tcc: Add DEBUG dump for new _Opcode. Refactor _NFA::_M_insert_*. * include/bits/regex_compiler.h (_Compiler<>::_M_get_nfa): Use make_shared instead of construct by hand. * include/bits/regex_compiler.tcc: Implement _Compiler<>::_M_assertion. * include/bits/regex_constants.h: Fix indentation and line breaking. * include/bits/regex_executor.h: Add _ResultsEntry to support greedy/ungreedy mode. Move regex_search logic here. * include/bits/regex_executor.tcc: Implement assertions and greedy/ungreedy matching. * include/bits/regex_scanner.h: Add a new token _S_token_ungreedy. * include/bits/regex_scanner.tcc: Parse a new token _S_token_ungreedy. * testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc: New. * testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc: New. * testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc: Fix comment. From-SVN: r202591
Diffstat (limited to 'libstdc++-v3/testsuite/28_regex')
-rw-r--r--libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc80
-rw-r--r--libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc71
-rw-r--r--libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc2
3 files changed, 152 insertions, 1 deletions
diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc
new file mode 100644
index 0000000..82e9905
--- /dev/null
+++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc
@@ -0,0 +1,80 @@
+// { dg-options "-std=gnu++11" }
+// { dg-do run { xfail *-*-* } }
+
+//
+// 2013-09-14 Tim Shen <timshen91@gmail.com>
+//
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 28.11.3 regex_search
+// Tests ECMAScript assertion.
+
+#include <regex>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ VERIFY(!regex_search("2123456", regex("^1234")));
+ VERIFY(regex_search("123456", regex("^1234")));
+ VERIFY(regex_search("123456", regex("(5|^)1234")));
+ VERIFY(regex_search("5123456", regex("(5|^)1234")));
+ VERIFY(!regex_search("1234562", regex("3456$")));
+ VERIFY(regex_search("123456", regex("3456$")));
+ VERIFY(!regex_search("123456", regex("(?=1234)56")));
+ VERIFY(regex_search("123456", regex("(?=1234)123456")));
+ VERIFY(regex_search("123456", regex("(?!1234)56")));
+ VERIFY(!regex_search("123456", regex("(?!1234)123456")));
+
+ VERIFY(regex_search("a-", regex("a\\b-")));
+ VERIFY(!regex_search("ab", regex("a\\bb")));
+ VERIFY(!regex_search("a-", regex("a\\B-")));
+ VERIFY(regex_search("ab", regex("a\\Bb")));
+
+ string s("This is a regular expression");
+ string sol[] =
+ {
+ "This",
+ "is",
+ "a",
+ "regular",
+ "expression",
+ };
+
+ regex re("\\b\\w*\\b");
+ int i = 0;
+ for (auto it = sregex_iterator(s.begin(), s.end(), re);
+ it != sregex_iterator() && i < 5;
+ ++it)
+ {
+ string s((*it)[0].first, (*it)[0].second);
+ VERIFY(s == sol[i++]);
+ }
+ VERIFY(i == 5);
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc
new file mode 100644
index 0000000..ad37ec8
--- /dev/null
+++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc
@@ -0,0 +1,71 @@
+// { dg-options "-std=gnu++11" }
+
+//
+// 2013-09-14 Tim Shen <timshen91@gmail.com>
+//
+// Copyright (C) 2013 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 28.11.3 regex_search
+// Tests ECMAScript greedy and ungreedy quantifiers.
+
+#include <regex>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ cmatch m;
+#define TEST(i, s) VERIFY(m[i].matched && string(m[i].first, m[i].second) == s)
+ VERIFY(regex_search("aaaa", m, regex("a*")));
+ TEST(0, "aaaa");
+ VERIFY(regex_search("aaaa", m, regex("a*?")));
+ TEST(0, "");
+ VERIFY(regex_search("aaaa", m, regex("a+")));
+ TEST(0, "aaaa");
+ VERIFY(regex_search("aaaa", m, regex("a+?")));
+ TEST(0, "a");
+ VERIFY(regex_search("a", m, regex("a?")));
+ TEST(0, "a");
+ VERIFY(regex_search("a", m, regex("a??")));
+ TEST(0, "");
+ VERIFY(regex_search("", m, regex("a??")));
+ TEST(0, "");
+ VERIFY(regex_search("aaaa", m, regex("(a+)(a+)")));
+ TEST(1, "aaa");
+ TEST(2, "a");
+ VERIFY(regex_search("aaaa", m, regex("(a+?)(a+)")));
+ TEST(1, "a");
+ TEST(2, "aaa");
+ VERIFY(regex_search("aaaa", m, regex("(a+?)(a+)")));
+ TEST(1, "a");
+ TEST(2, "aaa");
+ VERIFY(regex_search("aaaa", m, regex("(a+?)(a+?)")));
+ TEST(1, "a");
+ TEST(2, "a");
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc
index a2d290d..ec25875 100644
--- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc
+++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc
@@ -21,7 +21,7 @@
// <http://www.gnu.org/licenses/>.
// 28.11.3 regex_search
-// Tests BRE against a std::string target.
+// Tests ECMAScript against a std::string target.
#include <regex>
#include <testsuite_hooks.h>