@@ -5,88 +5,99 @@ import {
55 endOfString ,
66 type RegexSequence ,
77 startOfString ,
8+ unicodeChar ,
89 unicodeProperty ,
910} from '../..' ;
1011
1112function u ( sequence : RegexSequence ) {
1213 return buildRegExp ( sequence , { unicode : true } ) ;
1314}
1415
15- test ( '`char ` pattern' , ( ) => {
16+ test ( '`unicodeChar ` pattern' , ( ) => {
1617 // eslint-disable-next-line no-control-regex
17- expect ( char ( 0 ) ) . toEqualRegex ( / \u0000 / ) ;
18+ expect ( unicodeChar ( 0 ) ) . toEqualRegex ( / \u0000 / ) ;
1819 // eslint-disable-next-line no-control-regex
19- expect ( char ( 0x1 ) ) . toEqualRegex ( / \u0001 / ) ;
20+ expect ( unicodeChar ( 0x1 ) ) . toEqualRegex ( / \u0001 / ) ;
2021 // eslint-disable-next-line no-control-regex
21- expect ( char ( 0x12 ) ) . toEqualRegex ( / \u0012 / ) ;
22- expect ( char ( 0x123 ) ) . toEqualRegex ( / \u0123 / ) ;
23- expect ( char ( 0x1234 ) ) . toEqualRegex ( / \u1234 / ) ;
22+ expect ( unicodeChar ( 0x12 ) ) . toEqualRegex ( / \u0012 / ) ;
23+ expect ( unicodeChar ( 0x123 ) ) . toEqualRegex ( / \u0123 / ) ;
24+ expect ( unicodeChar ( 0x1234 ) ) . toEqualRegex ( / \u1234 / ) ;
2425
2526 // eslint-disable-next-line no-control-regex
26- expect ( u ( char ( 0 ) ) ) . toEqualRegex ( new RegExp ( '\\u0000' , 'u' ) ) ;
27+ expect ( u ( unicodeChar ( 0 ) ) ) . toEqualRegex ( new RegExp ( '\\u0000' , 'u' ) ) ;
2728 // eslint-disable-next-line no-control-regex
28- expect ( u ( char ( 0x1 ) ) ) . toEqualRegex ( new RegExp ( '\\u0001' , 'u' ) ) ;
29- expect ( u ( char ( 0x12 ) ) ) . toEqualRegex (
29+ expect ( u ( unicodeChar ( 0x1 ) ) ) . toEqualRegex ( new RegExp ( '\\u0001' , 'u' ) ) ;
30+ expect ( u ( unicodeChar ( 0x12 ) ) ) . toEqualRegex (
3031 // eslint-disable-next-line no-control-regex
3132 new RegExp ( '\\u0012' , 'u' ) ,
3233 ) ;
33- expect ( char ( 0x0123 ) ) . toEqualRegex ( / \u0123 / ) ;
34- expect ( char ( 0x1234 ) ) . toEqualRegex ( / \u1234 / ) ;
34+ expect ( unicodeChar ( 0x0123 ) ) . toEqualRegex ( / \u0123 / ) ;
35+ expect ( unicodeChar ( 0x1234 ) ) . toEqualRegex ( / \u1234 / ) ;
3536
36- expect ( u ( char ( 0x0123 ) ) ) . toEqualRegex ( / \u0123 / u) ;
37- expect ( u ( char ( 0x1234 ) ) ) . toEqualRegex ( / \u1234 / u) ;
38- expect ( u ( char ( 0x12345 ) ) ) . toEqualRegex ( new RegExp ( '\\u{12345}' , 'u' ) ) ;
39- expect ( u ( char ( 0x103456 ) ) ) . toEqualRegex ( new RegExp ( '\\u{103456}' , 'u' ) ) ;
37+ expect ( u ( unicodeChar ( 0x0123 ) ) ) . toEqualRegex ( / \u0123 / u) ;
38+ expect ( u ( unicodeChar ( 0x1234 ) ) ) . toEqualRegex ( / \u1234 / u) ;
39+ expect ( u ( unicodeChar ( 0x12345 ) ) ) . toEqualRegex ( new RegExp ( '\\u{12345}' , 'u' ) ) ;
40+ expect ( u ( unicodeChar ( 0x103456 ) ) ) . toEqualRegex ( new RegExp ( '\\u{103456}' , 'u' ) ) ;
4041} ) ;
4142
42- test ( '`char ` matching' , ( ) => {
43- expect ( char ( 0 ) ) . toMatchString ( '\u{0}' ) ;
44- expect ( char ( 0x1 ) ) . toMatchString ( '\u{1}' ) ;
45- expect ( char ( 0x12 ) ) . toMatchString ( '\u{12}}' ) ;
46- expect ( char ( 0x123 ) ) . toMatchString ( '\u{123}' ) ;
47- expect ( char ( 0x1234 ) ) . toMatchString ( '\u{1234}}' ) ;
48-
49- expect ( char ( 'a' . codePointAt ( 0 ) ! ) ) . toMatchString ( 'a' ) ;
50- expect ( char ( 'ą' . codePointAt ( 0 ) ! ) ) . toMatchString ( 'ą' ) ;
51- expect ( char ( '©' . codePointAt ( 0 ) ! ) ) . toMatchString ( '©' ) ;
52-
53- expect ( u ( char ( 0 ) ) ) . toMatchString ( '\u{0}' ) ;
54- expect ( u ( char ( 0 ) ) ) . not . toMatchString ( 'a' ) ;
55- expect ( u ( char ( 0x1 ) ) ) . toMatchString ( '\u{1}' ) ;
56- expect ( u ( char ( 0x12 ) ) ) . toMatchString ( '\u{12}' ) ;
57- expect ( u ( char ( 0x123 ) ) ) . toMatchString ( '\u{123}' ) ;
58- expect ( u ( char ( 0x1234 ) ) ) . toMatchString ( '\u{1234}' ) ;
59- expect ( u ( char ( 0x12345 ) ) ) . toMatchString ( '\u{12345}' ) ;
60- expect ( u ( char ( 0x103456 ) ) ) . toMatchString ( '\u{103456}' ) ;
61-
62- expect ( u ( char ( 'a' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( 'a' ) ;
63- expect ( u ( char ( 'ą' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( 'ą' ) ;
64- expect ( u ( char ( '©' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( '©' ) ;
65- expect ( u ( char ( '😎' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( '😎' ) ;
66- expect ( u ( char ( '😎' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( '\u{1f60e}' ) ;
43+ test ( '`unicodeChar ` matching' , ( ) => {
44+ expect ( unicodeChar ( 0 ) ) . toMatchString ( '\u{0}' ) ;
45+ expect ( unicodeChar ( 0x1 ) ) . toMatchString ( '\u{1}' ) ;
46+ expect ( unicodeChar ( 0x12 ) ) . toMatchString ( '\u{12}}' ) ;
47+ expect ( unicodeChar ( 0x123 ) ) . toMatchString ( '\u{123}' ) ;
48+ expect ( unicodeChar ( 0x1234 ) ) . toMatchString ( '\u{1234}}' ) ;
49+
50+ expect ( unicodeChar ( 'a' . codePointAt ( 0 ) ! ) ) . toMatchString ( 'a' ) ;
51+ expect ( unicodeChar ( 'ą' . codePointAt ( 0 ) ! ) ) . toMatchString ( 'ą' ) ;
52+ expect ( unicodeChar ( '©' . codePointAt ( 0 ) ! ) ) . toMatchString ( '©' ) ;
53+
54+ expect ( u ( unicodeChar ( 0 ) ) ) . toMatchString ( '\u{0}' ) ;
55+ expect ( u ( unicodeChar ( 0 ) ) ) . not . toMatchString ( 'a' ) ;
56+ expect ( u ( unicodeChar ( 0x1 ) ) ) . toMatchString ( '\u{1}' ) ;
57+ expect ( u ( unicodeChar ( 0x12 ) ) ) . toMatchString ( '\u{12}' ) ;
58+ expect ( u ( unicodeChar ( 0x123 ) ) ) . toMatchString ( '\u{123}' ) ;
59+ expect ( u ( unicodeChar ( 0x1234 ) ) ) . toMatchString ( '\u{1234}' ) ;
60+ expect ( u ( unicodeChar ( 0x12345 ) ) ) . toMatchString ( '\u{12345}' ) ;
61+ expect ( u ( unicodeChar ( 0x103456 ) ) ) . toMatchString ( '\u{103456}' ) ;
62+
63+ expect ( u ( unicodeChar ( 'a' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( 'a' ) ;
64+ expect ( u ( unicodeChar ( 'ą' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( 'ą' ) ;
65+ expect ( u ( unicodeChar ( '©' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( '©' ) ;
66+ expect ( u ( unicodeChar ( '😎' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( '😎' ) ;
67+ expect ( u ( unicodeChar ( '😎' . codePointAt ( 0 ) ! ) ) ) . toMatchString ( '\u{1f60e}' ) ;
6768} ) ;
6869
69- test ( '`char` nesting matching' , ( ) => {
70- expect ( u ( charClass ( char ( 'a' . codePointAt ( 0 ) ! ) , char ( 'ą' . codePointAt ( 0 ) ! ) ) ) ) . toMatchString ( 'a' ) ;
71- expect ( u ( charClass ( char ( 'a' . codePointAt ( 0 ) ! ) , char ( 'ą' . codePointAt ( 0 ) ! ) ) ) ) . toMatchString ( 'ą' ) ;
72- expect ( u ( charClass ( char ( 'a' . codePointAt ( 0 ) ! ) , char ( 'ą' . codePointAt ( 0 ) ! ) ) ) ) . not . toMatchString ( 'b' ) ;
70+ test ( '`unicodeChar` nesting matching' , ( ) => {
71+ expect (
72+ u ( charClass ( unicodeChar ( 'a' . codePointAt ( 0 ) ! ) , unicodeChar ( 'ą' . codePointAt ( 0 ) ! ) ) ) ,
73+ ) . toMatchString ( 'a' ) ;
74+ expect (
75+ u ( charClass ( unicodeChar ( 'a' . codePointAt ( 0 ) ! ) , unicodeChar ( 'ą' . codePointAt ( 0 ) ! ) ) ) ,
76+ ) . toMatchString ( 'ą' ) ;
77+ expect (
78+ u ( charClass ( unicodeChar ( 'a' . codePointAt ( 0 ) ! ) , unicodeChar ( 'ą' . codePointAt ( 0 ) ! ) ) ) ,
79+ ) . not . toMatchString ( 'b' ) ;
7380} ) ;
7481
75- test ( '`char ` edge cases handling' , ( ) => {
76- expect ( ( ) => u ( char ( NaN ) ) ) . toThrowErrorMatchingInlineSnapshot (
82+ test ( '`unicodeChar ` edge cases handling' , ( ) => {
83+ expect ( ( ) => u ( unicodeChar ( NaN ) ) ) . toThrowErrorMatchingInlineSnapshot (
7784 `"Expected a valid unicode code point but received NaN"` ,
7885 ) ;
79- expect ( ( ) => u ( char ( 1.5 ) ) ) . toThrowErrorMatchingInlineSnapshot (
86+ expect ( ( ) => u ( unicodeChar ( 1.5 ) ) ) . toThrowErrorMatchingInlineSnapshot (
8087 `"Expected a valid unicode code point but received 1.5"` ,
8188 ) ;
82- expect ( ( ) => u ( char ( - 1 ) ) ) . toThrowErrorMatchingInlineSnapshot (
89+ expect ( ( ) => u ( unicodeChar ( - 1 ) ) ) . toThrowErrorMatchingInlineSnapshot (
8390 `"Expected a valid unicode code point but received -1"` ,
8491 ) ;
85- expect ( ( ) => u ( char ( 0x110000 ) ) ) . toThrowErrorMatchingInlineSnapshot (
92+ expect ( ( ) => u ( unicodeChar ( 0x110000 ) ) ) . toThrowErrorMatchingInlineSnapshot (
8693 `"Expected a valid unicode code point but received 1114112"` ,
8794 ) ;
8895
89- expect ( u ( char ( 0x10ffff ) ) ) . toEqualRegex ( / \u{10ffff} / u) ;
96+ expect ( u ( unicodeChar ( 0x10ffff ) ) ) . toEqualRegex ( / \u{10ffff} / u) ;
97+ } ) ;
98+
99+ test ( '"char" alias' , ( ) => {
100+ expect ( char ( 'a' . codePointAt ( 0 ) ! ) ) . toEqualRegex ( / \u0061 / ) ;
90101} ) ;
91102
92103test ( '`unicodeProperty` pattern' , ( ) => {
0 commit comments