OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 "src/char-predicates.h" | 5 #include "src/char-predicates.h" |
6 #include "src/unicode.h" | 6 #include "src/unicode.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 | 11 |
12 TEST(UnicodePredicatesTest, WhiteSpace) { | 12 TEST(CharPredicatesTest, WhiteSpace) { |
13 // As of Unicode 6.3.0, \u180E is no longer a white space. We still consider | 13 // As of Unicode 6.3.0, \u180E is no longer a white space. We still consider |
14 // it to be one though, since JS recognizes all white spaces in Unicode 5.1. | 14 // it to be one though, since JS recognizes all white spaces in Unicode 5.1. |
15 EXPECT_TRUE(WhiteSpace::Is(0x0009)); | 15 EXPECT_TRUE(WhiteSpace::Is(0x0009)); |
16 EXPECT_TRUE(WhiteSpace::Is(0x000B)); | 16 EXPECT_TRUE(WhiteSpace::Is(0x000B)); |
17 EXPECT_TRUE(WhiteSpace::Is(0x000C)); | 17 EXPECT_TRUE(WhiteSpace::Is(0x000C)); |
18 EXPECT_TRUE(WhiteSpace::Is(' ')); | 18 EXPECT_TRUE(WhiteSpace::Is(' ')); |
19 EXPECT_TRUE(WhiteSpace::Is(0x00A0)); | 19 EXPECT_TRUE(WhiteSpace::Is(0x00A0)); |
20 EXPECT_TRUE(WhiteSpace::Is(0x180E)); | 20 EXPECT_TRUE(WhiteSpace::Is(0x180E)); |
21 EXPECT_TRUE(WhiteSpace::Is(0xFEFF)); | 21 EXPECT_TRUE(WhiteSpace::Is(0xFEFF)); |
22 } | 22 } |
23 | 23 |
24 | 24 |
25 TEST(UnicodePredicatesTest, WhiteSpaceOrLineTerminator) { | 25 TEST(CharPredicatesTest, WhiteSpaceOrLineTerminator) { |
26 // As of Unicode 6.3.0, \u180E is no longer a white space. We still consider | 26 // As of Unicode 6.3.0, \u180E is no longer a white space. We still consider |
27 // it to be one though, since JS recognizes all white spaces in Unicode 5.1. | 27 // it to be one though, since JS recognizes all white spaces in Unicode 5.1. |
28 // White spaces | 28 // White spaces |
29 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x0009)); | 29 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x0009)); |
30 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000B)); | 30 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000B)); |
31 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000C)); | 31 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000C)); |
32 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(' ')); | 32 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(' ')); |
33 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x00A0)); | 33 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x00A0)); |
34 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x180E)); | 34 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x180E)); |
35 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0xFEFF)); | 35 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0xFEFF)); |
36 // Line terminators | 36 // Line terminators |
37 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000A)); | 37 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000A)); |
38 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000D)); | 38 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000D)); |
39 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x2028)); | 39 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x2028)); |
40 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x2029)); | 40 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x2029)); |
41 } | 41 } |
42 | 42 |
43 | 43 |
44 TEST(UnicodePredicatesTest, IdentifierStart) { | 44 TEST(CharPredicatesTest, IdentifierStart) { |
45 EXPECT_TRUE(IdentifierStart::Is('$')); | 45 EXPECT_TRUE(IdentifierStart::Is('$')); |
46 EXPECT_TRUE(IdentifierStart::Is('_')); | 46 EXPECT_TRUE(IdentifierStart::Is('_')); |
47 EXPECT_TRUE(IdentifierStart::Is('\\')); | 47 EXPECT_TRUE(IdentifierStart::Is('\\')); |
48 | 48 |
49 // http://www.unicode.org/reports/tr31/ | 49 // http://www.unicode.org/reports/tr31/ |
50 // Other_ID_Start | 50 // Other_ID_Start |
51 EXPECT_TRUE(IdentifierStart::Is(0x2118)); | 51 EXPECT_TRUE(IdentifierStart::Is(0x2118)); |
52 EXPECT_TRUE(IdentifierStart::Is(0x212E)); | 52 EXPECT_TRUE(IdentifierStart::Is(0x212E)); |
53 EXPECT_TRUE(IdentifierStart::Is(0x309B)); | 53 EXPECT_TRUE(IdentifierStart::Is(0x309B)); |
54 EXPECT_TRUE(IdentifierStart::Is(0x309C)); | 54 EXPECT_TRUE(IdentifierStart::Is(0x309C)); |
55 | 55 |
56 // Issue 2892: | 56 // Issue 2892: |
57 // \u2E2F has the Pattern_Syntax property, excluding it from ID_Start. | 57 // \u2E2F has the Pattern_Syntax property, excluding it from ID_Start. |
58 EXPECT_FALSE(unibrow::ID_Start::Is(0x2E2F)); | 58 EXPECT_FALSE(unibrow::ID_Start::Is(0x2E2F)); |
59 } | 59 } |
60 | 60 |
61 | 61 |
62 TEST(UnicodePredicatesTest, IdentifierPart) { | 62 TEST(CharPredicatesTest, IdentifierPart) { |
63 EXPECT_TRUE(IdentifierPart::Is('$')); | 63 EXPECT_TRUE(IdentifierPart::Is('$')); |
64 EXPECT_TRUE(IdentifierPart::Is('_')); | 64 EXPECT_TRUE(IdentifierPart::Is('_')); |
65 EXPECT_TRUE(IdentifierPart::Is('\\')); | 65 EXPECT_TRUE(IdentifierPart::Is('\\')); |
66 EXPECT_TRUE(IdentifierPart::Is(0x200C)); | 66 EXPECT_TRUE(IdentifierPart::Is(0x200C)); |
67 EXPECT_TRUE(IdentifierPart::Is(0x200D)); | 67 EXPECT_TRUE(IdentifierPart::Is(0x200D)); |
68 | 68 |
69 // http://www.unicode.org/reports/tr31/ | 69 // http://www.unicode.org/reports/tr31/ |
70 // Other_ID_Start | 70 // Other_ID_Start |
71 EXPECT_TRUE(IdentifierPart::Is(0x2118)); | 71 EXPECT_TRUE(IdentifierPart::Is(0x2118)); |
72 EXPECT_TRUE(IdentifierPart::Is(0x212E)); | 72 EXPECT_TRUE(IdentifierPart::Is(0x212E)); |
73 EXPECT_TRUE(IdentifierPart::Is(0x309B)); | 73 EXPECT_TRUE(IdentifierPart::Is(0x309B)); |
74 EXPECT_TRUE(IdentifierPart::Is(0x309C)); | 74 EXPECT_TRUE(IdentifierPart::Is(0x309C)); |
75 | 75 |
76 // Other_ID_Continue | 76 // Other_ID_Continue |
77 EXPECT_TRUE(IdentifierPart::Is(0x00B7)); | 77 EXPECT_TRUE(IdentifierPart::Is(0x00B7)); |
78 EXPECT_TRUE(IdentifierPart::Is(0x0387)); | 78 EXPECT_TRUE(IdentifierPart::Is(0x0387)); |
79 EXPECT_TRUE(IdentifierPart::Is(0x1369)); | 79 EXPECT_TRUE(IdentifierPart::Is(0x1369)); |
80 EXPECT_TRUE(IdentifierPart::Is(0x1370)); | 80 EXPECT_TRUE(IdentifierPart::Is(0x1370)); |
81 EXPECT_TRUE(IdentifierPart::Is(0x1371)); | 81 EXPECT_TRUE(IdentifierPart::Is(0x1371)); |
82 EXPECT_TRUE(IdentifierPart::Is(0x19DA)); | 82 EXPECT_TRUE(IdentifierPart::Is(0x19DA)); |
83 | 83 |
84 // Issue 2892: | 84 // Issue 2892: |
85 // \u2E2F has the Pattern_Syntax property, excluding it from ID_Start. | 85 // \u2E2F has the Pattern_Syntax property, excluding it from ID_Start. |
86 EXPECT_FALSE(IdentifierPart::Is(0x2E2F)); | 86 EXPECT_FALSE(IdentifierPart::Is(0x2E2F)); |
87 } | 87 } |
88 | 88 |
89 | 89 |
90 #ifdef V8_I18N_SUPPORT | 90 #ifdef V8_I18N_SUPPORT |
91 TEST(UnicodePredicatesTest, SupplementaryPlaneIdentifiers) { | 91 TEST(CharPredicatesTest, SupplementaryPlaneIdentifiers) { |
92 // Both ID_Start and ID_Continue. | 92 // Both ID_Start and ID_Continue. |
93 EXPECT_TRUE(IdentifierStart::Is(0x10403)); // Category Lu | 93 EXPECT_TRUE(IdentifierStart::Is(0x10403)); // Category Lu |
94 EXPECT_TRUE(IdentifierPart::Is(0x10403)); | 94 EXPECT_TRUE(IdentifierPart::Is(0x10403)); |
95 EXPECT_TRUE(IdentifierStart::Is(0x1043C)); // Category Ll | 95 EXPECT_TRUE(IdentifierStart::Is(0x1043C)); // Category Ll |
96 EXPECT_TRUE(IdentifierPart::Is(0x1043C)); | 96 EXPECT_TRUE(IdentifierPart::Is(0x1043C)); |
97 EXPECT_TRUE(IdentifierStart::Is(0x16F9C)); // Category Lm | 97 EXPECT_TRUE(IdentifierStart::Is(0x16F9C)); // Category Lm |
98 EXPECT_TRUE(IdentifierPart::Is(0x16F9C)); | 98 EXPECT_TRUE(IdentifierPart::Is(0x16F9C)); |
99 EXPECT_TRUE(IdentifierStart::Is(0x10048)); // Category Lo | 99 EXPECT_TRUE(IdentifierStart::Is(0x10048)); // Category Lo |
100 EXPECT_TRUE(IdentifierPart::Is(0x10048)); | 100 EXPECT_TRUE(IdentifierPart::Is(0x10048)); |
101 EXPECT_TRUE(IdentifierStart::Is(0x1014D)); // Category Nl | 101 EXPECT_TRUE(IdentifierStart::Is(0x1014D)); // Category Nl |
(...skipping 10 matching lines...) Expand all Loading... |
112 // Neither. | 112 // Neither. |
113 EXPECT_FALSE(IdentifierStart::Is(0x10111)); // Category No | 113 EXPECT_FALSE(IdentifierStart::Is(0x10111)); // Category No |
114 EXPECT_FALSE(IdentifierPart::Is(0x10111)); | 114 EXPECT_FALSE(IdentifierPart::Is(0x10111)); |
115 EXPECT_FALSE(IdentifierStart::Is(0x1F4A9)); // Category So | 115 EXPECT_FALSE(IdentifierStart::Is(0x1F4A9)); // Category So |
116 EXPECT_FALSE(IdentifierPart::Is(0x1F4A9)); | 116 EXPECT_FALSE(IdentifierPart::Is(0x1F4A9)); |
117 } | 117 } |
118 #endif // V8_I18N_SUPPORT | 118 #endif // V8_I18N_SUPPORT |
119 | 119 |
120 } // namespace internal | 120 } // namespace internal |
121 } // namespace v8 | 121 } // namespace v8 |
OLD | NEW |