LCOV - code coverage report
Current view: top level - test/unittests - char-predicates-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 102 103 99.0 %
Date: 2019-04-17 Functions: 12 17 70.6 %

          Line data    Source code
       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/char-predicates-inl.h"
       7             : #include "src/unicode.h"
       8             : #include "testing/gtest/include/gtest/gtest.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : 
      13       15443 : TEST(CharPredicatesTest, WhiteSpace) {
      14             :   EXPECT_TRUE(IsWhiteSpace(0x0009));
      15             :   EXPECT_TRUE(IsWhiteSpace(0x000B));
      16             :   EXPECT_TRUE(IsWhiteSpace(0x000C));
      17             :   EXPECT_TRUE(IsWhiteSpace(' '));
      18           1 :   EXPECT_TRUE(IsWhiteSpace(0x00A0));
      19           1 :   EXPECT_TRUE(IsWhiteSpace(0x1680));
      20           1 :   EXPECT_TRUE(IsWhiteSpace(0x2000));
      21           1 :   EXPECT_TRUE(IsWhiteSpace(0x2007));
      22           1 :   EXPECT_TRUE(IsWhiteSpace(0x202F));
      23           1 :   EXPECT_TRUE(IsWhiteSpace(0x205F));
      24           1 :   EXPECT_TRUE(IsWhiteSpace(0x3000));
      25           1 :   EXPECT_TRUE(IsWhiteSpace(0xFEFF));
      26           2 :   EXPECT_FALSE(IsWhiteSpace(0x180E));
      27           1 : }
      28             : 
      29             : 
      30       15443 : TEST(CharPredicatesTest, WhiteSpaceOrLineTerminator) {
      31             :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x0009));
      32             :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x000B));
      33             :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x000C));
      34             :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(' '));
      35           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x00A0));
      36           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x1680));
      37           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x2000));
      38           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x2007));
      39           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x202F));
      40           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x205F));
      41           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0xFEFF));
      42             :   // Line terminators
      43             :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x000A));
      44             :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x000D));
      45           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x2028));
      46           1 :   EXPECT_TRUE(IsWhiteSpaceOrLineTerminator(0x2029));
      47           2 :   EXPECT_FALSE(IsWhiteSpaceOrLineTerminator(0x180E));
      48           1 : }
      49             : 
      50             : 
      51       15443 : TEST(CharPredicatesTest, IdentifierStart) {
      52             :   EXPECT_TRUE(IsIdentifierStart('$'));
      53             :   EXPECT_TRUE(IsIdentifierStart('_'));
      54             :   EXPECT_TRUE(IsIdentifierStart('\\'));
      55             : 
      56             :   // http://www.unicode.org/reports/tr31/
      57             :   // curl http://www.unicode.org/Public/UCD/latest/ucd/PropList.txt |
      58             :   // grep 'Other_ID_Start'
      59             :   // Other_ID_Start
      60           1 :   EXPECT_TRUE(IsIdentifierStart(0x1885));
      61           1 :   EXPECT_TRUE(IsIdentifierStart(0x1886));
      62           1 :   EXPECT_TRUE(IsIdentifierStart(0x2118));
      63           1 :   EXPECT_TRUE(IsIdentifierStart(0x212E));
      64           1 :   EXPECT_TRUE(IsIdentifierStart(0x309B));
      65           1 :   EXPECT_TRUE(IsIdentifierStart(0x309C));
      66             : 
      67             :   // Issue 2892:
      68             :   // \u2E2F has the Pattern_Syntax property, excluding it from ID_Start.
      69           2 :   EXPECT_FALSE(IsIdentifierStart(0x2E2F));
      70             : 
      71             : #ifdef V8_INTL_SUPPORT
      72             :   // New in Unicode 8.0 (6,847 code points)
      73             :   // [:ID_Start:] & [[:Age=8.0:] - [:Age=7.0:]]
      74           1 :   EXPECT_TRUE(IsIdentifierStart(0x08B3));
      75           1 :   EXPECT_TRUE(IsIdentifierStart(0x0AF9));
      76           1 :   EXPECT_TRUE(IsIdentifierStart(0x13F8));
      77           1 :   EXPECT_TRUE(IsIdentifierStart(0x9FCD));
      78           1 :   EXPECT_TRUE(IsIdentifierStart(0xAB60));
      79           1 :   EXPECT_TRUE(IsIdentifierStart(0x10CC0));
      80           1 :   EXPECT_TRUE(IsIdentifierStart(0x108E0));
      81           1 :   EXPECT_TRUE(IsIdentifierStart(0x2B820));
      82             : 
      83             :   // New in Unicode 9.0 (7,177 code points)
      84             :   // [:ID_Start:] & [[:Age=9.0:] - [:Age=8.0:]]
      85             : 
      86           1 :   EXPECT_TRUE(IsIdentifierStart(0x1C80));
      87           1 :   EXPECT_TRUE(IsIdentifierStart(0x104DB));
      88           1 :   EXPECT_TRUE(IsIdentifierStart(0x1E922));
      89             : #endif
      90           1 : }
      91             : 
      92             : 
      93       15443 : TEST(CharPredicatesTest, IdentifierPart) {
      94             :   EXPECT_TRUE(IsIdentifierPart('$'));
      95             :   EXPECT_TRUE(IsIdentifierPart('_'));
      96             :   EXPECT_TRUE(IsIdentifierPart('\\'));
      97           1 :   EXPECT_TRUE(IsIdentifierPart(0x200C));
      98           1 :   EXPECT_TRUE(IsIdentifierPart(0x200D));
      99             : 
     100             : #ifdef V8_INTL_SUPPORT
     101             :   // New in Unicode 8.0 (6,847 code points)
     102             :   // [:ID_Start:] & [[:Age=8.0:] - [:Age=7.0:]]
     103           1 :   EXPECT_TRUE(IsIdentifierPart(0x08B3));
     104           1 :   EXPECT_TRUE(IsIdentifierPart(0x0AF9));
     105           0 :   EXPECT_TRUE(IsIdentifierPart(0x13F8));
     106           1 :   EXPECT_TRUE(IsIdentifierPart(0x9FCD));
     107           1 :   EXPECT_TRUE(IsIdentifierPart(0xAB60));
     108           1 :   EXPECT_TRUE(IsIdentifierPart(0x10CC0));
     109           1 :   EXPECT_TRUE(IsIdentifierPart(0x108E0));
     110           1 :   EXPECT_TRUE(IsIdentifierPart(0x2B820));
     111             : 
     112             :   // [[:ID_Continue:]-[:ID_Start:]] &  [[:Age=8.0:]-[:Age=7.0:]]
     113             :   // 162 code points
     114           1 :   EXPECT_TRUE(IsIdentifierPart(0x08E3));
     115           1 :   EXPECT_TRUE(IsIdentifierPart(0xA69E));
     116           1 :   EXPECT_TRUE(IsIdentifierPart(0x11730));
     117             : 
     118             :   // New in Unicode 9.0 (7,177 code points)
     119             :   // [:ID_Start:] & [[:Age=9.0:] - [:Age=8.0:]]
     120           1 :   EXPECT_TRUE(IsIdentifierPart(0x1C80));
     121           1 :   EXPECT_TRUE(IsIdentifierPart(0x104DB));
     122           1 :   EXPECT_TRUE(IsIdentifierPart(0x1E922));
     123             : 
     124             :   // [[:ID_Continue:]-[:ID_Start:]] &  [[:Age=9.0:]-[:Age=8.0:]]
     125             :   // 162 code points
     126           1 :   EXPECT_TRUE(IsIdentifierPart(0x08D4));
     127           1 :   EXPECT_TRUE(IsIdentifierPart(0x1DFB));
     128           1 :   EXPECT_TRUE(IsIdentifierPart(0xA8C5));
     129           1 :   EXPECT_TRUE(IsIdentifierPart(0x11450));
     130             : #endif
     131             : 
     132             :   // http://www.unicode.org/reports/tr31/
     133             :   // curl http://www.unicode.org/Public/UCD/latest/ucd/PropList.txt |
     134             :   // grep 'Other_ID_(Continue|Start)'
     135             : 
     136             :   // Other_ID_Start
     137           1 :   EXPECT_TRUE(IsIdentifierPart(0x1885));
     138           1 :   EXPECT_TRUE(IsIdentifierPart(0x1886));
     139           1 :   EXPECT_TRUE(IsIdentifierPart(0x2118));
     140           1 :   EXPECT_TRUE(IsIdentifierPart(0x212E));
     141           1 :   EXPECT_TRUE(IsIdentifierPart(0x309B));
     142           1 :   EXPECT_TRUE(IsIdentifierPart(0x309C));
     143             : 
     144             :   // Other_ID_Continue
     145           1 :   EXPECT_TRUE(IsIdentifierPart(0x00B7));
     146           1 :   EXPECT_TRUE(IsIdentifierPart(0x0387));
     147           1 :   EXPECT_TRUE(IsIdentifierPart(0x1369));
     148           1 :   EXPECT_TRUE(IsIdentifierPart(0x1370));
     149           1 :   EXPECT_TRUE(IsIdentifierPart(0x1371));
     150           1 :   EXPECT_TRUE(IsIdentifierPart(0x19DA));
     151             : 
     152             :   // Issue 2892:
     153             :   // \u2E2F has the Pattern_Syntax property, excluding it from ID_Start.
     154           2 :   EXPECT_FALSE(IsIdentifierPart(0x2E2F));
     155           1 : }
     156             : 
     157             : #ifdef V8_INTL_SUPPORT
     158       15443 : TEST(CharPredicatesTest, SupplementaryPlaneIdentifiers) {
     159             :   // Both ID_Start and ID_Continue.
     160           1 :   EXPECT_TRUE(IsIdentifierStart(0x10403));  // Category Lu
     161           1 :   EXPECT_TRUE(IsIdentifierPart(0x10403));
     162           1 :   EXPECT_TRUE(IsIdentifierStart(0x1043C));  // Category Ll
     163           1 :   EXPECT_TRUE(IsIdentifierPart(0x1043C));
     164           1 :   EXPECT_TRUE(IsIdentifierStart(0x16F9C));  // Category Lm
     165           1 :   EXPECT_TRUE(IsIdentifierPart(0x16F9C));
     166           1 :   EXPECT_TRUE(IsIdentifierStart(0x10048));  // Category Lo
     167           1 :   EXPECT_TRUE(IsIdentifierPart(0x10048));
     168           1 :   EXPECT_TRUE(IsIdentifierStart(0x1014D));  // Category Nl
     169           1 :   EXPECT_TRUE(IsIdentifierPart(0x1014D));
     170             : 
     171             :   // New in Unicode 8.0
     172             :   // [ [:ID_Start=Yes:] & [:Age=8.0:]] - [:Age=7.0:]
     173           1 :   EXPECT_TRUE(IsIdentifierStart(0x108E0));
     174           1 :   EXPECT_TRUE(IsIdentifierStart(0x10C80));
     175             : 
     176             :   // Only ID_Continue.
     177           2 :   EXPECT_FALSE(IsIdentifierStart(0x101FD));  // Category Mn
     178           1 :   EXPECT_TRUE(IsIdentifierPart(0x101FD));
     179           2 :   EXPECT_FALSE(IsIdentifierStart(0x11002));  // Category Mc
     180           1 :   EXPECT_TRUE(IsIdentifierPart(0x11002));
     181           2 :   EXPECT_FALSE(IsIdentifierStart(0x104A9));  // Category Nd
     182           1 :   EXPECT_TRUE(IsIdentifierPart(0x104A9));
     183             : 
     184             :   // Neither.
     185           2 :   EXPECT_FALSE(IsIdentifierStart(0x10111));  // Category No
     186           2 :   EXPECT_FALSE(IsIdentifierPart(0x10111));
     187           2 :   EXPECT_FALSE(IsIdentifierStart(0x1F4A9));  // Category So
     188           2 :   EXPECT_FALSE(IsIdentifierPart(0x1F4A9));
     189           1 : }
     190             : #endif  // V8_INTL_SUPPORT
     191             : 
     192             : }  // namespace internal
     193        9264 : }  // namespace v8

Generated by: LCOV version 1.10