Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
int main()
{
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// 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 ST, class SA, class Allocator, class charT, class traits>
// bool regex_match(const basic_string<charT, ST, SA>&&,
// match_results<
// typename basic_string<charT, ST, SA>::const_iterator,
// Allocator>&,
// const basic_regex<charT, traits>&,
// regex_constants::match_flag_type =
// regex_constants::match_default) = delete;
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <cassert>
int main()
{
{
std::smatch m;
std::regex re{"*"};
std::regex_match(std::string("abcde"), m, re);
}
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_match(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
#include <regex>
#include <cassert>
#include "test_iterators.h"
int main()
{
{
std::cmatch m;
const char s[] = "tournament";
assert(std::regex_match(s, m, std::regex("tour\nto\ntournament",
std::regex_constants::egrep)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 10);
assert(m.position(0) == 0);
assert(m.str(0) == "tournament");
}
{
std::cmatch m;
const char s[] = "ment";
assert(!std::regex_match(s, m, std::regex("tour\n\ntournament",
std::regex_constants::egrep)));
assert(m.size() == 0);
}
{
std::cmatch m;
const char s[] = "tournament";
assert(std::regex_match(s, m, std::regex("(tour|to|tournament)+\ntourna",
std::regex_constants::egrep)));
assert(m.size() == 2);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 10);
assert(m.position(0) == 0);
assert(m.str(0) == "tournament");
}
{
std::cmatch m;
const char s[] = "tourna";
assert(std::regex_match(s, m, std::regex("(tour|to|tournament)+\ntourna",
std::regex_constants::egrep)));
assert(m.size() == 2);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 6);
assert(m.position(0) == 0);
assert(m.str(0) == "tourna");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_match(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
#include <regex>
#include <cassert>
#include "test_iterators.h"
int main()
{
{
std::cmatch m;
const char s[] = "tournament";
assert(std::regex_match(s, m, std::regex("tour\nto\ntournament",
std::regex_constants::grep)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 10);
assert(m.position(0) == 0);
assert(m.str(0) == "tournament");
}
{
std::cmatch m;
const char s[] = "ment";
assert(!std::regex_match(s, m, std::regex("tour\n\ntournament",
std::regex_constants::grep)));
assert(m.size() == 0);
}
}

View File

@@ -0,0 +1,98 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_match(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
// std::regex in ECMAScript mode should not ignore capture groups inside lookahead assertions.
// For example, matching /(?=(a))(a)/ to "a" should yield two captures: \1 = "a", \2 = "a"
#include <regex>
#include <cassert>
#include "test_iterators.h"
int main()
{
{
std::regex re("^(?=(.))a$");
assert(re.mark_count() == 1);
std::string s("a");
std::smatch m;
assert(std::regex_match(s, m, re));
assert(m.size() == 2);
assert(m[0] == "a");
assert(m[1] == "a");
}
{
std::regex re("^(a)(?=(.))(b)$");
assert(re.mark_count() == 3);
std::string s("ab");
std::smatch m;
assert(std::regex_match(s, m, re));
assert(m.size() == 4);
assert(m[0] == "ab");
assert(m[1] == "a");
assert(m[2] == "b");
assert(m[3] == "b");
}
{
std::regex re("^(.)(?=(.)(?=.(.)))(...)$");
assert(re.mark_count() == 4);
std::string s("abcd");
std::smatch m;
assert(std::regex_match(s, m, re));
assert(m.size() == 5);
assert(m[0] == "abcd");
assert(m[1] == "a");
assert(m[2] == "b");
assert(m[3] == "d");
assert(m[4] == "bcd");
}
{
std::regex re("^(a)(?!([^b]))(.c)$");
assert(re.mark_count() == 3);
std::string s("abc");
std::smatch m;
assert(std::regex_match(s, m, re));
assert(m.size() == 4);
assert(m[0] == "abc");
assert(m[1] == "a");
assert(m[2] == "");
assert(m[3] == "bc");
}
{
std::regex re("^(?!((b)))(?=(.))(?!(abc)).b$");
assert(re.mark_count() == 4);
std::string s("ab");
std::smatch m;
assert(std::regex_match(s, m, re));
assert(m.size() == 5);
assert(m[0] == "ab");
assert(m[1] == "");
assert(m[2] == "");
assert(m[3] == "a");
assert(m[4] == "");
}
}

View File

@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_match(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
// http://llvm.org/bugs/show_bug.cgi?id=16135
#include <string>
#include <regex>
#include <cassert>
void
test1()
{
std::string re("\\{a\\}");
std::string target("{a}");
std::regex regex(re);
std::smatch smatch;
assert((std::regex_match(target, smatch, regex)));
}
void
test2()
{
std::string re("\\{a\\}");
std::string target("{a}");
std::regex regex(re, std::regex::extended);
std::smatch smatch;
assert((std::regex_match(target, smatch, regex)));
}
void
test3()
{
std::string re("\\{a\\}");
std::string target("{a}");
std::regex regex(re, std::regex::awk);
std::smatch smatch;
assert((std::regex_match(target, smatch, regex)));
}
void
test4()
{
std::string re("\\{a\\}");
std::string target("{a}");
std::regex regex(re, std::regex::egrep);
std::smatch smatch;
assert((std::regex_match(target, smatch, regex)));
}
int
main()
{
test1();
test2();
test3();
test4();
}

View File

@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// 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 OutputIterator, class BidirectionalIterator,
// class traits, class charT, class ST, class SA>
// OutputIterator
// regex_replace(OutputIterator out,
// BidirectionalIterator first, BidirectionalIterator last,
// const basic_regex<charT, traits>& e,
// const basic_string<charT, ST, SA>& fmt,
// regex_constants::match_flag_type flags =
// regex_constants::match_default);
#include <regex>
#include <cassert>
#include "test_iterators.h"
int main()
{
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
std::string("123-$&"));
assert(r.base() == buf+40);
assert(buf == std::string("123-555-1234, 123-555-2345, 123-555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
std::string("123-$&"),
std::regex_constants::format_sed);
assert(r.base() == buf+43);
assert(buf == std::string("123-$555-1234, 123-$555-2345, 123-$555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
std::string("123-&"),
std::regex_constants::format_sed);
assert(r.base() == buf+40);
assert(buf == std::string("123-555-1234, 123-555-2345, 123-555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
std::string("123-$&"),
std::regex_constants::format_no_copy);
assert(r.base() == buf+36);
assert(buf == std::string("123-555-1234123-555-2345123-555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
std::string("123-$&"),
std::regex_constants::format_first_only);
assert(r.base() == buf+32);
assert(buf == std::string("123-555-1234, 555-2345, 555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
std::string("123-$&"),
std::regex_constants::format_first_only |
std::regex_constants::format_no_copy);
assert(r.base() == buf+12);
assert(buf == std::string("123-555-1234"));
}
}

View File

@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// 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 OutputIterator, class BidirectionalIterator,
// class traits, class charT, class ST, class SA>
// OutputIterator
// regex_replace(OutputIterator out,
// BidirectionalIterator first, BidirectionalIterator last,
// const basic_regex<charT, traits>& e,
// const charT* fmt,
// regex_constants::match_flag_type flags =
// regex_constants::match_default);
#include <regex>
#include <cassert>
#include "test_iterators.h"
int main()
{
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
"123-$&");
assert(r.base() == buf+40);
assert(buf == std::string("123-555-1234, 123-555-2345, 123-555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
"123-$&",
std::regex_constants::format_sed);
assert(r.base() == buf+43);
assert(buf == std::string("123-$555-1234, 123-$555-2345, 123-$555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
"123-&",
std::regex_constants::format_sed);
assert(r.base() == buf+40);
assert(buf == std::string("123-555-1234, 123-555-2345, 123-555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
"123-$&",
std::regex_constants::format_no_copy);
assert(r.base() == buf+36);
assert(buf == std::string("123-555-1234123-555-2345123-555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
"123-$&",
std::regex_constants::format_first_only);
assert(r.base() == buf+32);
assert(buf == std::string("123-555-1234, 555-2345, 555-3456"));
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
typedef output_iterator<char*> Out;
typedef bidirectional_iterator<const char*> Bi;
char buf[100] = {0};
Out r = std::regex_replace(Out(buf), Bi(std::begin(phone_book)),
Bi(std::end(phone_book)-1), phone_numbers,
"123-$&",
std::regex_constants::format_first_only |
std::regex_constants::format_no_copy);
assert(r.base() == buf+12);
assert(buf == std::string("123-555-1234"));
}
}

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// 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 traits, class charT, class ST, class SA, class FST, class FSA>>
// basic_string<charT, ST, SA>
// regex_replace(const basic_string<charT, ST, SA>& s,
// const basic_regex<charT, traits>& e,
// const basic_string<charT, FST, FSA>& fmt,
// regex_constants::match_flag_type flags =
// regex_constants::match_default);
#include <regex>
#include <cassert>
int main()
{
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"));
assert(r == "123-555-1234, 123-555-2345, 123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"),
std::regex_constants::format_sed);
assert(r == "123-$555-1234, 123-$555-2345, 123-$555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-&"),
std::regex_constants::format_sed);
assert(r == "123-555-1234, 123-555-2345, 123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"),
std::regex_constants::format_no_copy);
assert(r == "123-555-1234123-555-2345123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"),
std::regex_constants::format_first_only);
assert(r == "123-555-1234, 555-2345, 555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"),
std::regex_constants::format_first_only |
std::regex_constants::format_no_copy);
assert(r == "123-555-1234");
}
}

View File

@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// 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 traits, class charT, class ST, class SA>
// basic_string<charT, ST, SA>
// regex_replace(const basic_string<charT, ST, SA>& s,
// const basic_regex<charT, traits>& e, const charT* fmt,
// regex_constants::match_flag_type flags =
// regex_constants::match_default);
#include <regex>
#include <cassert>
int main()
{
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&");
assert(r == "123-555-1234, 123-555-2345, 123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&",
std::regex_constants::format_sed);
assert(r == "123-$555-1234, 123-$555-2345, 123-$555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-&",
std::regex_constants::format_sed);
assert(r == "123-555-1234, 123-555-2345, 123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&",
std::regex_constants::format_no_copy);
assert(r == "123-555-1234123-555-2345123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&",
std::regex_constants::format_first_only);
assert(r == "123-555-1234, 555-2345, 555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
std::string phone_book("555-1234, 555-2345, 555-3456");
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&",
std::regex_constants::format_first_only |
std::regex_constants::format_no_copy);
assert(r == "123-555-1234");
}
}

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// 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 traits, class charT, class ST, class SA>
// basic_string<charT>
// regex_replace(const charT* s,
// const basic_regex<charT, traits>& e,
// const basic_string<charT, ST, SA>& fmt,
// regex_constants::match_flag_type flags =
// regex_constants::match_default);
#include <regex>
#include <cassert>
int main()
{
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"));
assert(r == "123-555-1234, 123-555-2345, 123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"),
std::regex_constants::format_sed);
assert(r == "123-$555-1234, 123-$555-2345, 123-$555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-&"),
std::regex_constants::format_sed);
assert(r == "123-555-1234, 123-555-2345, 123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"),
std::regex_constants::format_no_copy);
assert(r == "123-555-1234123-555-2345123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"),
std::regex_constants::format_first_only);
assert(r == "123-555-1234, 555-2345, 555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
std::string("123-$&"),
std::regex_constants::format_first_only |
std::regex_constants::format_no_copy);
assert(r == "123-555-1234");
}
}

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// 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 traits, class charT>
// basic_string<charT>
// regex_replace(const charT* s,
// const basic_regex<charT, traits>& e,
// const charT* fmt,
// regex_constants::match_flag_type flags =
// regex_constants::match_default);
#include <regex>
#include <cassert>
int main()
{
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&");
assert(r == "123-555-1234, 123-555-2345, 123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&",
std::regex_constants::format_sed);
assert(r == "123-$555-1234, 123-$555-2345, 123-$555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-&",
std::regex_constants::format_sed);
assert(r == "123-555-1234, 123-555-2345, 123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&",
std::regex_constants::format_no_copy);
assert(r == "123-555-1234123-555-2345123-555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&",
std::regex_constants::format_first_only);
assert(r == "123-555-1234, 555-2345, 555-3456");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::string r = std::regex_replace(phone_book, phone_numbers,
"123-$&",
std::regex_constants::format_first_only |
std::regex_constants::format_no_copy);
assert(r == "123-555-1234");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_search(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
#include <regex>
#include <string>
#include <list>
#include <cassert>
int main()
{
// This regex_iterator uses regex_search(__wrap_iter<_Iter> __first, ...)
// Test for http://llvm.org/bugs/show_bug.cgi?id=16240 fixed in r185273.
{
std::string s("aaaa a");
std::regex re("\\ba");
std::sregex_iterator it(s.begin(), s.end(), re);
std::sregex_iterator end = std::sregex_iterator();
assert(it->position(0) == 0);
assert(it->length(0) == 1);
++it;
assert(it->position(0) == 5);
assert(it->length(0) == 1);
++it;
assert(it == end);
}
// This regex_iterator uses regex_search(_BidirectionalIterator __first, ...)
{
std::string s("aaaa a");
std::list<char> l(s.begin(), s.end());
std::regex re("\\ba");
std::regex_iterator<std::list<char>::iterator> it(l.begin(), l.end(), re);
std::regex_iterator<std::list<char>::iterator> end = std::regex_iterator<std::list<char>::iterator>();
assert(it->position(0) == 0);
assert(it->length(0) == 1);
++it;
assert(it->position(0) == 5);
assert(it->length(0) == 1);
++it;
assert(it == end);
}
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// 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 ST, class SA, class Allocator, class charT, class traits>
// bool regex_search(const basic_string<charT, ST, SA>&&,
// match_results<
// typename basic_string<charT, ST, SA>::const_iterator,
// Allocator>&,
// const basic_regex<charT, traits>&,
// regex_constants::match_flag_type =
// regex_constants::match_default) = delete;
#include <__config>
#if _LIBCPP_STD_VER <= 11
#error
#else
#include <regex>
#include <cassert>
int main()
{
{
std::smatch m;
std::regex re{"*"};
std::regex_search(std::string("abcde"), m, re);
}
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,90 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_search(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
#include <regex>
#include <cassert>
#include "test_iterators.h"
int main()
{
{
std::cmatch m;
const char s[] = "tournament";
assert(std::regex_search(s, m, std::regex("tour\nto\ntournament",
std::regex_constants::egrep)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 10);
assert(m.position(0) == 0);
assert(m.str(0) == "tournament");
}
{
std::cmatch m;
const char s[] = "ment";
assert(std::regex_search(s, m, std::regex("tour\n\ntournament",
std::regex_constants::egrep)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 0);
assert(m.position(0) == 0);
assert(m.str(0) == "");
}
{
std::cmatch m;
const char s[] = "tournament";
assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+\ntourna",
std::regex_constants::egrep)));
assert(m.size() == 2);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 10);
assert(m.position(0) == 0);
assert(m.str(0) == "tournament");
}
{
std::cmatch m;
const char s[] = "tourna";
assert(std::regex_search(s, m, std::regex("(tour|to|tournament)+\ntourna",
std::regex_constants::egrep)));
assert(m.size() == 2);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 6);
assert(m.position(0) == 0);
assert(m.str(0) == "tourna");
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_search(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
#include <regex>
#include <cassert>
#include "test_iterators.h"
int main()
{
{
std::cmatch m;
const char s[] = "tournament";
assert(std::regex_search(s, m, std::regex("tour\nto\ntournament",
std::regex_constants::grep)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(!m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 10);
assert(m.position(0) == 0);
assert(m.str(0) == "tournament");
}
{
std::cmatch m;
const char s[] = "ment";
assert(std::regex_search(s, m, std::regex("tour\n\ntournament",
std::regex_constants::grep)));
assert(m.size() == 1);
assert(!m.prefix().matched);
assert(m.prefix().first == s);
assert(m.prefix().second == m[0].first);
assert(m.suffix().matched);
assert(m.suffix().first == m[0].second);
assert(m.suffix().second == s + std::char_traits<char>::length(s));
assert(m.length(0) == 0);
assert(m.position(0) == 0);
assert(m.str(0) == "");
}
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_search(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
// http://llvm.org/bugs/show_bug.cgi?id=11118
#include <regex>
#include <cassert>
int main()
{
assert(!std::regex_search("ab", std::regex("(?=^)b")));
assert(!std::regex_search("ab", std::regex("a(?=^)b")));
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// 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 BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_search(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
#include <regex>
#include <cassert>
int main()
{
// Iterating over /^a/ should yield one instance at the beginning
// of the text.
const char *text = "aaa\naa";
std::regex re("^a");
std::cregex_iterator it(text, text+6, re);
std::cregex_iterator end = std::cregex_iterator();
assert(it->str() == "a");
assert(it->position(0) == 0);
assert(it->length(0) == 1);
++it;
assert(it == end);
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
int main()
{
}