48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
|
const assert = require('assert')
|
||
|
const PinyinMatch = require('../src/index')
|
||
|
let text = '123曾经沧海难为水除却巫山不是云'
|
||
|
|
||
|
describe('PinyinMatch', () => {
|
||
|
describe('#match', () => {
|
||
|
it('精准匹配', () => {
|
||
|
assert.deepEqual([1, 3], PinyinMatch.match(text, '23曾'))
|
||
|
})
|
||
|
it('首字母匹配', () => {
|
||
|
assert.deepEqual([3, 5], PinyinMatch.match(text, 'cjc'))
|
||
|
})
|
||
|
it('完整拼音匹配', () => {
|
||
|
assert.deepEqual([3, 6], PinyinMatch.match(text, 'cengjingcanghai'))
|
||
|
})
|
||
|
it('最后一个拼音不完整', () => {
|
||
|
assert.deepEqual([3, 6], PinyinMatch.match(text, 'cengjingcangha'))
|
||
|
})
|
||
|
it('分词功能', () => {
|
||
|
assert.equal(false, PinyinMatch.match(text, 'engjing'))
|
||
|
})
|
||
|
it('多音字', () => {
|
||
|
assert.deepEqual([3, 5], PinyinMatch.match(text, 'zengjingcang'))
|
||
|
})
|
||
|
it('忽略空格', () => {
|
||
|
assert.deepEqual([3, 5], PinyinMatch.match(text, 'zengji ng cang'))
|
||
|
})
|
||
|
it('超出', () => {
|
||
|
assert.deepEqual(false, PinyinMatch.match(text, 'zengji ng cangsdjfkl'))
|
||
|
})
|
||
|
it('忽略空格', () => {
|
||
|
assert.deepEqual([6, 12], PinyinMatch.match(' 我 爱你 中 国 ', 'nzg'))
|
||
|
})
|
||
|
it('忽略空格原文', () => {
|
||
|
assert.deepEqual([5, 8], PinyinMatch.match(' 我 爱你 中 国s ', '爱你中'))
|
||
|
})
|
||
|
it('忽略空格原文', () => {
|
||
|
assert.deepEqual([5, 13], PinyinMatch.match(' 我 爱你 中 国s ', '爱你中国s'))
|
||
|
})
|
||
|
it('超出原文', () => {
|
||
|
assert.deepEqual(false, PinyinMatch.match(' 我 爱你 中 国s ', '爱你中国sj'))
|
||
|
})
|
||
|
it('bao', () => {
|
||
|
assert.deepEqual([1, 1], PinyinMatch.match('淘宝', 'bao'))
|
||
|
})
|
||
|
})
|
||
|
})
|