OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/fonts/UnicodeRangeSet.h" | 5 #include "platform/fonts/UnicodeRangeSet.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 static const UChar hiraganaA[2] = {0x3042, 0}; | 11 static const UChar hiraganaA[2] = {0x3042, 0}; |
12 | 12 |
13 TEST(UnicodeRangeSet, Empty) { | 13 TEST(UnicodeRangeSet, Empty) { |
14 Vector<UnicodeRange> ranges; | 14 Vector<UnicodeRange> ranges; |
15 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); | 15 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); |
16 EXPECT_TRUE(set->isEntireRange()); | 16 EXPECT_TRUE(set->isEntireRange()); |
17 EXPECT_EQ(0u, set->size()); | 17 EXPECT_EQ(0u, set->size()); |
18 EXPECT_FALSE(set->intersectsWith(String())); | 18 EXPECT_FALSE(set->intersectsWith(String())); |
19 EXPECT_TRUE(set->intersectsWith(String("a"))); | 19 EXPECT_TRUE(set->intersectsWith(String("a"))); |
20 EXPECT_TRUE(set->intersectsWith(String(hiraganaA))); | 20 EXPECT_TRUE(set->intersectsWith(String(hiraganaA))); |
21 } | 21 } |
22 | 22 |
23 TEST(UnicodeRangeSet, SingleCharacter) { | 23 TEST(UnicodeRangeSet, SingleCharacter) { |
24 Vector<UnicodeRange> ranges; | 24 Vector<UnicodeRange> ranges; |
25 ranges.append(UnicodeRange('b', 'b')); | 25 ranges.push_back(UnicodeRange('b', 'b')); |
26 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); | 26 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); |
27 EXPECT_FALSE(set->isEntireRange()); | 27 EXPECT_FALSE(set->isEntireRange()); |
28 EXPECT_FALSE(set->intersectsWith(String())); | 28 EXPECT_FALSE(set->intersectsWith(String())); |
29 EXPECT_FALSE(set->intersectsWith(String("a"))); | 29 EXPECT_FALSE(set->intersectsWith(String("a"))); |
30 EXPECT_TRUE(set->intersectsWith(String("b"))); | 30 EXPECT_TRUE(set->intersectsWith(String("b"))); |
31 EXPECT_FALSE(set->intersectsWith(String("c"))); | 31 EXPECT_FALSE(set->intersectsWith(String("c"))); |
32 EXPECT_TRUE(set->intersectsWith(String("abc"))); | 32 EXPECT_TRUE(set->intersectsWith(String("abc"))); |
33 EXPECT_FALSE(set->intersectsWith(String(hiraganaA))); | 33 EXPECT_FALSE(set->intersectsWith(String(hiraganaA))); |
34 ASSERT_EQ(1u, set->size()); | 34 ASSERT_EQ(1u, set->size()); |
35 EXPECT_EQ('b', set->rangeAt(0).from()); | 35 EXPECT_EQ('b', set->rangeAt(0).from()); |
36 EXPECT_EQ('b', set->rangeAt(0).to()); | 36 EXPECT_EQ('b', set->rangeAt(0).to()); |
37 } | 37 } |
38 | 38 |
39 TEST(UnicodeRangeSet, TwoRanges) { | 39 TEST(UnicodeRangeSet, TwoRanges) { |
40 Vector<UnicodeRange> ranges; | 40 Vector<UnicodeRange> ranges; |
41 ranges.append(UnicodeRange('6', '7')); | 41 ranges.push_back(UnicodeRange('6', '7')); |
42 ranges.append(UnicodeRange('2', '4')); | 42 ranges.push_back(UnicodeRange('2', '4')); |
43 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); | 43 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); |
44 EXPECT_FALSE(set->isEntireRange()); | 44 EXPECT_FALSE(set->isEntireRange()); |
45 EXPECT_FALSE(set->intersectsWith(String())); | 45 EXPECT_FALSE(set->intersectsWith(String())); |
46 EXPECT_FALSE(set->intersectsWith(String("1"))); | 46 EXPECT_FALSE(set->intersectsWith(String("1"))); |
47 EXPECT_TRUE(set->intersectsWith(String("2"))); | 47 EXPECT_TRUE(set->intersectsWith(String("2"))); |
48 EXPECT_TRUE(set->intersectsWith(String("3"))); | 48 EXPECT_TRUE(set->intersectsWith(String("3"))); |
49 EXPECT_TRUE(set->intersectsWith(String("4"))); | 49 EXPECT_TRUE(set->intersectsWith(String("4"))); |
50 EXPECT_FALSE(set->intersectsWith(String("5"))); | 50 EXPECT_FALSE(set->intersectsWith(String("5"))); |
51 EXPECT_TRUE(set->intersectsWith(String("6"))); | 51 EXPECT_TRUE(set->intersectsWith(String("6"))); |
52 EXPECT_TRUE(set->intersectsWith(String("7"))); | 52 EXPECT_TRUE(set->intersectsWith(String("7"))); |
53 EXPECT_FALSE(set->intersectsWith(String("8"))); | 53 EXPECT_FALSE(set->intersectsWith(String("8"))); |
54 ASSERT_EQ(2u, set->size()); | 54 ASSERT_EQ(2u, set->size()); |
55 EXPECT_EQ('2', set->rangeAt(0).from()); | 55 EXPECT_EQ('2', set->rangeAt(0).from()); |
56 EXPECT_EQ('4', set->rangeAt(0).to()); | 56 EXPECT_EQ('4', set->rangeAt(0).to()); |
57 EXPECT_EQ('6', set->rangeAt(1).from()); | 57 EXPECT_EQ('6', set->rangeAt(1).from()); |
58 EXPECT_EQ('7', set->rangeAt(1).to()); | 58 EXPECT_EQ('7', set->rangeAt(1).to()); |
59 } | 59 } |
60 | 60 |
61 TEST(UnicodeRangeSet, Overlap) { | 61 TEST(UnicodeRangeSet, Overlap) { |
62 Vector<UnicodeRange> ranges; | 62 Vector<UnicodeRange> ranges; |
63 ranges.append(UnicodeRange('0', '2')); | 63 ranges.push_back(UnicodeRange('0', '2')); |
64 ranges.append(UnicodeRange('1', '1')); | 64 ranges.push_back(UnicodeRange('1', '1')); |
65 ranges.append(UnicodeRange('3', '5')); | 65 ranges.push_back(UnicodeRange('3', '5')); |
66 ranges.append(UnicodeRange('4', '6')); | 66 ranges.push_back(UnicodeRange('4', '6')); |
67 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); | 67 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); |
68 ASSERT_EQ(1u, set->size()); | 68 ASSERT_EQ(1u, set->size()); |
69 EXPECT_EQ('0', set->rangeAt(0).from()); | 69 EXPECT_EQ('0', set->rangeAt(0).from()); |
70 EXPECT_EQ('6', set->rangeAt(0).to()); | 70 EXPECT_EQ('6', set->rangeAt(0).to()); |
71 } | 71 } |
72 | 72 |
73 TEST(UnicodeRangeSet, Non8Bit) { | 73 TEST(UnicodeRangeSet, Non8Bit) { |
74 Vector<UnicodeRange> ranges; | 74 Vector<UnicodeRange> ranges; |
75 ranges.append(UnicodeRange(0x3042, 0x3042)); | 75 ranges.push_back(UnicodeRange(0x3042, 0x3042)); |
76 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); | 76 RefPtr<UnicodeRangeSet> set = adoptRef(new UnicodeRangeSet(ranges)); |
77 ASSERT_EQ(1u, set->size()); | 77 ASSERT_EQ(1u, set->size()); |
78 EXPECT_EQ(0x3042, set->rangeAt(0).from()); | 78 EXPECT_EQ(0x3042, set->rangeAt(0).from()); |
79 EXPECT_EQ(0x3042, set->rangeAt(0).to()); | 79 EXPECT_EQ(0x3042, set->rangeAt(0).to()); |
80 EXPECT_FALSE(set->intersectsWith(String("a"))); | 80 EXPECT_FALSE(set->intersectsWith(String("a"))); |
81 EXPECT_TRUE(set->intersectsWith(String(hiraganaA))); | 81 EXPECT_TRUE(set->intersectsWith(String(hiraganaA))); |
82 } | 82 } |
83 | 83 |
84 } // namespace blink | 84 } // namespace blink |
OLD | NEW |