|
1 |
| -import { match, customPinyin, clearCustomDict } from '../lib/index'; |
2 |
| -import { expect, describe, it } from 'vitest'; |
| 1 | +import { match, customPinyin, clearCustomDict } from "../lib/index"; |
| 2 | +import { expect, describe, it } from "vitest"; |
3 | 3 |
|
4 |
| -describe('match', () => { |
5 |
| - it('[match]default', () => { |
6 |
| - const result = match('欢迎使用汉语拼音', 'hy'); |
| 4 | +describe("match", () => { |
| 5 | + it("[match]default", () => { |
| 6 | + const result = match("欢迎使用汉语拼音", "hy"); |
7 | 7 | expect(result).to.deep.equal([0, 1]);
|
8 | 8 | });
|
9 | 9 |
|
10 |
| - it('[match]start and continuous', () => { |
11 |
| - const result = match('欢迎使用汉语拼音', 'yingshyon', { |
12 |
| - precision: 'start', |
| 10 | + it("[match]start and continuous", () => { |
| 11 | + const result = match("欢迎使用汉语拼音", "yingshyon", { |
| 12 | + precision: "start", |
13 | 13 | continuous: true,
|
14 | 14 | });
|
15 | 15 | expect(result).to.deep.equal([1, 2, 3]);
|
16 | 16 | });
|
17 | 17 |
|
18 |
| - it('[match]multiple1', () => { |
19 |
| - const result = match('会计', 'kj'); |
| 18 | + it("[match]multiple1", () => { |
| 19 | + const result = match("会计", "kj"); |
20 | 20 | expect(result).to.deep.equal([0, 1]);
|
21 | 21 | });
|
22 | 22 |
|
23 |
| - it('[match]multiple2', () => { |
24 |
| - const result = match('会计', 'huij'); |
| 23 | + it("[match]multiple2", () => { |
| 24 | + const result = match("会计", "huij"); |
25 | 25 | expect(result).to.deep.equal([0, 1]);
|
26 | 26 | });
|
27 | 27 |
|
28 |
| - it('[match]any', () => { |
29 |
| - const result = match('开会', 'kaiui', { precision: 'any' }); |
| 28 | + it("[match]any", () => { |
| 29 | + const result = match("开会", "kaiui", { precision: "any" }); |
30 | 30 | expect(result).to.deep.equal([0, 1]);
|
31 | 31 | });
|
32 | 32 |
|
33 |
| - it('[match]any&empty', () => { |
34 |
| - const result = match('开会', '', { precision: 'any' }); |
| 33 | + it("[match]any&empty", () => { |
| 34 | + const result = match("开会", "", { precision: "any" }); |
35 | 35 | expect(result).to.deep.equal(null);
|
36 | 36 | });
|
37 | 37 |
|
38 |
| - it('[match]any&continuous', () => { |
39 |
| - const result = match('开个大会', 'kaiui', { |
40 |
| - precision: 'any', |
| 38 | + it("[match]any&continuous", () => { |
| 39 | + const result = match("开个大会", "kaiui", { |
| 40 | + precision: "any", |
41 | 41 | continuous: true,
|
42 | 42 | });
|
43 | 43 | expect(result).to.deep.equal(null);
|
44 | 44 | });
|
45 | 45 |
|
46 |
| - it('[match]any&nonZh', () => { |
47 |
| - const result = match('开会', 'kaiuiaaaa', { precision: 'any' }); |
| 46 | + it("[match]any&nonZh", () => { |
| 47 | + const result = match("开会", "kaiuiaaaa", { precision: "any" }); |
48 | 48 | expect(result).to.deep.equal(null);
|
49 | 49 | });
|
50 | 50 |
|
51 |
| - it('[match]any&space', () => { |
52 |
| - const result = match('开 会s 啊', 'kaiuisa', { precision: 'any' }); |
| 51 | + it("[match]any&space", () => { |
| 52 | + const result = match("开 会s 啊", "kaiuisa", { precision: "any" }); |
53 | 53 | expect(result).to.deep.equal([0, 7, 8, 11]);
|
54 | 54 | });
|
55 | 55 |
|
56 |
| - it('[match]fail with sucess', () => { |
57 |
| - const result = match('开会', 'kaig'); |
| 56 | + it("[match]fail with sucess", () => { |
| 57 | + const result = match("开会", "kaig"); |
58 | 58 | expect(result).to.deep.equal(null);
|
59 | 59 | });
|
60 | 60 |
|
61 |
| - it('[match]fail', () => { |
62 |
| - const result = match('开会', 'l'); |
| 61 | + it("[match]fail", () => { |
| 62 | + const result = match("开会", "l"); |
63 | 63 | expect(result).to.deep.equal(null);
|
64 | 64 | });
|
65 | 65 |
|
66 |
| - it('[match]uncontinuous', () => { |
67 |
| - const result = match('汉语拼音', 'hanpin'); |
| 66 | + it("[match]uncontinuous", () => { |
| 67 | + const result = match("汉语拼音", "hanpin"); |
68 | 68 | expect(result).to.deep.equal([0, 2]);
|
69 | 69 | });
|
70 | 70 |
|
71 |
| - it('[match]basic', () => { |
72 |
| - const result = match('汉语拼音', 'hyupy'); |
| 71 | + it("[match]basic", () => { |
| 72 | + const result = match("汉语拼音", "hyupy"); |
73 | 73 | expect(result).to.deep.equal([0, 1, 2, 3]);
|
74 | 74 | });
|
75 | 75 |
|
76 |
| - it('[match]first & double unicode', () => { |
77 |
| - const result = match('𧒽测试', 'cs'); |
| 76 | + it("[match]first & double unicode", () => { |
| 77 | + const result = match("𧒽测试", "cs"); |
78 | 78 | expect(result).to.deep.equal([2, 3]);
|
79 | 79 | });
|
80 | 80 |
|
81 |
| - it('[match]start', () => { |
82 |
| - const result = match('欢迎使用汉语拼音', '欢yingshy', { |
83 |
| - precision: 'start', |
| 81 | + it("[match]start", () => { |
| 82 | + const result = match("欢迎使用汉语拼音", "欢yingshy", { |
| 83 | + precision: "start", |
84 | 84 | });
|
85 | 85 | expect(result).to.deep.equal([0, 1, 2, 3]);
|
86 | 86 | });
|
87 | 87 |
|
88 |
| - it('[match]first&space', () => { |
89 |
| - const result = match('𧒽测 试', 'c s'); |
| 88 | + it("[match]first&space", () => { |
| 89 | + const result = match("𧒽测 试", "c s"); |
90 | 90 | expect(result).to.deep.equal([2, 4]);
|
91 | 91 | });
|
92 | 92 |
|
93 |
| - it('[match]first&space', () => { |
94 |
| - customPinyin({ |
95 |
| - 𧒽: 'lei' |
96 |
| - }, { |
97 |
| - multiple: 'replace' |
98 |
| - }) |
99 |
| - const result = match('𧒽测 试', 'l c s'); |
| 93 | + it("[match]first&space", () => { |
| 94 | + customPinyin( |
| 95 | + { |
| 96 | + 𧒽: "lei", |
| 97 | + }, |
| 98 | + { |
| 99 | + multiple: "replace", |
| 100 | + } |
| 101 | + ); |
| 102 | + const result = match("𧒽测 试", "l c s"); |
100 | 103 | expect(result).to.deep.equal([0, 1, 2, 4]);
|
101 |
| - clearCustomDict(['pinyin', 'multiple', 'polyphonic']); |
| 104 | + clearCustomDict(["pinyin", "multiple", "polyphonic"]); |
102 | 105 | });
|
103 | 106 |
|
104 |
| - it('[match]nonZh match', () => { |
105 |
| - const result = match('测uuuuuuuuuu试', 'cuuuuuu'); |
| 107 | + it("[match]nonZh match", () => { |
| 108 | + const result = match("测uuuuuuuuuu试", "cuuuuuu"); |
106 | 109 | expect(result).to.deep.equal([0, 1, 2, 3, 4, 5, 6]);
|
107 | 110 | });
|
108 | 111 |
|
109 |
| - it('[match]lastPrecision every fail', () => { |
110 |
| - const result = match('汉语拼音', 'hanyupinyi', { lastPrecision: 'every' }); |
| 112 | + it("[match]lastPrecision every fail", () => { |
| 113 | + const result = match("汉语拼音", "hanyupinyi", { lastPrecision: "every" }); |
111 | 114 | expect(result).to.deep.equal(null);
|
112 | 115 | });
|
113 | 116 |
|
114 |
| - it('[match]lastPrecision every success', () => { |
115 |
| - const result = match('汉语拼音', 'hanyupinyin', { lastPrecision: 'every' }); |
| 117 | + it("[match]lastPrecision every success", () => { |
| 118 | + const result = match("汉语拼音", "hanyupinyin", { lastPrecision: "every" }); |
116 | 119 | expect(result).to.deep.equal([0, 1, 2, 3]);
|
117 | 120 | });
|
118 | 121 |
|
119 |
| - it('[match]lastPrecision first fail', () => { |
120 |
| - const result = match('汉语拼音', 'hanyupinyi', { lastPrecision: 'first' }); |
| 122 | + it("[match]lastPrecision first fail", () => { |
| 123 | + const result = match("汉语拼音", "hanyupinyi", { lastPrecision: "first" }); |
121 | 124 | expect(result).to.deep.equal(null);
|
122 | 125 | });
|
123 | 126 |
|
124 |
| - it('[match]lastPrecision first success', () => { |
125 |
| - const result = match('汉语拼音', 'hanyupiny', { lastPrecision: 'first' }); |
| 127 | + it("[match]lastPrecision first success", () => { |
| 128 | + const result = match("汉语拼音", "hanyupiny", { lastPrecision: "first" }); |
126 | 129 | expect(result).to.deep.equal([0, 1, 2, 3]);
|
127 | 130 | });
|
128 | 131 |
|
129 |
| - it('[match]lastPrecision any', () => { |
130 |
| - const result = match('汉语拼音', 'hanyupini', { lastPrecision: 'any' }); |
| 132 | + it("[match]lastPrecision any", () => { |
| 133 | + const result = match("汉语拼音", "hanyupini", { lastPrecision: "any" }); |
131 | 134 | expect(result).to.deep.equal([0, 1, 2, 3]);
|
132 | 135 | });
|
133 | 136 |
|
134 |
| - it('[match]lastPrecision ignore space', () => { |
135 |
| - const result = match('汉语 拼音', 'hanyu pini', { lastPrecision: 'any', space: 'ignore' }); |
| 137 | + it("[match]lastPrecision ignore space", () => { |
| 138 | + const result = match("汉语 拼音", "hanyu pini", { |
| 139 | + lastPrecision: "any", |
| 140 | + space: "ignore", |
| 141 | + }); |
136 | 142 | expect(result).to.deep.equal([0, 1, 3, 4]);
|
137 | 143 | });
|
138 | 144 |
|
139 |
| - it('[match]lastPrecision preserve space', () => { |
140 |
| - const result = match('汉语 拼音', 'hanyu pini', { lastPrecision: 'any', space: 'preserve' }); |
| 145 | + it("[match]lastPrecision preserve space", () => { |
| 146 | + const result = match("汉语 拼音", "hanyu pini", { |
| 147 | + lastPrecision: "any", |
| 148 | + space: "preserve", |
| 149 | + }); |
141 | 150 | expect(result).to.deep.equal([0, 1, 2, 3, 4]);
|
142 | 151 | });
|
143 | 152 |
|
144 |
| - it('[match]precision preserve space', () => { |
145 |
| - const result = match('汉语 拼音', 'hanyu pini', { precision: 'any', space: 'preserve' }); |
| 153 | + it("[match]precision preserve space", () => { |
| 154 | + const result = match("汉语 拼音", "hanyu pini", { |
| 155 | + precision: "any", |
| 156 | + space: "preserve", |
| 157 | + }); |
146 | 158 | expect(result).to.deep.equal([0, 1, 2, 3, 4]);
|
147 | 159 | });
|
148 | 160 |
|
149 |
| - it('[match]precision not continuous', () => { |
150 |
| - const result = match('汉语 拼音', 'hanyu yin', { precision: 'any', space: 'preserve', continuous: true }); |
| 161 | + it("[match]precision not continuous", () => { |
| 162 | + const result = match("汉语 拼音", "hanyu yin", { |
| 163 | + precision: "any", |
| 164 | + space: "preserve", |
| 165 | + continuous: true, |
| 166 | + }); |
151 | 167 | expect(result).to.deep.equal(null);
|
152 | 168 | });
|
153 | 169 |
|
154 |
| - it('[match]precision continuous', () => { |
155 |
| - const result = match('汉语 拼音', 'hanyu pinyin', { precision: 'any', space: 'preserve', continuous: true }); |
| 170 | + it("[match]precision continuous", () => { |
| 171 | + const result = match("汉语 拼音", "hanyu pinyin", { |
| 172 | + precision: "any", |
| 173 | + space: "preserve", |
| 174 | + continuous: true, |
| 175 | + }); |
156 | 176 | expect(result).to.deep.equal([0, 1, 2, 3, 4]);
|
157 | 177 | });
|
158 | 178 |
|
159 |
| - it('[match]lastPrecision none', () => { |
| 179 | + it("[match]lastPrecision none", () => { |
160 | 180 | // @ts-ignore
|
161 |
| - const result = match('汉语拼音', 'hanyupini', { lastPrecision: 'none' }); |
| 181 | + const result = match("汉语拼音", "hanyupini", { lastPrecision: "none" }); |
162 | 182 | expect(result).to.deep.equal(null);
|
163 | 183 | });
|
164 | 184 |
|
165 |
| - it('[match]insensitive', () => { |
166 |
| - const result = match('汉语KK拼音', 'hanyukkpinyin'); |
| 185 | + it("[match]insensitive", () => { |
| 186 | + const result = match("汉语KK拼音", "hanyukkpinyin"); |
167 | 187 | expect(result).to.deep.equal([0, 1, 2, 3, 4, 5]);
|
168 | 188 |
|
169 |
| - const result1 = match('汉语KK拼音', 'hanyukkpinyin', { |
| 189 | + const result1 = match("汉语KK拼音", "hanyukkpinyin", { |
170 | 190 | insensitive: false,
|
171 | 191 | });
|
172 | 192 | expect(result1).to.deep.equal(null);
|
173 | 193 | });
|
| 194 | + |
| 195 | + it("[match]v", () => { |
| 196 | + const result = match("我是吕布", "woshilvbu", { v: true }); |
| 197 | + expect(result).to.deep.equal([0, 1, 2, 3]); |
| 198 | + }); |
174 | 199 | });
|
0 commit comments