Files
pinyin-pro/test/segmentit.test.js
2024-04-15 14:40:48 +08:00

38 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { pinyin, addDict, customPinyin } from '../lib/index';
import { expect, describe, it } from 'vitest';
const completeDict = require("@pinyin-pro/data/complete.json");
addDict(completeDict);
describe('segmentit', () => {
it('[surname]segmentit-max-probability', () => {
const result = pinyin('小明硕士毕业于中国科学院计算所,后在日本京都大学深造');
expect(result).to.be.equal('xiǎo míng shuò shì bì yè yú zhōng guó kē xué yuàn jì suàn suǒ hòu zài rì běn jīng dū dà xué shēn zào');
});
it('[surname]segmentit-reverse-max-match', () => {
customPinyin({
京都: 'jīng dū',
: 'shì',
});
const result = pinyin('小明硕士毕业于中国科学院计算所,后在日本京都大学深造', { segmentit: 1 });
expect(result).to.be.equal('xiǎo míng shuò shì bì yè yú zhōng guó kē xué yuàn jì suàn suǒ hòu zài rì běn jīng dū dà xué shēn zào');
});
it('[surname]segmentit:min-segmentit', () => {
const result = pinyin('小明硕士毕业于中国科学院计算所,后在日本京都大学深造', { segmentit: 3 });
expect(result).to.be.equal('xiǎo míng shuò shì bì yè yú zhōng guó kē xué yuàn jì suàn suǒ hòu zài rì běn jīng dū dà xué shēn zào');
});
it('[surname]segmentit with custom', () => {
customPinyin({
京都: 'jīng dū',
: 'shì',
});
const result = pinyin('小明硕士毕业于中国科学院计算所,后在日本京都大学深造', { segmentit: 3, mode: 'surname' });
expect(result).to.be.equal('xiǎo míng shuò shì bì yè yú zhōng guó kē xué yuàn jì suàn suǒ hòu zài rì běn jīng dū dà xué shēn zào');
});
});