summaryrefslogtreecommitdiffstats
path: root/webkit/glue/regular_expression_unittest.cc
diff options
context:
space:
mode:
authoryaar@chromium.org <yaar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-04 21:43:51 +0000
committeryaar@chromium.org <yaar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-04 21:43:51 +0000
commitaf1b308bca8864706a3858dc9f551d206f95e80e (patch)
tree42104307d9023c8e6c1085ae659e0b27206b3875 /webkit/glue/regular_expression_unittest.cc
parent8af4c1991ec7ff8d8e6bcd87d882ba0c99e4f916 (diff)
downloadchromium_src-af1b308bca8864706a3858dc9f551d206f95e80e.zip
chromium_src-af1b308bca8864706a3858dc9f551d206f95e80e.tar.gz
chromium_src-af1b308bca8864706a3858dc9f551d206f95e80e.tar.bz2
regular_expression_unittest to only use WebKit API.
Review URL: http://codereview.chromium.org/548077 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38136 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/regular_expression_unittest.cc')
-rw-r--r--webkit/glue/regular_expression_unittest.cc124
1 files changed, 67 insertions, 57 deletions
diff --git a/webkit/glue/regular_expression_unittest.cc b/webkit/glue/regular_expression_unittest.cc
index 5958ed1..39741f8 100644
--- a/webkit/glue/regular_expression_unittest.cc
+++ b/webkit/glue/regular_expression_unittest.cc
@@ -2,22 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "config.h"
-
-#include "base/compiler_specific.h"
-
-MSVC_PUSH_WARNING_LEVEL(0);
-#include "PlatformString.h"
-#include "RegularExpression.h"
-MSVC_POP_WARNING();
-
#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/glue/glue_util.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebTextCaseSensitivity.h"
-using std::wstring;
-using webkit_glue::StdWStringToString;
-using WebCore::RegularExpression;
-using WebCore::String;
+using namespace WebKit;
namespace {
@@ -25,17 +15,35 @@ class RegexTest : public testing::Test {
};
struct Match {
- const std::wstring text;
- const int position;
- const int length;
+ const WebUChar* text;
+ const int textLength;
+ const int matchPosition;
+ const int matchLength;
};
+void testMatches(const WebRegularExpression& regex,
+ const Match* matches,
+ const size_t nMatches) {
+
+ for (size_t i = 0; i < nMatches; ++i) {
+ int matchedLength = matches[i].textLength;
+ EXPECT_EQ(matches[i].matchPosition, regex.match(
+ WebString(matches[i].text, matches[i].textLength), 0, &matchedLength));
+ if (matches[i].matchPosition != -1)
+ EXPECT_EQ(matches[i].matchLength, matchedLength);
+ }
+
+}
+
} // namespace
+#define MATCH_DESC(webuchar, matchPosition, matchLength) \
+ { webuchar, arraysize(webuchar), matchPosition, matchLength }
+
+
TEST(RegexTest, Basic) {
// Just make sure we're not completely broken.
- const String pattern("the quick brown fox");
- RegularExpression regex(pattern, WebCore::TextCaseSensitive);
+ WebRegularExpression regex("the quick brown fox", WebTextCaseSensitive);
EXPECT_EQ(0, regex.match("the quick brown fox"));
EXPECT_EQ(1, regex.match(" the quick brown fox"));
EXPECT_EQ(3, regex.match("foothe quick brown foxbar"));
@@ -46,50 +54,52 @@ TEST(RegexTest, Basic) {
TEST(RegexTest, Unicode) {
// Make sure we get the right offsets for unicode strings.
+ WebUChar pattern[] = {L'\x6240', L'\x6709', L'\x7f51', L'\x9875'};
+ WebRegularExpression regex(WebString(pattern, arraysize(pattern)),
+ WebTextCaseInsensitive);
- // Test 1
- wstring wstr_pattern(L"\x6240\x6709\x7f51\x9875");
- String pattern = StdWStringToString(wstr_pattern);
- RegularExpression regex(pattern, WebCore::TextCaseInsensitive);
+ WebUChar text1[] = {L'\x6240', L'\x6709', L'\x7f51', L'\x9875'};
+ WebUChar text2[] = {L' ', L'\x6240', L'\x6709', L'\x7f51', L'\x9875'};
+ WebUChar text3[] = {L'f', L'o', L'o', L'\x6240', L'\x6709', L'\x7f51', L'\x9875', L'b', L'a', L'r'};
+ WebUChar text4[] = {L'\x4e2d', L'\x6587', L'\x7f51', L'\x9875', L'\x6240', L'\x6709', L'\x7f51', L'\x9875'};
- EXPECT_EQ(0, regex.match(StdWStringToString(wstr_pattern)));
- EXPECT_EQ(1, regex.match(StdWStringToString(
- wstring(L" ") + wstr_pattern)));
- EXPECT_EQ(3, regex.match(StdWStringToString(
- wstring(L"foo") + wstr_pattern + wstring(L"bar"))));
- EXPECT_EQ(4, regex.match(StdWStringToString(
- wstring(L"\x4e2d\x6587\x7f51\x9875") + wstr_pattern)));
+ const Match matches[] = {
+ MATCH_DESC(text1, 0, 4),
+ MATCH_DESC(text2, 1, 4),
+ MATCH_DESC(text3, 3, 4),
+ MATCH_DESC(text4, 4, 4),
+ };
+
+ testMatches(regex, matches, arraysize(matches));
+}
+
+TEST(RegexTest, UnicodeMixedLength) {
+ WebUChar pattern[] = {L':', L'[', L' ', L'\x2000', L']', L'+', L':'};
+ WebRegularExpression regex(WebString(pattern, arraysize(pattern)),
+ WebTextCaseInsensitive);
- // Test 2, mixed length
- wstr_pattern = L":[ \x2000]+:";
- pattern = StdWStringToString(wstr_pattern);
- regex = RegularExpression(pattern, WebCore::TextCaseInsensitive);
+ WebUChar text1[] = {L':', L' ', L' ', L':'};
+ WebUChar text2[] = {L' ', L' ', L':', L' ', L' ', L' ', L' ', L':', L' ', L' '};
+ WebUChar text3[] = {L' ', L':', L' ', L'\x2000', L' ', L':', L' '};
+ WebUChar text4[] = {L'\x6240', L'\x6709', L'\x7f51', L'\x9875', L' ', L':', L' ', L'\x2000', L' ', L'\x2000', L' ', L':', L' '};
+ WebUChar text5[] = {L' '};
+ WebUChar text6[] = {L':', L':'};
const Match matches[] = {
- { L": :", 0, 4 },
- { L" : : ", 2, 6 },
- { L" : \x2000 : ", 1, 5 },
- { L"\x6240\x6709\x7f51\x9875 : \x2000 \x2000 : ", 5, 7 },
- { L"", -1, -1 },
- { L"::", -1, -1 },
+ MATCH_DESC(text1, 0, 4),
+ MATCH_DESC(text2, 2, 6),
+ MATCH_DESC(text3, 1, 5),
+ MATCH_DESC(text4, 5, 7),
+ MATCH_DESC(text5, -1, -1),
+ MATCH_DESC(text6, -1, -1),
};
- for (size_t i = 0; i < arraysize(matches); ++i) {
- EXPECT_EQ(matches[i].position, regex.match(StdWStringToString(
- wstring(matches[i].text))));
- EXPECT_EQ(matches[i].length, regex.matchedLength());
- }
- // Test 3, empty match
- wstr_pattern = L"|x";
- pattern = StdWStringToString(wstr_pattern);
- regex = RegularExpression(pattern, WebCore::TextCaseInsensitive);
+ testMatches(regex, matches, arraysize(matches));
+}
- const Match matches2[] = {
- { L"", 0, 0 },
- };
- for (size_t i = 0; i < arraysize(matches2); ++i) {
- EXPECT_EQ(matches2[i].position, regex.match(StdWStringToString(
- wstring(matches2[i].text))));
- EXPECT_EQ(matches2[i].length, regex.matchedLength());
- }
+TEST(RegexTest, EmptyMatch) {
+ WebRegularExpression regex("|x", WebTextCaseInsensitive);
+ int matchedLength = 0;
+ EXPECT_EQ(0, regex.match("", 0, &matchedLength));
+ EXPECT_EQ(0, matchedLength);
}