You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
import t from 'tap';
|
|
|
|
import { getRegexStringForThesaurusPath } from './viteThesaurusRegexPlugin.js';
|
|
|
|
void t.test('extractWordsFromFile', async (t) => {
|
|
const regexString = await getRegexStringForThesaurusPath(
|
|
new URL('../assets/th-en-x-basic.ooo-thesaurus', import.meta.url),
|
|
);
|
|
const regex = new RegExp(regexString, 'gi');
|
|
|
|
const getMatches = (str: string) =>
|
|
[...str.matchAll(regex)].map((match) => match[0]);
|
|
|
|
t.strictSame(
|
|
getMatches(
|
|
'afterthought airplane another anybody anyhow anyone anything anywhere',
|
|
),
|
|
[],
|
|
);
|
|
|
|
t.strictSame(
|
|
getMatches(
|
|
'afterthought airplane another xxx anybody anyhow anyone anything anywhere',
|
|
),
|
|
['xxx'],
|
|
);
|
|
|
|
t.strictSame(
|
|
getMatches(
|
|
'xx afterthought airplane another yy anybody anyhow anyone anything anywhere zzzz',
|
|
),
|
|
['xx', 'yy', 'zzzz'],
|
|
);
|
|
|
|
t.strictSame(getMatches('xx yy zzzz'), ['xx', 'yy', 'zzzz']);
|
|
|
|
t.strictSame(
|
|
getMatches(
|
|
"Thing to help people escape really fast if there's a problem and everything is on fire so they decide not to go to space",
|
|
),
|
|
[],
|
|
);
|
|
});
|
|
|