@@ -4,7 +4,12 @@ import { test } from 'node:test';
44import * as assert from 'node:assert/strict' ;
55import fc from 'fast-check' ;
66
7- import { graphemeSegments , countGrapheme , GraphemeCategory } from 'unicode-segmenter/grapheme' ;
7+ import {
8+ GraphemeCategory ,
9+ graphemeSegments ,
10+ countGrapheme ,
11+ splitGraphemes ,
12+ } from 'unicode-segmenter/grapheme' ;
813import { assertObjectContaining } from './_helper.js' ;
914
1015test ( 'graphemeSegments' , async t => {
@@ -74,10 +79,6 @@ test('countGrapheme', async t => {
7479 assert . equal ( countGrapheme ( 'abcd' ) , 4 ) ;
7580 } ) ;
7681
77- await t . test ( 'latin' , ( ) => {
78- assert . equal ( countGrapheme ( 'abcd' ) , 4 ) ;
79- } ) ;
80-
8182 await t . test ( 'flags' , ( ) => {
8283 assert . equal ( countGrapheme ( '🇷🇸🇮🇴' ) , 2 ) ;
8384 } ) ;
@@ -104,6 +105,61 @@ test('countGrapheme', async t => {
104105 } ) ;
105106} ) ;
106107
108+ test ( 'splitGrapheme' , async t => {
109+ await t . test ( 'latin' , ( ) => {
110+ assert . deepEqual (
111+ [ ...splitGraphemes ( 'abcd' ) ] ,
112+ [ 'a' , 'b' , 'c' , 'd' ] ,
113+ ) ;
114+ } ) ;
115+
116+ await t . test ( 'flags' , ( ) => {
117+ assert . deepEqual (
118+ [ ...splitGraphemes ( '🇷🇸🇮🇴' ) ] ,
119+ [ '🇷🇸' , '🇮🇴' ] ,
120+ ) ;
121+ } ) ;
122+
123+ await t . test ( 'emoji' , ( ) => {
124+ assert . deepEqual (
125+ [ ...splitGraphemes ( '👻👩👩👦👦' ) ] ,
126+ [ '👻' , '👩👩👦👦' ] ,
127+ ) ;
128+ assert . deepEqual (
129+ [ ...splitGraphemes ( '🌷🎁💩😜👍🏳️🌈' ) ] ,
130+ [ '🌷' , '🎁' , '💩' , '😜' , '👍' , '🏳️🌈' ] ,
131+ ) ;
132+ } ) ;
133+
134+ await t . test ( 'diacritics as combining marks' , ( ) => {
135+ assert . deepEqual (
136+ [ ...splitGraphemes ( 'Ĺo͂řȩm̅' ) ] ,
137+ [ 'Ĺ' , 'o͂' , 'ř' , 'ȩ' , 'm̅' ] ,
138+ ) ;
139+ } ) ;
140+
141+ await t . test ( 'Jamo' , ( ) => {
142+ assert . deepEqual (
143+ [ ...splitGraphemes ( '가갉' ) ] ,
144+ [ '가' , '갉' ] ,
145+ ) ;
146+ } ) ;
147+
148+ await t . test ( 'Hindi' , ( ) => {
149+ assert . deepEqual (
150+ [ ...splitGraphemes ( 'अनुच्छेद' ) ] ,
151+ [ 'अ' , 'नु' , 'च्छे' , 'द' ] ,
152+ ) ;
153+ } ) ;
154+
155+ await t . test ( 'demonic' , ( ) => {
156+ assert . deepEqual (
157+ [ ...splitGraphemes ( 'Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞' ) ] ,
158+ [ 'Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍' , 'A̴̵̜̰͔ͫ͗͢' , 'L̠ͨͧͩ͘' , 'G̴̻͈͍͔̹̑͗̎̅͛́' , 'Ǫ̵̹̻̝̳͂̌̌͘' , '!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞' ] ,
159+ ) ;
160+ } ) ;
161+ } ) ;
162+
107163test ( 'spec compliant' , async t => {
108164 fc . configureGlobal ( {
109165 // Fix seed here for stable coverage report
0 commit comments