Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: third_party/re2/re2/testing/set_test.cc

Issue 1544433002: Replace RE2 import with a dependency (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-Added LICENSE and OWNERS file Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2010 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 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <vector>
8
9 #include "util/test.h"
10 #include "re2/re2.h"
11 #include "re2/set.h"
12
13 namespace re2 {
14
15 TEST(Set, Unanchored) {
16 RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED);
17
18 CHECK_EQ(s.Add("foo", NULL), 0);
19 CHECK_EQ(s.Add("(", NULL), -1);
20 CHECK_EQ(s.Add("bar", NULL), 1);
21
22 CHECK_EQ(s.Compile(), true);
23
24 vector<int> v;
25 CHECK_EQ(s.Match("foobar", &v), true);
26 CHECK_EQ(v.size(), 2);
27 CHECK_EQ(v[0], 0);
28 CHECK_EQ(v[1], 1);
29
30 v.clear();
31 CHECK_EQ(s.Match("fooba", &v), true);
32 CHECK_EQ(v.size(), 1);
33 CHECK_EQ(v[0], 0);
34
35 v.clear();
36 CHECK_EQ(s.Match("oobar", &v), true);
37 CHECK_EQ(v.size(), 1);
38 CHECK_EQ(v[0], 1);
39 }
40
41 TEST(Set, UnanchoredFactored) {
42 RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED);
43
44 CHECK_EQ(s.Add("foo", NULL), 0);
45 CHECK_EQ(s.Add("(", NULL), -1);
46 CHECK_EQ(s.Add("foobar", NULL), 1);
47
48 CHECK_EQ(s.Compile(), true);
49
50 vector<int> v;
51 CHECK_EQ(s.Match("foobar", &v), true);
52 CHECK_EQ(v.size(), 2);
53 CHECK_EQ(v[0], 0);
54 CHECK_EQ(v[1], 1);
55
56 v.clear();
57 CHECK_EQ(s.Match("obarfoobaroo", &v), true);
58 CHECK_EQ(v.size(), 2);
59 CHECK_EQ(v[0], 0);
60 CHECK_EQ(v[1], 1);
61
62 v.clear();
63 CHECK_EQ(s.Match("fooba", &v), true);
64 CHECK_EQ(v.size(), 1);
65 CHECK_EQ(v[0], 0);
66
67 v.clear();
68 CHECK_EQ(s.Match("oobar", &v), false);
69 CHECK_EQ(v.size(), 0);
70 }
71
72 TEST(Set, UnanchoredDollar) {
73 RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED);
74
75 CHECK_EQ(s.Add("foo$", NULL), 0);
76 CHECK_EQ(s.Compile(), true);
77
78 vector<int> v;
79 CHECK_EQ(s.Match("foo", &v), true);
80 CHECK_EQ(v.size(), 1);
81 CHECK_EQ(v[0], 0);
82 }
83
84 TEST(Set, Anchored) {
85 RE2::Set s(RE2::DefaultOptions, RE2::ANCHOR_BOTH);
86
87 CHECK_EQ(s.Add("foo", NULL), 0);
88 CHECK_EQ(s.Add("(", NULL), -1);
89 CHECK_EQ(s.Add("bar", NULL), 1);
90
91 CHECK_EQ(s.Compile(), true);
92
93 vector<int> v;
94 CHECK_EQ(s.Match("foobar", &v), false);
95 CHECK_EQ(v.size(), 0);
96
97 CHECK_EQ(s.Match("fooba", &v), false);
98 CHECK_EQ(v.size(), 0);
99
100 CHECK_EQ(s.Match("oobar", &v), false);
101 CHECK_EQ(v.size(), 0);
102
103 CHECK_EQ(s.Match("foo", &v), true);
104 CHECK_EQ(v.size(), 1);
105 CHECK_EQ(v[0], 0);
106
107 CHECK_EQ(s.Match("bar", &v), true);
108 CHECK_EQ(v.size(), 1);
109 CHECK_EQ(v[0], 1);
110 }
111
112 TEST(Set, EmptyUnanchored) {
113 RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED);
114
115 CHECK_EQ(s.Compile(), true);
116
117 vector<int> v;
118 CHECK_EQ(s.Match("", &v), false);
119 CHECK_EQ(v.size(), 0);
120
121 v.clear();
122 CHECK_EQ(s.Match("foobar", &v), false);
123 CHECK_EQ(v.size(), 0);
124 }
125
126 TEST(Set, EmptyAnchored) {
127 RE2::Set s(RE2::DefaultOptions, RE2::ANCHOR_BOTH);
128
129 CHECK_EQ(s.Compile(), true);
130
131 vector<int> v;
132 CHECK_EQ(s.Match("", &v), false);
133 CHECK_EQ(v.size(), 0);
134
135 v.clear();
136 CHECK_EQ(s.Match("foobar", &v), false);
137 CHECK_EQ(v.size(), 0);
138 }
139
140 } // namespace re2
OLDNEW
« no previous file with comments | « third_party/re2/re2/testing/search_test.cc ('k') | third_party/re2/re2/testing/simplify_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698