diff options
author | Tim Shen <timshen91@gmail.com> | 2013-09-18 15:56:20 +0000 |
---|---|---|
committer | Tim Shen <timshen@gcc.gnu.org> | 2013-09-18 15:56:20 +0000 |
commit | b21abceec3c77f2b847b4687947d7fcf745ffdf9 (patch) | |
tree | db5788d9dc9a22dd1aeac31c52fb72395dd7756d /libstdc++-v3/testsuite/28_regex | |
parent | 64bc8861e91cba89fbdeb0880395315ecc2dcf28 (diff) | |
download | gcc-b21abceec3c77f2b847b4687947d7fcf745ffdf9.zip gcc-b21abceec3c77f2b847b4687947d7fcf745ffdf9.tar.gz gcc-b21abceec3c77f2b847b4687947d7fcf745ffdf9.tar.bz2 |
regex.h: Add friend classes.
2013-09-18 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h: Add friend classes.
(match_results<>::position, regex_iterator<>::operator++):
Implement position specification in regex_iterator.
(regex_match<>, regex_search<>):
Move match_results initializations to these function. Remove `todo`.
* include/bits/regex_compiler.tcc:
(_Compiler<>::_M_quantifier): Fix greedy/ungreedy of interval matching.
* include/bits/regex_constants.h:
Fix indentation. Change match_flag_type to enum type.
* include/bits/regex_executor.h:
Merge identical code to the base class _Executor.
Support flags in regex_constants.
* include/bits/regex_executor.tcc: Likewise.
* include/bits/regex_scanner.h: Add comments.
* include/bits/regex_scanner.tcc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc:
Add a testcase.
* testsuite/28_regex/algorithms/regex_search/ecma/flags.cc: New.
* testsuite/28_regex/iterators/regex_iterator/char/
string_position_01.cc: Remove `xfail`.
* testsuite/28_regex/iterators/regex_iterator/wchar_t/string_02.cc:
Remove `xfail` and make the case really work.
From-SVN: r202706
Diffstat (limited to 'libstdc++-v3/testsuite/28_regex')
4 files changed, 101 insertions, 12 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 index 82e9905..3064b3b 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc @@ -1,5 +1,4 @@ // { dg-options "-std=gnu++11" } -// { dg-do run { xfail *-*-* } } // // 2013-09-14 Tim Shen <timshen91@gmail.com> @@ -54,22 +53,37 @@ test01() 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 != sregex_iterator(); ++it) { string s((*it)[0].first, (*it)[0].second); VERIFY(s == sol[i++]); } - VERIFY(i == 5); + VERIFY(i == 10); + + { + cmatch m; + regex re("(?=(as)df)as(df)"); + regex_search("asdf", m, re); + VERIFY(m.size() == 3); + VERIFY(m[0].matched && string(m[0].first, m[0].second) == "asdf"); + VERIFY(m[1].matched && string(m[1].first, m[1].second) == "as"); + VERIFY(m[2].matched && string(m[2].first, m[2].second) == "df"); + } } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/flags.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/flags.cc new file mode 100644 index 0000000..4be406cb --- /dev/null +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/flags.cc @@ -0,0 +1,71 @@ +// { dg-options "-std=gnu++11" } + +// +// 2013-09-18 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 flags. + +#include <regex> +#include <testsuite_hooks.h> + +using namespace std; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + cmatch m; + regex re("((as)(df))", regex_constants::ECMAScript | regex_constants::nosubs); + VERIFY(regex_search("asdf", m, re)); + VERIFY(m.size() == 1); + VERIFY(m[0].matched && string(m[0].first, m[0].second) == "asdf"); + + VERIFY( regex_search("a", regex("^a"))); + VERIFY(!regex_search("a", regex("^a"), regex_constants::match_not_bol)); + VERIFY( regex_search("a", regex("a$"))); + VERIFY(!regex_search("a", regex("a$"), regex_constants::match_not_eol)); + VERIFY( regex_search("a", regex("\\ba"))); + VERIFY(!regex_search("a", regex("\\ba"), regex_constants::match_not_bow)); + VERIFY( regex_search("a", regex("a\\b"))); + VERIFY(!regex_search("a", regex("a\\b"), regex_constants::match_not_eow)); + VERIFY( regex_search("", regex(""))); + VERIFY(!regex_search("", regex(""), regex_constants::match_not_null)); + VERIFY( regex_search("", regex("^$"))); + VERIFY(!regex_search("", regex("^$"), regex_constants::match_not_null)); + VERIFY( regex_search("aaa", m, regex("a*?"), + regex_constants::match_not_null)); + VERIFY(m[0].matched && string(m[0].first, m[0].second) == "a"); + VERIFY( regex_search("asdf", regex("sdf"))); + VERIFY(!regex_search("asdf", regex("sdf"), + regex_constants::match_continuous)); + VERIFY( regex_search(" a"+1, regex("\\ba"), + regex_constants::match_prev_avail)); + VERIFY( regex_search("ba"+1, regex("\\Ba"), + regex_constants::match_prev_avail)); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc index 75ef058..9785650 100644 --- a/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc +++ b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc @@ -1,5 +1,4 @@ // { dg-options "-std=gnu++11" } -// { dg-do run { xfail *-*-* } } // // 2013-07-25 Tim Shen <timshen91@gmail.com> diff --git a/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/wchar_t/string_02.cc b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/wchar_t/string_02.cc index cd2c68e..9cb96f7 100644 --- a/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/wchar_t/string_02.cc +++ b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/wchar_t/string_02.cc @@ -1,6 +1,5 @@ // { dg-options "-std=gnu++11" } // { dg-require-namedlocale "en_US.UTF-8" } -// { dg-do run { xfail *-*-* } } // // 2013-09-05 Tim Shen <timshen91@gmail.com> @@ -42,13 +41,19 @@ test01() re2.assign(L"([[:lower:]]{0,1}[[:space:]]{0,1}[[:upper:]]{0,1})"); - std::wsregex_iterator p(str2.begin(), str2.end(), re2); - auto a = p; - ++p; - VERIFY(a != p); - //for (std::wsregex_iterator p(str2.begin(), str2.end(), re2); - // p != std::wsregex_iterator{}; ++p) - // std::wcout << (*p)[1] << std::endl; + std::wstring sol[] = + { + L"ä\u2009Ä", + L"\u2009", + L"ö\u2009Ö", + L"\u2009", + L"ü\u2009Ü", + L"", + }; + int i = 0; + for (std::wsregex_iterator p(str2.begin(), str2.end(), re2); + p != std::wsregex_iterator{}; ++p) + VERIFY(std::wstring((*p)[1].first, (*p)[1].second) == sol[i++]); } int |