diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2010-08-17 20:42:03 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2010-08-17 20:42:03 +0000 |
| commit | 14dcd3d1ff4da48deed3f619dc57f485f9374299 (patch) | |
| tree | 13d402bb5cebdf192207f7fcff070175a502091d /libcxx/test | |
| parent | e2cbaf6ed7712880477888608d7e7eb2b787d949 (diff) | |
| download | bcm5719-llvm-14dcd3d1ff4da48deed3f619dc57f485f9374299.tar.gz bcm5719-llvm-14dcd3d1ff4da48deed3f619dc57f485f9374299.zip | |
[re.tokiter]
llvm-svn: 111278
Diffstat (limited to 'libcxx/test')
9 files changed, 588 insertions, 0 deletions
diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp new file mode 100644 index 00000000000..c876fcf0761 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// class regex_token_iterator<BidirectionalIterator, charT, traits> + +// template <size_t N> +// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, +// const regex_type& re, +// const int (&submatches)[N], +// regex_constants::match_flag_type m = +// regex_constants::match_default); + +#include <regex> +#include <cassert> + +int main() +{ + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + const int indices[] = {-1, 0, 1}; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, indices); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "start "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-3456"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "3456"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == " end"); + ++i; + assert(i == std::cregex_token_iterator()); + } +}
\ No newline at end of file diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp new file mode 100644 index 00000000000..88b5c2396e5 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/default.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// class regex_token_iterator<BidirectionalIterator, charT, traits> + +// regex_token_iterator(); + +#include <regex> +#include <cassert> + +template <class CharT> +void +test() +{ + typedef std::regex_token_iterator<const CharT*> I; + I i1; + assert(i1 == I()); +} + +int main() +{ + test<char>(); + test<wchar_t>(); +}
\ No newline at end of file diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.pass.cpp new file mode 100644 index 00000000000..1f85dec3765 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/init.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// class regex_token_iterator<BidirectionalIterator, charT, traits> + +// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, +// const regex_type& re, +// initializer_list<int> submatches, +// regex_constants::match_flag_type m = +// regex_constants::match_default); + +#include <regex> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, {-1, 0, 1}); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "start "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-3456"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "3456"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == " end"); + ++i; + assert(i == std::cregex_token_iterator()); + } +#endif +}
\ No newline at end of file diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.pass.cpp new file mode 100644 index 00000000000..45afd9bba31 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/int.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// class regex_token_iterator<BidirectionalIterator, charT, traits> + +// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, +// const regex_type& re, int submatch = 0, +// regex_constants::match_flag_type m = +// regex_constants::match_default); + +#include <regex> +#include <cassert> + +int main() +{ + { + std::regex phone_numbers("\\d{3}-\\d{4}"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, -1); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "start "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == " end"); + ++i; + assert(i == std::cregex_token_iterator()); + } + { + std::regex phone_numbers("\\d{3}-\\d{4}"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-3456"); + ++i; + assert(i == std::cregex_token_iterator()); + } + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, 1); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "3456"); + ++i; + assert(i == std::cregex_token_iterator()); + } +}
\ No newline at end of file diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.pass.cpp new file mode 100644 index 00000000000..f614f075c0d --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.cnstr/vector.pass.cpp @@ -0,0 +1,128 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// class regex_token_iterator<BidirectionalIterator, charT, traits> + +// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, +// const regex_type& re, +// const std::vector<int>& submatches, +// regex_constants::match_flag_type m = +// regex_constants::match_default); + +#include <regex> +#include <cassert> + +int main() +{ + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::vector<int> v; + v.push_back(-1); + v.push_back(-1); + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, v); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "start "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "start "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == " end"); + ++i; + assert(i == std::cregex_token_iterator()); + } + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::vector<int> v; + v.push_back(-1); + v.push_back(0); + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, v); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "start "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-3456"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == " end"); + ++i; + assert(i == std::cregex_token_iterator()); + } + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::vector<int> v; + v.push_back(-1); + v.push_back(0); + v.push_back(1); + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, v); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "start "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-3456"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "3456"); + ++i; + assert(i != std::cregex_token_iterator()); + assert(i->str() == " end"); + ++i; + assert(i == std::cregex_token_iterator()); + } +}
\ No newline at end of file diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.comp/equal.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.comp/equal.pass.cpp new file mode 100644 index 00000000000..d76c3b0f6aa --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.comp/equal.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// class regex_token_iterator<BidirectionalIterator, charT, traits> + +// bool operator==(const regex_token_iterator& right) const; +// bool operator!=(const regex_token_iterator& right) const; + +#include <regex> +#include <cassert> + +int main() +{ + { + std::regex phone_numbers("\\d{3}-\\d{4}"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, -1); + assert(i != std::cregex_token_iterator()); + assert(!(i == std::cregex_token_iterator())); + std::cregex_token_iterator i2 = i; + assert(i2 == i); + assert(!(i2 != i)); + ++i; + assert(!(i2 == i)); + assert(i2 != i); + } +}
\ No newline at end of file diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp new file mode 100644 index 00000000000..a2599d562a8 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.deref/deref.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// class regex_token_iterator<BidirectionalIterator, charT, traits> + +// const value_type& operator*() const; + +#include <regex> +#include <cassert> + +int main() +{ + { + std::regex phone_numbers("\\d{3}-\\d{4}"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, -1); + assert(i != std::cregex_token_iterator()); + assert((*i).str() == "start "); + ++i; + assert(i != std::cregex_token_iterator()); + assert((*i).str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert((*i).str() == ", "); + ++i; + assert(i != std::cregex_token_iterator()); + assert((*i).str() == " end"); + ++i; + assert(i == std::cregex_token_iterator()); + } + { + std::regex phone_numbers("\\d{3}-\\d{4}"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers); + assert(i != std::cregex_token_iterator()); + assert((*i).str() == "555-1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert((*i).str() == "555-2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert((*i).str() == "555-3456"); + ++i; + assert(i == std::cregex_token_iterator()); + } + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, 1); + assert(i != std::cregex_token_iterator()); + assert((*i).str() == "1234"); + ++i; + assert(i != std::cregex_token_iterator()); + assert((*i).str() == "2345"); + ++i; + assert(i != std::cregex_token_iterator()); + assert((*i).str() == "3456"); + ++i; + assert(i == std::cregex_token_iterator()); + } +}
\ No newline at end of file diff --git a/libcxx/test/re/re.iter/re.tokiter/re.tokiter.incr/post.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.incr/post.pass.cpp new file mode 100644 index 00000000000..105ecf76eb9 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/re.tokiter.incr/post.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// class regex_token_iterator<BidirectionalIterator, charT, traits> + +// regex_token_iterator& operator++(int); + +#include <regex> +#include <cassert> + +int main() +{ + { + std::regex phone_numbers("\\d{3}-\\d{4}"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, -1); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "start "); + i++; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + i++; + assert(i != std::cregex_token_iterator()); + assert(i->str() == ", "); + i++; + assert(i != std::cregex_token_iterator()); + assert(i->str() == " end"); + i++; + assert(i == std::cregex_token_iterator()); + } + { + std::regex phone_numbers("\\d{3}-\\d{4}"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-1234"); + i++; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-2345"); + i++; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "555-3456"); + i++; + assert(i == std::cregex_token_iterator()); + } + { + std::regex phone_numbers("\\d{3}-(\\d{4})"); + const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end"; + std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book), + phone_numbers, 1); + assert(i != std::cregex_token_iterator()); + assert(i->str() == "1234"); + i++; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "2345"); + i++; + assert(i != std::cregex_token_iterator()); + assert(i->str() == "3456"); + i++; + assert(i == std::cregex_token_iterator()); + } +}
\ No newline at end of file diff --git a/libcxx/test/re/re.iter/re.tokiter/types.pass.cpp b/libcxx/test/re/re.iter/re.tokiter/types.pass.cpp new file mode 100644 index 00000000000..75cdae8da88 --- /dev/null +++ b/libcxx/test/re/re.iter/re.tokiter/types.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> + +// template <class BidirectionalIterator, +// class charT = typename iterator_traits< BidirectionalIterator>::value_type, +// class traits = regex_traits<charT>> +// class regex_token_iterator +// { +// public: +// typedef basic_regex<charT, traits> regex_type; +// typedef sub_match<BidirectionalIterator> value_type; +// typedef ptrdiff_t difference_type; +// typedef const value_type* pointer; +// typedef const value_type& reference; +// typedef forward_iterator_tag iterator_category; + +#include <regex> +#include <type_traits> + +template <class CharT> +void +test() +{ + typedef std::regex_token_iterator<const CharT*> I; + static_assert((std::is_same<typename I::regex_type, std::basic_regex<CharT> >::value), ""); + static_assert((std::is_same<typename I::value_type, std::sub_match<const CharT*> >::value), ""); + static_assert((std::is_same<typename I::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<typename I::pointer, const std::sub_match<const CharT*>*>::value), ""); + static_assert((std::is_same<typename I::reference, const std::sub_match<const CharT*>&>::value), ""); + static_assert((std::is_same<typename I::iterator_category, std::forward_iterator_tag>::value), ""); +} + +int main() +{ + test<char>(); + test<wchar_t>(); +}
\ No newline at end of file |

