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 9namespace v8 { 10namespace internal { 11 12TEST(CharPredicatesTest, 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 25TEST(CharPredicatesTest, 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 44TEST(CharPredicatesTest, 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 62TEST(CharPredicatesTest, 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 90#ifdef V8_I18N_SUPPORT 91TEST(CharPredicatesTest, SupplementaryPlaneIdentifiers) { 92 // Both ID_Start and ID_Continue. 93 EXPECT_TRUE(IdentifierStart::Is(0x10403)); // Category Lu 94 EXPECT_TRUE(IdentifierPart::Is(0x10403)); 95 EXPECT_TRUE(IdentifierStart::Is(0x1043C)); // Category Ll 96 EXPECT_TRUE(IdentifierPart::Is(0x1043C)); 97 EXPECT_TRUE(IdentifierStart::Is(0x16F9C)); // Category Lm 98 EXPECT_TRUE(IdentifierPart::Is(0x16F9C)); 99 EXPECT_TRUE(IdentifierStart::Is(0x10048)); // Category Lo 100 EXPECT_TRUE(IdentifierPart::Is(0x10048)); 101 EXPECT_TRUE(IdentifierStart::Is(0x1014D)); // Category Nl 102 EXPECT_TRUE(IdentifierPart::Is(0x1014D)); 103 104 // Only ID_Continue. 105 EXPECT_FALSE(IdentifierStart::Is(0x101FD)); // Category Mn 106 EXPECT_TRUE(IdentifierPart::Is(0x101FD)); 107 EXPECT_FALSE(IdentifierStart::Is(0x11002)); // Category Mc 108 EXPECT_TRUE(IdentifierPart::Is(0x11002)); 109 EXPECT_FALSE(IdentifierStart::Is(0x104A9)); // Category Nd 110 EXPECT_TRUE(IdentifierPart::Is(0x104A9)); 111 112 // Neither. 113 EXPECT_FALSE(IdentifierStart::Is(0x10111)); // Category No 114 EXPECT_FALSE(IdentifierPart::Is(0x10111)); 115 EXPECT_FALSE(IdentifierStart::Is(0x1F4A9)); // Category So 116 EXPECT_FALSE(IdentifierPart::Is(0x1F4A9)); 117} 118#endif // V8_I18N_SUPPORT 119 120} // namespace internal 121} // namespace v8 122