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

Unified Diff: third_party/re2/re2/testing/set_test.cc

Issue 10575037: Include RE2 library (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Less intrusive fix for Android Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/re2/re2/testing/set_test.cc
diff --git a/third_party/re2/re2/testing/set_test.cc b/third_party/re2/re2/testing/set_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..89aed802814a7d7c22cc3c4aea2411e49992a47d
--- /dev/null
+++ b/third_party/re2/re2/testing/set_test.cc
@@ -0,0 +1,102 @@
+// Copyright 2010 The RE2 Authors. All Rights Reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <vector>
+
+#include "util/test.h"
+#include "re2/re2.h"
+#include "re2/set.h"
+
+namespace re2 {
+
+TEST(Set, Unanchored) {
+ RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED);
+
+ CHECK_EQ(s.Add("foo", NULL), 0);
+ CHECK_EQ(s.Add("(", NULL), -1);
+ CHECK_EQ(s.Add("bar", NULL), 1);
+
+ CHECK_EQ(s.Compile(), true);
+
+ vector<int> v;
+ CHECK_EQ(s.Match("foobar", &v), true);
+ CHECK_EQ(v.size(), 2);
+ CHECK_EQ(v[0], 0);
+ CHECK_EQ(v[1], 1);
+
+ v.clear();
+ CHECK_EQ(s.Match("fooba", &v), true);
+ CHECK_EQ(v.size(), 1);
+ CHECK_EQ(v[0], 0);
+
+ v.clear();
+ CHECK_EQ(s.Match("oobar", &v), true);
+ CHECK_EQ(v.size(), 1);
+ CHECK_EQ(v[0], 1);
+}
+
+TEST(Set, UnanchoredFactored) {
+ RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED);
+
+ CHECK_EQ(s.Add("foo", NULL), 0);
+ CHECK_EQ(s.Add("(", NULL), -1);
+ CHECK_EQ(s.Add("foobar", NULL), 1);
+
+ CHECK_EQ(s.Compile(), true);
+
+ vector<int> v;
+ CHECK_EQ(s.Match("foobar", &v), true);
+ CHECK_EQ(v.size(), 2);
+ CHECK_EQ(v[0], 0);
+ CHECK_EQ(v[1], 1);
+
+ v.clear();
+ CHECK_EQ(s.Match("obarfoobaroo", &v), true);
+ CHECK_EQ(v.size(), 2);
+ CHECK_EQ(v[0], 0);
+ CHECK_EQ(v[1], 1);
+
+ v.clear();
+ CHECK_EQ(s.Match("fooba", &v), true);
+ CHECK_EQ(v.size(), 1);
+ CHECK_EQ(v[0], 0);
+
+ v.clear();
+ CHECK_EQ(s.Match("oobar", &v), false);
+ CHECK_EQ(v.size(), 0);
+}
+
+TEST(Set, Anchored) {
+ RE2::Set s(RE2::DefaultOptions, RE2::ANCHOR_BOTH);
+
+ CHECK_EQ(s.Add("foo", NULL), 0);
+ CHECK_EQ(s.Add("(", NULL), -1);
+ CHECK_EQ(s.Add("bar", NULL), 1);
+
+ CHECK_EQ(s.Compile(), true);
+
+ vector<int> v;
+ CHECK_EQ(s.Match("foobar", &v), false);
+ CHECK_EQ(v.size(), 0);
+
+ CHECK_EQ(s.Match("fooba", &v), false);
+ CHECK_EQ(v.size(), 0);
+
+ CHECK_EQ(s.Match("oobar", &v), false);
+ CHECK_EQ(v.size(), 0);
+
+ CHECK_EQ(s.Match("foo", &v), true);
+ CHECK_EQ(v.size(), 1);
+ CHECK_EQ(v[0], 0);
+
+ CHECK_EQ(s.Match("bar", &v), true);
+ CHECK_EQ(v.size(), 1);
+ CHECK_EQ(v[0], 1);
+
+}
+
+} // namespace re2
+
« 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