1- import { isAscii , isValidUtf8 , validateStringFormat } from '../stringFormats' ;
1+ import { isAscii , isUtf8 , validateStringFormat } from '../stringFormats' ;
22
33describe ( 'String format validation utilities' , ( ) => {
44 describe ( 'isAscii' , ( ) => {
@@ -30,57 +30,57 @@ describe('String format validation utilities', () => {
3030 } ) ;
3131 } ) ;
3232
33- describe ( 'isValidUtf8 ' , ( ) => {
33+ describe ( 'isUtf8 ' , ( ) => {
3434 test ( 'returns true for valid UTF-8 strings' , ( ) => {
35- expect ( isValidUtf8 ( '' ) ) . toBe ( true ) ;
36- expect ( isValidUtf8 ( 'hello' ) ) . toBe ( true ) ;
37- expect ( isValidUtf8 ( 'héllo' ) ) . toBe ( true ) ;
38- expect ( isValidUtf8 ( '🚀' ) ) . toBe ( true ) ;
39- expect ( isValidUtf8 ( '中文' ) ) . toBe ( true ) ;
40- expect ( isValidUtf8 ( 'русский' ) ) . toBe ( true ) ;
41- expect ( isValidUtf8 ( '👍💖🎉' ) ) . toBe ( true ) ; // Multiple emojis with surrogate pairs
35+ expect ( isUtf8 ( '' ) ) . toBe ( true ) ;
36+ expect ( isUtf8 ( 'hello' ) ) . toBe ( true ) ;
37+ expect ( isUtf8 ( 'héllo' ) ) . toBe ( true ) ;
38+ expect ( isUtf8 ( '🚀' ) ) . toBe ( true ) ;
39+ expect ( isUtf8 ( '中文' ) ) . toBe ( true ) ;
40+ expect ( isUtf8 ( 'русский' ) ) . toBe ( true ) ;
41+ expect ( isUtf8 ( '👍💖🎉' ) ) . toBe ( true ) ; // Multiple emojis with surrogate pairs
4242 } ) ;
4343
4444 test ( 'returns false for unpaired high surrogates' , ( ) => {
4545 const highSurrogate = String . fromCharCode ( 0xD800 ) ;
46- expect ( isValidUtf8 ( highSurrogate ) ) . toBe ( false ) ;
47- expect ( isValidUtf8 ( 'hello' + highSurrogate ) ) . toBe ( false ) ;
48- expect ( isValidUtf8 ( highSurrogate + 'world' ) ) . toBe ( false ) ;
46+ expect ( isUtf8 ( highSurrogate ) ) . toBe ( false ) ;
47+ expect ( isUtf8 ( 'hello' + highSurrogate ) ) . toBe ( false ) ;
48+ expect ( isUtf8 ( highSurrogate + 'world' ) ) . toBe ( false ) ;
4949 } ) ;
5050
5151 test ( 'returns false for orphaned low surrogates' , ( ) => {
5252 const lowSurrogate = String . fromCharCode ( 0xDC00 ) ;
53- expect ( isValidUtf8 ( lowSurrogate ) ) . toBe ( false ) ;
54- expect ( isValidUtf8 ( 'hello' + lowSurrogate ) ) . toBe ( false ) ;
55- expect ( isValidUtf8 ( lowSurrogate + 'world' ) ) . toBe ( false ) ;
53+ expect ( isUtf8 ( lowSurrogate ) ) . toBe ( false ) ;
54+ expect ( isUtf8 ( 'hello' + lowSurrogate ) ) . toBe ( false ) ;
55+ expect ( isUtf8 ( lowSurrogate + 'world' ) ) . toBe ( false ) ;
5656 } ) ;
5757
5858 test ( 'returns false for high surrogate not followed by low surrogate' , ( ) => {
5959 const highSurrogate = String . fromCharCode ( 0xD800 ) ;
6060 const notLowSurrogate = String . fromCharCode ( 0xE000 ) ; // Outside surrogate range
61- expect ( isValidUtf8 ( highSurrogate + notLowSurrogate ) ) . toBe ( false ) ;
62- expect ( isValidUtf8 ( highSurrogate + 'a' ) ) . toBe ( false ) ;
61+ expect ( isUtf8 ( highSurrogate + notLowSurrogate ) ) . toBe ( false ) ;
62+ expect ( isUtf8 ( highSurrogate + 'a' ) ) . toBe ( false ) ;
6363 } ) ;
6464
6565 test ( 'returns true for valid surrogate pairs' , ( ) => {
6666 // Create a valid surrogate pair manually
6767 const highSurrogate = String . fromCharCode ( 0xD800 ) ;
6868 const lowSurrogate = String . fromCharCode ( 0xDC00 ) ;
69- expect ( isValidUtf8 ( highSurrogate + lowSurrogate ) ) . toBe ( true ) ;
69+ expect ( isUtf8 ( highSurrogate + lowSurrogate ) ) . toBe ( true ) ;
7070
7171 // Test with real emoji
72- expect ( isValidUtf8 ( '👨💻' ) ) . toBe ( true ) ; // Complex emoji with ZWJ
73- expect ( isValidUtf8 ( '🏳️🌈' ) ) . toBe ( true ) ; // Rainbow flag emoji
72+ expect ( isUtf8 ( '👨💻' ) ) . toBe ( true ) ; // Complex emoji with ZWJ
73+ expect ( isUtf8 ( '🏳️🌈' ) ) . toBe ( true ) ; // Rainbow flag emoji
7474 } ) ;
7575
7676 test ( 'handles sequences correctly' , ( ) => {
7777 const highSurrogate = String . fromCharCode ( 0xD800 ) ;
7878 const lowSurrogate = String . fromCharCode ( 0xDC00 ) ;
7979 const validPair = highSurrogate + lowSurrogate ;
8080
81- expect ( isValidUtf8 ( validPair + validPair ) ) . toBe ( true ) ; // Two valid pairs
82- expect ( isValidUtf8 ( validPair + highSurrogate ) ) . toBe ( false ) ; // Valid pair + unpaired high
83- expect ( isValidUtf8 ( 'hello' + validPair + 'world' ) ) . toBe ( true ) ; // Valid pair in middle
81+ expect ( isUtf8 ( validPair + validPair ) ) . toBe ( true ) ; // Two valid pairs
82+ expect ( isUtf8 ( validPair + highSurrogate ) ) . toBe ( false ) ; // Valid pair + unpaired high
83+ expect ( isUtf8 ( 'hello' + validPair + 'world' ) ) . toBe ( true ) ; // Valid pair in middle
8484 } ) ;
8585 } ) ;
8686
@@ -90,7 +90,7 @@ describe('String format validation utilities', () => {
9090 expect ( validateStringFormat ( 'héllo' , 'ascii' ) ) . toBe ( false ) ;
9191 } ) ;
9292
93- test ( 'delegates to isValidUtf8 for utf8 format' , ( ) => {
93+ test ( 'delegates to isUtf8 for utf8 format' , ( ) => {
9494 expect ( validateStringFormat ( 'hello' , 'utf8' ) ) . toBe ( true ) ;
9595 expect ( validateStringFormat ( 'héllo' , 'utf8' ) ) . toBe ( true ) ;
9696 expect ( validateStringFormat ( String . fromCharCode ( 0xD800 ) , 'utf8' ) ) . toBe ( false ) ;
0 commit comments