diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
commit | 53a420fba21cf1644972b34dcd811a43cdb8368d (patch) | |
tree | 66a19f6f8b65215772549a51d688492ab8addc0d /test/std/re/re.regex/re.regex.construct | |
parent | b50f1549701eb950921e5d6f2e55ba1a1dadbb43 (diff) |
Notes
Diffstat (limited to 'test/std/re/re.regex/re.regex.construct')
4 files changed, 85 insertions, 2 deletions
diff --git a/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp b/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp new file mode 100644 index 000000000000..aca4d674d9f9 --- /dev/null +++ b/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-no-exceptions +// <regex> + +// template <class charT, class traits = regex_traits<charT>> class basic_regex; + +// template <class ST, class SA> +// basic_regex(const basic_string<charT, ST, SA>& s); + +#include <regex> +#include <cassert> +#include "test_macros.h" + +static bool error_badbackref_thrown(const char *pat) +{ + bool result = false; + try { + std::regex re(pat); + } catch (const std::regex_error &ex) { + result = (ex.code() == std::regex_constants::error_backref); + } + return result; +} + +int main() +{ + assert(error_badbackref_thrown("\\1abc")); // no references + assert(error_badbackref_thrown("ab(c)\\2def")); // only one reference + +// this should NOT throw, because we only should look at the '1' +// See https://llvm.org/bugs/show_bug.cgi?id=31387 + { + const char *pat1 = "a(b)c\\1234"; + std::regex re(pat1, pat1 + 7); // extra chars after the end. + } +} diff --git a/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp b/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp index 3c7e9f5e33c7..93b21ec9e9f6 100644 --- a/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp +++ b/test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions +// UNSUPPORTED: libcpp-no-exceptions // <regex> // template <class charT, class traits = regex_traits<charT>> class basic_regex; diff --git a/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp b/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp index 0692a59542f6..0f30a8b2082b 100644 --- a/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp +++ b/test/std/re/re.regex/re.regex.construct/bad_repeat.pass.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -// XFAIL: libcpp-no-exceptions +// UNSUPPORTED: libcpp-no-exceptions // <regex> // template <class charT, class traits = regex_traits<charT>> class basic_regex; diff --git a/test/std/re/re.regex/re.regex.construct/ptr_size.pass.cpp b/test/std/re/re.regex/re.regex.construct/ptr_size.pass.cpp new file mode 100644 index 000000000000..90a091a21c2a --- /dev/null +++ b/test/std/re/re.regex/re.regex.construct/ptr_size.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// template <class charT, class traits = regex_traits<charT>> class basic_regex; + +// basic_regex(const charT* p, size_t len); + +#include <regex> +#include <cassert> + +template <class CharT> +void +test(const CharT* p, std::size_t len, unsigned mc) +{ + std::basic_regex<CharT> r(p, len); + assert(r.flags() == std::regex_constants::ECMAScript); + assert(r.mark_count() == mc); +} + +int main() +{ + test("\\(a\\)", 5, 0); + test("\\(a[bc]\\)", 9, 0); + test("\\(a\\([bc]\\)\\)", 13, 0); + test("(a([bc]))", 9, 2); + + test("(\0)(b)(c)(d)", 12, 4); + test("(\0)(b)(c)(d)", 9, 3); + test("(\0)(b)(c)(d)", 3, 1); + test("(\0)(b)(c)(d)", 0, 0); +} |