OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/char-predicates.h" |
| 6 #include "src/unicode.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace v8 { |
| 10 namespace internal { |
| 11 |
| 12 TEST(UnicodePredicatesTest, WhiteSpace) { |
| 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. |
| 15 EXPECT_TRUE(WhiteSpace::Is(0x0009)); |
| 16 EXPECT_TRUE(WhiteSpace::Is(0x000B)); |
| 17 EXPECT_TRUE(WhiteSpace::Is(0x000C)); |
| 18 EXPECT_TRUE(WhiteSpace::Is(' ')); |
| 19 EXPECT_TRUE(WhiteSpace::Is(0x00A0)); |
| 20 EXPECT_TRUE(WhiteSpace::Is(0x180E)); |
| 21 EXPECT_TRUE(WhiteSpace::Is(0xFEFF)); |
| 22 } |
| 23 |
| 24 |
| 25 TEST(UnicodePredicatesTest, WhiteSpaceOrLineTerminator) { |
| 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. |
| 28 // White spaces |
| 29 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x0009)); |
| 30 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000B)); |
| 31 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000C)); |
| 32 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(' ')); |
| 33 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x00A0)); |
| 34 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x180E)); |
| 35 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0xFEFF)); |
| 36 // Line terminators |
| 37 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000A)); |
| 38 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x000D)); |
| 39 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x2028)); |
| 40 EXPECT_TRUE(WhiteSpaceOrLineTerminator::Is(0x2029)); |
| 41 } |
| 42 |
| 43 |
| 44 TEST(UnicodePredicatesTest, IdentifierStart) { |
| 45 EXPECT_TRUE(IdentifierStart::Is('$')); |
| 46 EXPECT_TRUE(IdentifierStart::Is('_')); |
| 47 EXPECT_TRUE(IdentifierStart::Is('\\')); |
| 48 |
| 49 // http://www.unicode.org/reports/tr31/ |
| 50 // Other_ID_Start |
| 51 EXPECT_TRUE(IdentifierStart::Is(0x2118)); |
| 52 EXPECT_TRUE(IdentifierStart::Is(0x212E)); |
| 53 EXPECT_TRUE(IdentifierStart::Is(0x309B)); |
| 54 EXPECT_TRUE(IdentifierStart::Is(0x309C)); |
| 55 |
| 56 // Issue 2892: |
| 57 // \u2E2F has the Pattern_Syntax property, excluding it from ID_Start. |
| 58 EXPECT_FALSE(unibrow::ID_Start::Is(0x2E2F)); |
| 59 } |
| 60 |
| 61 |
| 62 TEST(UnicodePredicatesTest, IdentifierPart) { |
| 63 EXPECT_TRUE(IdentifierPart::Is('$')); |
| 64 EXPECT_TRUE(IdentifierPart::Is('_')); |
| 65 EXPECT_TRUE(IdentifierPart::Is('\\')); |
| 66 EXPECT_TRUE(IdentifierPart::Is(0x200C)); |
| 67 EXPECT_TRUE(IdentifierPart::Is(0x200D)); |
| 68 |
| 69 // http://www.unicode.org/reports/tr31/ |
| 70 // Other_ID_Start |
| 71 EXPECT_TRUE(IdentifierPart::Is(0x2118)); |
| 72 EXPECT_TRUE(IdentifierPart::Is(0x212E)); |
| 73 EXPECT_TRUE(IdentifierPart::Is(0x309B)); |
| 74 EXPECT_TRUE(IdentifierPart::Is(0x309C)); |
| 75 |
| 76 // Other_ID_Continue |
| 77 EXPECT_TRUE(IdentifierPart::Is(0x00B7)); |
| 78 EXPECT_TRUE(IdentifierPart::Is(0x0387)); |
| 79 EXPECT_TRUE(IdentifierPart::Is(0x1369)); |
| 80 EXPECT_TRUE(IdentifierPart::Is(0x1370)); |
| 81 EXPECT_TRUE(IdentifierPart::Is(0x1371)); |
| 82 EXPECT_TRUE(IdentifierPart::Is(0x19DA)); |
| 83 |
| 84 // Issue 2892: |
| 85 // \u2E2F has the Pattern_Syntax property, excluding it from ID_Start. |
| 86 EXPECT_FALSE(IdentifierPart::Is(0x2E2F)); |
| 87 } |
| 88 |
| 89 } // namespace internal |
| 90 } // namespace v8 |
OLD | NEW |