物管理前端
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.

89 lines
2.9 KiB

  1. const assert = require('assert')
  2. const PinyinMatch = require('../dist/main.js')
  3. const PinyinMatch2 = require('../dist/traditional.js') // 繁体字
  4. let text = '123曾经沧海难为水除却巫山不是云'
  5. describe('PinyinMatch', () => {
  6. describe('#match', () => {
  7. it('精准匹配', () => {
  8. assert.deepEqual([1, 3], PinyinMatch.match(text, '23曾'))
  9. })
  10. it('首字母匹配', () => {
  11. assert.deepEqual([3, 5], PinyinMatch.match(text, 'cjc'))
  12. })
  13. it('完整拼音匹配', () => {
  14. assert.deepEqual([3, 6], PinyinMatch.match(text, 'cengjingcanghai'))
  15. })
  16. it('最后一个拼音不完整', () => {
  17. assert.deepEqual([3, 6], PinyinMatch.match(text, 'cengjingcangha'))
  18. })
  19. it('分词功能', () => {
  20. assert.equal(false, PinyinMatch.match(text, 'engjing'))
  21. })
  22. it('多音字', () => {
  23. assert.deepEqual([3, 5], PinyinMatch.match(text, 'zengjingcang'))
  24. })
  25. it('忽略空格', () => {
  26. assert.deepEqual([3, 5], PinyinMatch.match(text, 'zengji ng cang'))
  27. })
  28. it('超出', () => {
  29. assert.deepEqual(false, PinyinMatch.match(text, 'zengji ng cangsdjfkl'))
  30. })
  31. it('忽略空格', () => {
  32. assert.deepEqual([6, 12], PinyinMatch.match(' 我 爱你 中 国 ', 'nzg'))
  33. })
  34. it('忽略空格原文', () => {
  35. assert.deepEqual([5, 8], PinyinMatch.match(' 我 爱你 中 国s ', '爱你中'))
  36. })
  37. it('忽略空格原文', () => {
  38. assert.deepEqual([5, 13], PinyinMatch.match(' 我 爱你 中 国s ', '爱你中国s'))
  39. })
  40. it('超出原文', () => {
  41. assert.deepEqual(false, PinyinMatch.match(' 我 爱你 中 国s ', '爱你中国sj'))
  42. })
  43. it('bao', () => {
  44. assert.deepEqual([1, 1], PinyinMatch.match('淘宝', 'bao'))
  45. })
  46. it('issues 7', () => {
  47. assert.deepEqual([0, 0], PinyinMatch.match('卡号打开', 'ka'))
  48. })
  49. it('嫚', () => {
  50. assert.deepEqual([0, 0], PinyinMatch.match('嫚', 'man'))
  51. })
  52. it('喆', () => {
  53. assert.deepEqual([0, 0], PinyinMatch.match('喆', 'zhe'))
  54. })
  55. it('钭', () => {
  56. assert.deepEqual([0, 0], PinyinMatch.match('钭', 'tou'))
  57. })
  58. it('lue', () => {
  59. assert.deepEqual([0, 0], PinyinMatch.match('略', 'lue'))
  60. })
  61. it('lve', () => {
  62. assert.deepEqual([0, 0], PinyinMatch.match('略', 'lve'))
  63. })
  64. it('que', () => {
  65. assert.deepEqual([0, 0], PinyinMatch.match('缺', 'que'))
  66. })
  67. it('qve', () => {
  68. assert.deepEqual([0, 0], PinyinMatch.match('缺', 'qve'))
  69. })
  70. it('nü', () => {
  71. assert.deepEqual([0, 0], PinyinMatch.match('女', 'nü'))
  72. })
  73. it('lüe', () => {
  74. assert.deepEqual([0, 0], PinyinMatch.match('略', 'lüe'))
  75. })
  76. it('ü !== v', () => {
  77. assert.equal(false, PinyinMatch.match('v', 'ü'))
  78. })
  79. })
  80. })
  81. describe('PinyinMatch2', () => {
  82. describe('#match 繁体', () => {
  83. it('繁体字匹配', () => {
  84. assert.deepEqual([0, 0], PinyinMatch2.match('發', 'fa'))
  85. })
  86. })
  87. })