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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/editing/state_machines/ForwardCodePointStateMachine.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace blink {
10
11 namespace {
12 const TextSegmentationMachineState kInvalid =
13 TextSegmentationMachineState::Invalid;
14 const TextSegmentationMachineState kNeedMoreCodeUnit =
15 TextSegmentationMachineState::NeedMoreCodeUnit;
16 const TextSegmentationMachineState kFinished =
17 TextSegmentationMachineState::Finished;
18 } // namespace
19
20 TEST(ForwardCodePointStateMachineTest, DoNothingCase) {
21 ForwardCodePointStateMachine machine;
22 EXPECT_EQ(0, machine.getBoundaryOffset());
23 }
24
25 TEST(ForwardCodePointStateMachineTest, SingleCharacter) {
26 ForwardCodePointStateMachine machine;
27 EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit('a'));
28 EXPECT_EQ(1, machine.getBoundaryOffset());
29
30 machine.reset();
31 EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit('-'));
32 EXPECT_EQ(1, machine.getBoundaryOffset());
33
34 machine.reset();
35 EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit('\t'));
36 EXPECT_EQ(1, machine.getBoundaryOffset());
37
38 machine.reset();
39 // U+3042 HIRAGANA LETTER A.
40 EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit(0x3042));
41 EXPECT_EQ(1, machine.getBoundaryOffset());
42 }
43
44 TEST(ForwardCodePointStateMachineTest, SurrogatePair) {
45 ForwardCodePointStateMachine machine;
46
47 // U+20BB7 is \uD83D\uDDFA in UTF-16.
48 const UChar leadSurrogate = 0xD842;
49 const UChar trailSurrogate = 0xDFB7;
50
51 EXPECT_EQ(kNeedMoreCodeUnit, machine.feedFollowingCodeUnit(leadSurrogate));
52 EXPECT_EQ(kFinished, machine.feedFollowingCodeUnit(trailSurrogate));
53 EXPECT_EQ(2, machine.getBoundaryOffset());
54
55 // Edge cases
56 // Unpaired leading surrogate. Nothing to delete.
57 machine.reset();
58 EXPECT_EQ(kNeedMoreCodeUnit, machine.feedFollowingCodeUnit(leadSurrogate));
59 EXPECT_EQ(kInvalid, machine.feedFollowingCodeUnit('a'));
60 EXPECT_EQ(0, machine.getBoundaryOffset());
61
62 machine.reset();
63 EXPECT_EQ(kNeedMoreCodeUnit, machine.feedFollowingCodeUnit(leadSurrogate));
64 EXPECT_EQ(kInvalid, machine.feedFollowingCodeUnit(leadSurrogate));
65 EXPECT_EQ(0, machine.getBoundaryOffset());
66
67 // Unpaired trailing surrogate. Nothing to delete.
68 machine.reset();
69 EXPECT_EQ(kInvalid, machine.feedFollowingCodeUnit(trailSurrogate));
70 EXPECT_EQ(0, machine.getBoundaryOffset());
71 }
72
73 } // namespace blink
OLDNEW
« 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