tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

character-class-non-whitespace-class-escape-positive-cases.js (2507B)


      1 // Copyright (C) 2018 Leo Balter.  All rights reserved.
      2 // Copyright (C) 2024 Aurèle Barrière.  All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: prod-CharacterClassEscape
      7 description: >
      8  Check positive cases of non-whitespace class escape \S.
      9 info: |
     10  This is a generated test. Please check out
     11  https://github.com/tc39/test262/tree/main/tools/regexp-generator/
     12  for any changes.
     13 
     14  CharacterClassEscape[UnicodeMode] ::
     15    d
     16    D
     17    s
     18    S
     19    w
     20    W
     21    [+UnicodeMode] p{ UnicodePropertyValueExpression }
     22    [+UnicodeMode] P{ UnicodePropertyValueExpression }
     23 
     24  22.2.2.9 Runtime Semantics: CompileToCharSet
     25 
     26  CharacterClassEscape :: d
     27    1. Return the ten-element CharSet containing the characters 0, 1, 2, 3, 4,
     28      5, 6, 7, 8, and 9.
     29  CharacterClassEscape :: D
     30    1. Let S be the CharSet returned by CharacterClassEscape :: d.
     31    2. Return CharacterComplement(rer, S).
     32  CharacterClassEscape :: s
     33    1. Return the CharSet containing all characters corresponding to a code
     34      point on the right-hand side of the WhiteSpace or LineTerminator
     35      productions.
     36  CharacterClassEscape :: S
     37    1. Let S be the CharSet returned by CharacterClassEscape :: s.
     38    2. Return CharacterComplement(rer, S).
     39  CharacterClassEscape :: w
     40    1. Return MaybeSimpleCaseFolding(rer, WordCharacters(rer)).
     41  CharacterClassEscape :: W
     42    1. Let S be the CharSet returned by CharacterClassEscape :: w.
     43    2. Return CharacterComplement(rer, S).
     44 features: [String.fromCodePoint]
     45 includes: [regExpUtils.js]
     46 flags: [generated]
     47 ---*/
     48 
     49 const str = buildString(
     50 {
     51  loneCodePoints: [],
     52  ranges: [
     53    [0x00DC00, 0x00DFFF],
     54    [0x000000, 0x000008],
     55    [0x00000E, 0x00001F],
     56    [0x000021, 0x00009F],
     57    [0x0000A1, 0x00167F],
     58    [0x001681, 0x001FFF],
     59    [0x00200B, 0x002027],
     60    [0x00202A, 0x00202E],
     61    [0x002030, 0x00205E],
     62    [0x002060, 0x002FFF],
     63    [0x003001, 0x00DBFF],
     64    [0x00E000, 0x00FEFE],
     65    [0x00FF00, 0x10FFFF]
     66  ]
     67 }
     68 );
     69 
     70 const standard = /^\S+$/;
     71 const unicode = /^\S+$/u;
     72 const vflag = /^\S+$/v;
     73 const regexes = [standard,unicode,vflag];
     74 
     75 const errors = [];
     76 
     77 for (const regex of regexes) {
     78  if (!regex.test(str)) {
     79    // Error, let's find out where
     80    for (const char of str) {
     81      if (!regex.test(char)) {
     82        errors.push('0x' + char.codePointAt(0).toString(16));
     83      }
     84    }
     85  }
     86 }
     87 
     88 assert.sameValue(
     89  errors.length,
     90  0,
     91  'Expected full match, but did not match: ' + errors.join(',')
     92 );
     93 
     94 reportCompare(0, 0);