Skip to content

Commit

Permalink
fix browser test
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Jun 13, 2024
1 parent a901d5f commit a315ff5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions benchmark/performance-grapheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { Segmenter as FormatjsSegmenter } from '@formatjs/intl-segmenter/src/seg

import { graphemeSegments } from '../src/grapheme.js';

if (globalThis.origin) {
// Browser-like env
const isWebWorker = typeof self === 'object';
// Node.js, Deno, Bun
const isSystemRuntime = typeof process === 'object';

if (isWebWorker) {
await unicodeSegmentation.default();
}

Expand Down Expand Up @@ -58,11 +63,13 @@ const 테스트문자열 = "안녕하세요! Welcome to the unicode-segementer l
for (const [title, input] of testcases) {
const expected = [...intlSegmenter.segment(input)].map(({ segment }) => segment);

assert.deepEqual([...graphemeSegments(input)].map(({ segment }) => segment), expected);
assert.deepEqual([...graphemer.iterateGraphemes(input)], expected);
assert.deepEqual([...graphemeSplitter.iterateGraphemes(input)], expected);
assert.deepEqual([...unicodeSegmentation.collect(input)], expected);
assert.deepEqual([...formatjsSegmenter.segment(input)].map(({ segment }) => segment), expected);
if (isSystemRuntime) {
assert.deepEqual([...graphemeSegments(input)].map(({ segment }) => segment), expected);
assert.deepEqual([...graphemer.iterateGraphemes(input)], expected);
assert.deepEqual([...graphemeSplitter.iterateGraphemes(input)], expected);
assert.deepEqual([...unicodeSegmentation.collect(input)], expected);
assert.deepEqual([...formatjsSegmenter.segment(input)].map(({ segment }) => segment), expected);
}

group(title, () => {
baseline('unicode-segmenter/grapheme', () => {
Expand Down Expand Up @@ -94,6 +101,6 @@ for (const [title, input] of testcases) {

await run();

if (typeof self === 'object') {
if (isWebWorker) {
self.postMessage('done');
}

0 comments on commit a315ff5

Please sign in to comment.