File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,23 @@ test('`unicodeChar` nesting matching', () => {
81
81
) . not . toMatchString ( 'b' ) ;
82
82
} ) ;
83
83
84
+ test ( '`unicodeChar` edge cases handling' , ( ) => {
85
+ expect ( ( ) => u ( unicodeChar ( NaN ) ) ) . toThrowErrorMatchingInlineSnapshot (
86
+ `""unicodeChar": expected valid unicode code point but got: NaN"` ,
87
+ ) ;
88
+ expect ( ( ) => u ( unicodeChar ( 1.5 ) ) ) . toThrowErrorMatchingInlineSnapshot (
89
+ `""unicodeChar": expected valid unicode code point but got: 1.5"` ,
90
+ ) ;
91
+ expect ( ( ) => u ( unicodeChar ( - 1 ) ) ) . toThrowErrorMatchingInlineSnapshot (
92
+ `""unicodeChar": expected valid unicode code point but got: -1"` ,
93
+ ) ;
94
+ expect ( ( ) => u ( unicodeChar ( 0x110000 ) ) ) . toThrowErrorMatchingInlineSnapshot (
95
+ `""unicodeChar": expected valid unicode code point but got: 1114112"` ,
96
+ ) ;
97
+
98
+ expect ( u ( unicodeChar ( 0x10ffff ) ) ) . toEqualRegex ( / \u{10ffff} / u) ;
99
+ } ) ;
100
+
84
101
test ( '`unicodeProp` pattern' , ( ) => {
85
102
expect ( unicodeProp ( 'General_Category' , 'Letter' ) ) . toEqualRegex ( / \p{ General_Category= Letter} / ) ;
86
103
expect ( unicodeProp ( 'Letter' ) ) . toEqualRegex ( / \p{ Letter} / ) ;
Original file line number Diff line number Diff line change @@ -13,12 +13,8 @@ import type { CharacterEscape } from '../types';
13
13
* @returns A character class representing the unicode escape.
14
14
*/
15
15
export function unicodeChar ( codePoint : number ) : CharacterEscape {
16
- if ( ! Number . isInteger ( codePoint ) ) {
17
- throw new TypeError ( 'Expected an integer code point but got: ' + codePoint ) ;
18
- }
19
-
20
- if ( codePoint < 0 ) {
21
- throw new RangeError ( 'Code point must be a positive integer but got: ' + codePoint ) ;
16
+ if ( ! Number . isInteger ( codePoint ) || codePoint < 0 || codePoint > 0x10ffff ) {
17
+ throw new RangeError ( '"unicodeChar": expected valid unicode code point but got: ' + codePoint ) ;
22
18
}
23
19
24
20
let escape =
You can’t perform that action at this time.
0 commit comments