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

Unified Diff: third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachineTest.cpp

Issue 2708523002: Introduce ForwardCodePointStateMachine to traverse chars in code points (Closed)
Patch Set: Created 3 years, 10 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/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachineTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachineTest.cpp b/third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachineTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..499c77596cbf5fb9fc0dfb0b6280d73f75fa6402
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachineTest.cpp
@@ -0,0 +1,73 @@
+// Copyright 2017 The Chromium 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 "core/editing/state_machines/ForwardCodePointStateMachine.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+namespace {
+const TextSegmentationMachineState kInvalid =
+ TextSegmentationMachineState::Invalid;
+const TextSegmentationMachineState kNeedMoreCodeUnit =
+ TextSegmentationMachineState::NeedMoreCodeUnit;
+const TextSegmentationMachineState kFinished =
+ TextSegmentationMachineState::Finished;
+} // namespace
+
+TEST(ForwardCodePointStateMachineTest, DoNothingCase) {
+ ForwardCodePointStateMachine machine;
+ EXPECT_EQ(0, machine.getBoundaryOffset());
+}
+
+TEST(ForwardCodePointStateMachineTest, SingleCharacter) {
+ ForwardCodePointStateMachine machine;
+ EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit('a'));
+ EXPECT_EQ(1, machine.getBoundaryOffset());
+
+ machine.reset();
+ EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit('-'));
+ EXPECT_EQ(1, machine.getBoundaryOffset());
+
+ machine.reset();
+ EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit('\t'));
+ EXPECT_EQ(1, machine.getBoundaryOffset());
+
+ machine.reset();
+ // U+3042 HIRAGANA LETTER A.
+ EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit(0x3042));
+ EXPECT_EQ(1, machine.getBoundaryOffset());
+}
+
+TEST(ForwardCodePointStateMachineTest, SurrogatePair) {
+ ForwardCodePointStateMachine machine;
+
+ // U+20BB7 is \uD83D\uDDFA in UTF-16.
+ const UChar leadSurrogate = 0xD842;
+ const UChar trailSurrogate = 0xDFB7;
+
+ EXPECT_EQ(kNeedMoreCodeUnit, machine.feedFollowingCodeUnit(leadSurrogate));
+ EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit(trailSurrogate));
+ EXPECT_EQ(2, machine.getBoundaryOffset());
+
+ // Edge cases
+ // Unpaired leading surrogate. Nothing to delete.
+ machine.reset();
+ EXPECT_EQ(kNeedMoreCodeUnit, machine.feedFollowingCodeUnit(leadSurrogate));
+ EXPECT_EQ(kInvalid, machine.feedFollowingCodeUnit('a'));
+ EXPECT_EQ(0, machine.getBoundaryOffset());
+
+ machine.reset();
+ EXPECT_EQ(kNeedMoreCodeUnit, machine.feedFollowingCodeUnit(leadSurrogate));
+ EXPECT_EQ(kInvalid, machine.feedFollowingCodeUnit(leadSurrogate));
+ EXPECT_EQ(0, machine.getBoundaryOffset());
+
+ // Unpaired trailing surrogate. Nothing to delete.
+ machine.reset();
+ EXPECT_EQ(kInvalid, machine.feedFollowingCodeUnit(trailSurrogate));
+ EXPECT_EQ(0, machine.getBoundaryOffset());
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/editing/state_machines/ForwardCodePointStateMachine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698