1 // Copyright 2008 The RE2 Authors.  All Rights Reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4 
5 // Exhaustive testing of regular expression matching.
6 
7 #include <string>
8 #include <vector>
9 
10 #include "util/test.h"
11 #include "re2/testing/exhaustive_tester.h"
12 
13 namespace re2 {
14 
15 // Test simple repetition operators
TEST(Repetition,Simple)16 TEST(Repetition, Simple) {
17   std::vector<std::string> ops = Split(" ",
18     "%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} "
19     "%s{1,2} %s{2} %s{2,} %s{3,4} %s{4,5} "
20     "%s* %s+ %s? %s*? %s+? %s??");
21   ExhaustiveTest(3, 2, Explode("abc."), ops,
22                  6, Explode("ab"), "(?:%s)", "");
23   ExhaustiveTest(3, 2, Explode("abc."), ops,
24                  40, Explode("a"), "(?:%s)", "");
25 }
26 
27 // Test capturing parens -- (a) -- inside repetition operators
TEST(Repetition,Capturing)28 TEST(Repetition, Capturing) {
29   std::vector<std::string> ops = Split(" ",
30     "%s{0} %s{0,} %s{1} %s{1,} %s{0,1} %s{0,2} "
31     "%s{1,2} %s{2} %s{2,} %s{3,4} %s{4,5} "
32     "%s* %s+ %s? %s*? %s+? %s??");
33   ExhaustiveTest(3, 2, Split(" ", "a (a) b"), ops,
34                  7, Explode("ab"), "(?:%s)", "");
35   ExhaustiveTest(3, 2, Split(" ", "a (a)"), ops,
36                  50, Explode("a"), "(?:%s)", "");
37 }
38 
39 }  // namespace re2
40