mirror of
				https://github.com/tc39/test262.git
				synced 2025-11-03 21:24:30 +01:00 
			
		
		
		
	Previously, these tests simply compared against an equivalent regular expression pattern by generating a large string containing either all code points up to U+FFFF or U+10FFFF, depending on the `u` flag, and then performing:
    str.replace(re, '') === str.replace(otherRe, '');
These two `String#replace` calls can be optimized into a single `RegExp#test` call by following the pattern used in the property escapes tests at https://github.com/mathiasbynens/unicode-property-escapes-tests.
		
	
			
		
			
				
	
	
		
			65 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
// Copyright (C) 2018 Leo Balter.  All rights reserved.
 | 
						|
// This code is governed by the BSD license found in the LICENSE file.
 | 
						|
 | 
						|
/*---
 | 
						|
esid: prod-CharacterClassEscape
 | 
						|
description: >
 | 
						|
    Compare range for digit class escape \d+ with flags g
 | 
						|
info: |
 | 
						|
    This is a generated test. Please check out
 | 
						|
    https://github.com/bocoup/test262-regexp-generator
 | 
						|
    for any changes.
 | 
						|
 | 
						|
    CharacterClassEscape[U] ::
 | 
						|
        d
 | 
						|
        D
 | 
						|
        s
 | 
						|
        S
 | 
						|
        w
 | 
						|
        W
 | 
						|
 | 
						|
    21.2.2.12 CharacterClassEscape
 | 
						|
 | 
						|
    The production CharacterClassEscape :: d evaluates as follows:
 | 
						|
        Return the ten-element set of characters containing the characters 0 through 9 inclusive.
 | 
						|
    The production CharacterClassEscape :: D evaluates as follows:
 | 
						|
        Return the set of all characters not included in the set returned by CharacterClassEscape :: d.
 | 
						|
    The production CharacterClassEscape :: s evaluates as follows:
 | 
						|
        Return the set of characters containing the characters that are on the right-hand side of
 | 
						|
        the WhiteSpace or LineTerminator productions.
 | 
						|
    The production CharacterClassEscape :: S evaluates as follows:
 | 
						|
        Return the set of all characters not included in the set returned by CharacterClassEscape :: s.
 | 
						|
    The production CharacterClassEscape :: w evaluates as follows:
 | 
						|
        Return the set of all characters returned by WordCharacters().
 | 
						|
    The production CharacterClassEscape :: W evaluates as follows:
 | 
						|
        Return the set of all characters not included in the set returned by CharacterClassEscape :: w.
 | 
						|
features: [String.fromCodePoint]
 | 
						|
includes: [regExpUtils.js]
 | 
						|
---*/
 | 
						|
 | 
						|
const str = buildString({
 | 
						|
    loneCodePoints: [],
 | 
						|
    ranges: [
 | 
						|
        [0x0030, 0x0039],
 | 
						|
    ],
 | 
						|
});
 | 
						|
 | 
						|
const re = /\d+/g;
 | 
						|
 | 
						|
const errors = [];
 | 
						|
 | 
						|
if (!re.test(str)) {
 | 
						|
    // Error, let's find out where
 | 
						|
    for (const char of str) {
 | 
						|
        if (!re.test(char)) {
 | 
						|
            errors.push('0x' + char.codePointAt(0).toString(16));
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
assert.sameValue(
 | 
						|
    errors.length,
 | 
						|
    0,
 | 
						|
    'Expected matching code points, but received: ' + errors.join(',')
 | 
						|
);
 |