namespace unicode { export function run ( ) { let shortASCII = "hello world!" ; let shortUTF = "hęłłó world!" ; let longASCII = `
99 Bottles of beer on the wall!
Take one down
Pass it around
98 Bottles of beer on the wall!
Take one down
Pass it around
97 Bottles of beer on the wall
Take one down
Pass it around
` ; let longUTF = `
99 Bottlęs of beer on the wall! 💺
Take one down
Pass it around
98 Bottłeś of beer on the wall! 💃
Take one down
Pass it around
97 Bottles of beer on the wall! 😂
Take óne down
Pasś it around
` ; testAllStr ( shortASCII ) ; testAllStr ( shortUTF ) ; testAllStr ( longASCII ) ; testAllStr ( longUTF ) ; testAllStr ( longUTF + longASCII ) ; testAllStr ( longUTF + shortUTF ) ; } function testAllStr ( s ) { msg ( "utf8-t: " + s . length ) ; testOneCh ( s ) ; testFromCh ( s ) ; testSliceR ( s ) ; } function testOneCh ( s ) { let r = "" ; for ( let i = 0 ; i < s . length ; ++ i ) r += s [ i ] ; assert ( s . length == r . length , "1chL" ) ; assert ( s == r , "1ch" ) ; } function testFromCh ( s ) { let r = "" ; for ( let i = 0 ; i < s . length ; ++ i ) r += String . fromCharCode ( s . charCodeAt ( i ) ) ; assert ( s == r , "1fch" ) ; } function testSliceR ( s ) { for ( let rep = 0 ; rep < 20 ; ++ rep ) { let r = "" ; for ( let i = 0 ; i < s . length ; ) { let len = Math . randomRange ( 0 , 10 ) ; r += s . slice ( i , i + len ) ; i += len ; } assert ( s == r , "1sl" ) ; } } } unicode . run ( ) ;