@@ -23,4 +23,37 @@ describe('splitUtf8', () => {
2323 new TextEncoder ( ) . encode ( 'd' ) ,
2424 ] ) ;
2525 } ) ;
26+
27+ it ( 'splits a string with special characters into chunks of the given size' , ( ) => {
28+ expect ( splitUtf8 ( 'héllo wörld' , 5 ) ) . toEqual ( [
29+ new TextEncoder ( ) . encode ( 'héll' ) ,
30+ new TextEncoder ( ) . encode ( 'o wö' ) ,
31+ new TextEncoder ( ) . encode ( 'rld' ) ,
32+ ] ) ;
33+ } ) ;
34+
35+ it ( 'splits a string with multi-byte utf8 characters correctly' , ( ) => {
36+ expect ( splitUtf8 ( 'こんにちは世界' , 5 ) ) . toEqual ( [
37+ new TextEncoder ( ) . encode ( 'こん' ) ,
38+ new TextEncoder ( ) . encode ( 'にち' ) ,
39+ new TextEncoder ( ) . encode ( 'は世' ) ,
40+ new TextEncoder ( ) . encode ( '界' ) ,
41+ ] ) ;
42+ } ) ;
43+
44+ it ( 'handles a string with a single multi-byte utf8 character' , ( ) => {
45+ expect ( splitUtf8 ( '😊' , 5 ) ) . toEqual ( [ new TextEncoder ( ) . encode ( '😊' ) ] ) ;
46+ } ) ;
47+
48+ it ( 'handles a string with mixed single and multi-byte utf8 characters' , ( ) => {
49+ expect ( splitUtf8 ( 'a😊b' , 2 ) ) . toEqual ( [
50+ new TextEncoder ( ) . encode ( 'a' ) ,
51+ new TextEncoder ( ) . encode ( '😊' ) ,
52+ new TextEncoder ( ) . encode ( 'b' ) ,
53+ ] ) ;
54+ } ) ;
55+
56+ it ( 'handles an empty string' , ( ) => {
57+ expect ( splitUtf8 ( '' , 5 ) ) . toEqual ( [ ] ) ;
58+ } ) ;
2659} ) ;
0 commit comments