Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <regex> |
| 11 | |
| 12 | // class match_results<BidirectionalIterator, Allocator> |
| 13 | |
| 14 | // const_reference operator[](size_type n) const; |
| 15 | |
| 16 | #include <regex> |
| 17 | #include <cassert> |
| 18 | |
| 19 | void |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 20 | test(std::regex_constants::syntax_option_type syntax) |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 21 | { |
| 22 | std::match_results<const char*> m; |
| 23 | const char s[] = "abcdefghijk"; |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 24 | assert(std::regex_search(s, m, std::regex("cd((e)fg)hi|(z)", syntax))); |
| 25 | |
| 26 | assert(m.size() == 4); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 27 | |
| 28 | assert(m[0].first == s+2); |
| 29 | assert(m[0].second == s+9); |
| 30 | assert(m[0].matched == true); |
| 31 | |
| 32 | assert(m[1].first == s+4); |
| 33 | assert(m[1].second == s+7); |
| 34 | assert(m[1].matched == true); |
| 35 | |
| 36 | assert(m[2].first == s+4); |
| 37 | assert(m[2].second == s+5); |
| 38 | assert(m[2].matched == true); |
| 39 | |
| 40 | assert(m[3].first == s+11); |
| 41 | assert(m[3].second == s+11); |
| 42 | assert(m[3].matched == false); |
| 43 | |
| 44 | assert(m[4].first == s+11); |
| 45 | assert(m[4].second == s+11); |
| 46 | assert(m[4].matched == false); |
| 47 | } |
| 48 | |
| 49 | int main() |
| 50 | { |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 51 | test(std::regex_constants::ECMAScript); |
| 52 | test(std::regex_constants::extended); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 53 | } |