Files
pinyin-pro/test/basic.test.js

69 lines
1.7 KiB
JavaScript

const { pinyin } = require('../');
const expect = require('chai').expect;
describe('basic', () => {
it('[basic]正常拼音字符串', () => {
const result = pinyin('汉语拼音');
expect(result).to.be.equal('hàn yǔ pīn yīn');
});
it('[basic]拼音+非汉字字符串', () => {
const result = pinyin('汉语拼音xxx.,');
expect(result).to.be.equal('hàn yǔ pīn yīn x x x . ,');
});
it('[basic]正常拼音数组', () => {
const result = pinyin('汉语拼音', { type: 'array' });
expect(result).to.deep.equal(['hàn', 'yǔ', 'pīn', 'yīn']);
});
it('[basic]拼音+非汉字数组', () => {
const result = pinyin('汉语拼音xxx.,', { type: 'array' });
expect(result).to.deep.equal([
'hàn',
'yǔ',
'pīn',
'yīn',
'x',
'x',
'x',
'.',
',',
]);
});
it('[basic]空字符串', () => {
const result = pinyin('');
expect(result).to.be.equal('');
});
it('[basic]空数组', () => {
const result = pinyin('', { type: 'array' });
expect(result).to.deep.equal([]);
});
it('[basic]正常拼音1', () => {
const result = pinyin('哈发生你看三零四');
expect(result).to.be.equal('hā fā shēng nǐ kàn sān líng sì');
});
it('[basic]正常拼音数组1', () => {
const result = pinyin('哈发生你看三零四', { type: 'array' });
expect(result).to.deep.equal([
'hā',
'fā',
'shēng',
'nǐ',
'kàn',
'sān',
'líng',
'sì',
]);
});
it('[basic]test行不行', () => {
const result = pinyin('行不行');
expect(result).to.be.equal('xíng bù xíng');
});
});