scancscode 1.0.28 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CSCodeScanner.js +5 -4
- package/dist/LiteralCollector.js +2 -2
- package/jest.config.js +9 -0
- package/package.json +6 -3
- package/src/CSCodeScanner.ts +174 -150
- package/src/CSVUtils.ts +5 -1
- package/src/CSharpStringExtractor.ts +1069 -0
- package/src/CmdExecutor.ts +9 -1
- package/src/LiteralCollector.ts +74 -31
- package/src/TableScanner.ts +55 -31
- package/test/CSharpStringExtractor.test.ts +1029 -0
- package/test/GuildDonateDialog.cs +194 -0
- package/test/MainSutraDetailDialog.cs +362 -0
- package/test/TestConvert.test.ts +8 -0
- package/src/CodeSnippet.ts +0 -7
- package/src/TestConvert.test.ts +0 -6
- package/src/TestSlimCsv.test.ts +0 -6
- package/src/index.ts +0 -3
|
@@ -0,0 +1,1029 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { CSharpStringExtractor, CodeSnippet } from '../src/CSharpStringExtractor';
|
|
3
|
+
|
|
4
|
+
describe('CSharpStringExtractor', () => {
|
|
5
|
+
let extractor: CSharpStringExtractor;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
extractor = new CSharpStringExtractor();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('should extract plain strings', () => {
|
|
12
|
+
const code = 'Console.WriteLine("Hello, world!");';
|
|
13
|
+
const snippets = extractor.extractStrings(code);
|
|
14
|
+
|
|
15
|
+
expect(snippets.length).toBe(1);
|
|
16
|
+
expect(snippets[0].literals).toEqual(['Hello, world!']);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('should handle strings with .TR() already appended', () => {
|
|
20
|
+
const code = 'obj.prop = "Hello, world!".TR();';
|
|
21
|
+
const snippets = extractor.extractStrings(code);
|
|
22
|
+
|
|
23
|
+
expect(snippets.length).toBe(1);
|
|
24
|
+
expect(snippets[0].originalCode).toBe('obj.prop = "Hello, world!".TR();');
|
|
25
|
+
expect(snippets[0].convertedCode).toBe('obj.prop = "Hello, world!".TR();');
|
|
26
|
+
expect(snippets[0].isChanged).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should not add .TR() to function arguments', () => {
|
|
30
|
+
const code = 'CallFunc("Hello, world!");';
|
|
31
|
+
const snippets = extractor.extractStrings(code);
|
|
32
|
+
|
|
33
|
+
expect(snippets.length).toBe(1);
|
|
34
|
+
expect(snippets[0].convertedCode).toBe('CallFunc("Hello, world!");');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('should not add .TR() to regular property assignments', () => {
|
|
38
|
+
const code = 'obj.prop = "Hello, world!";';
|
|
39
|
+
const snippets = extractor.extractStrings(code);
|
|
40
|
+
|
|
41
|
+
expect(snippets.length).toBe(1);
|
|
42
|
+
expect(snippets[0].convertedCode).toBe('obj.prop = "Hello, world!";');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('should handle $"" string templates', () => {
|
|
46
|
+
const code = '$"Hello, {name}!";';
|
|
47
|
+
const snippets = extractor.extractStrings(code);
|
|
48
|
+
|
|
49
|
+
expect(snippets.length).toBe(1);
|
|
50
|
+
expect(snippets[0].literals).toContain('Hello, {0}!');
|
|
51
|
+
expect(snippets[0].convertedCode).toBe('Tr.Format("Hello, {0}!", name);');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('should handle $"" string templates in function calls', () => {
|
|
55
|
+
const code = 'CallFunc($"Hello, world: {obj.Func1()}");';
|
|
56
|
+
const snippets = extractor.extractStrings(code);
|
|
57
|
+
|
|
58
|
+
expect(snippets.length).toBe(1);
|
|
59
|
+
expect(snippets[0].convertedCode).toBe('CallFunc(Tr.Format("Hello, world: {0}", obj.Func1()));');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('should convert string.Format to Tr.Format', () => {
|
|
63
|
+
const code = 'string.Format("Hello, ", name, "!");';
|
|
64
|
+
const snippets = extractor.extractStrings(code);
|
|
65
|
+
|
|
66
|
+
expect(snippets.length).toBe(1);
|
|
67
|
+
expect(snippets[0].convertedCode).toBe('Tr.Format("Hello, ", name, "!");');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('should handle string.Format in .text assignments', () => {
|
|
71
|
+
const code = 'label.text = Tr.Format("pre", Func(), "sub") + other;';
|
|
72
|
+
const snippets = extractor.extractStrings(code);
|
|
73
|
+
|
|
74
|
+
expect(snippets.length).toBe(1);
|
|
75
|
+
expect(snippets[0].literals).toContain('pre');
|
|
76
|
+
expect(snippets[0].literals).toContain('sub');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('should handle string concatenation', () => {
|
|
80
|
+
const code = '"Hello, " + name + "!";';
|
|
81
|
+
const snippets = extractor.extractStrings(code);
|
|
82
|
+
|
|
83
|
+
expect(snippets.length).toBe(1);
|
|
84
|
+
expect(snippets[0].convertedCode).toBe('"Hello, ".TR() + name.TR() + "!".TR();');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('should handle .text = assignments with function calls', () => {
|
|
88
|
+
const code = 'label.text = Func();';
|
|
89
|
+
const snippets = extractor.extractStrings(code);
|
|
90
|
+
|
|
91
|
+
expect(snippets.length).toBe(1);
|
|
92
|
+
expect(snippets[0].convertedCode).toBe('label.text = Func().TR();');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('should handle .text = assignments with multiple function calls', () => {
|
|
96
|
+
const code = 'label.text = Func() + Func();';
|
|
97
|
+
const snippets = extractor.extractStrings(code);
|
|
98
|
+
|
|
99
|
+
expect(snippets.length).toBe(1);
|
|
100
|
+
expect(snippets[0].convertedCode).toBe('label.text = Func().TR() + Func().TR();');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('should handle .text = assignments with string templates', () => {
|
|
104
|
+
const code = 'label.text = $"pre{Func()}sub";';
|
|
105
|
+
const snippets = extractor.extractStrings(code);
|
|
106
|
+
|
|
107
|
+
expect(snippets.length).toBe(1);
|
|
108
|
+
expect(snippets[0].literals).toContain('pre{0}sub');
|
|
109
|
+
expect(snippets[0].convertedCode).toBe('label.text = Tr.Format("pre{0}sub", Func());');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('should handle .text = assignments with string.Format', () => {
|
|
113
|
+
const code = 'label.text = string.Format("pre{0:F2}{1}", Func(), "sub") + other;';
|
|
114
|
+
const snippets = extractor.extractStrings(code);
|
|
115
|
+
|
|
116
|
+
expect(snippets.length).toBe(1);
|
|
117
|
+
expect(snippets[0].literals).toContain('pre{0:F2}{1}');
|
|
118
|
+
expect(snippets[0].literals).toContain('sub');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('should handle complex concatenation with existing .TR() calls', () => {
|
|
122
|
+
const code = '"Hello, ".TR() + name.TR() + obj2.name.TR() + obj2.nam1_e.Fn1().Prop + "!";';
|
|
123
|
+
const snippets = extractor.extractStrings(code);
|
|
124
|
+
|
|
125
|
+
expect(snippets.length).toBe(1);
|
|
126
|
+
expect(snippets[0].convertedCode).toBe('"Hello, ".TR() + name.TR() + obj2.name.TR() + obj2.nam1_e.Fn1().Prop.TR() + "!".TR();');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('should handle escaped quotes in strings', () => {
|
|
130
|
+
const code = 'Debug.Log("aaa\\\"bbb\\\"c\\\"d\\\\\"cc");';
|
|
131
|
+
const snippets = extractor.extractStrings(code);
|
|
132
|
+
|
|
133
|
+
expect(snippets.length).toBe(1);
|
|
134
|
+
// 由于JavaScript字符串转义的复杂性,我们只检查是否提取了字符串
|
|
135
|
+
expect(snippets[0].literals.length).toBeGreaterThan(0);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('should capture statement boundaries correctly', () => {
|
|
139
|
+
const code = 'obj.text = "Test property" + "Test property2";';
|
|
140
|
+
const snippets = extractor.extractStrings(code);
|
|
141
|
+
|
|
142
|
+
expect(snippets.length).toBe(1);
|
|
143
|
+
expect(snippets[0].originalCode).toBe('obj.text = "Test property" + "Test property2";');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('should handle multiple statements', () => {
|
|
147
|
+
const code = 'obj1.text = "Hello"; obj2.text = "World";';
|
|
148
|
+
const snippets = extractor.extractStrings(code);
|
|
149
|
+
|
|
150
|
+
expect(snippets.length).toBe(2);
|
|
151
|
+
expect(snippets[0].originalCode).toBe('obj1.text = "Hello";');
|
|
152
|
+
expect(snippets[1].originalCode).toBe('obj2.text = "World";');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('should extract and convert string templates', () => {
|
|
156
|
+
const code = 'Ljk.Ilk($"Hello, {name}!");';
|
|
157
|
+
const snippets = extractor.extractStrings(code);
|
|
158
|
+
|
|
159
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
160
|
+
const snippet = snippets[0];
|
|
161
|
+
expect(snippet.originalCode).toBe('Ljk.Ilk($"Hello, {name}!");');
|
|
162
|
+
expect(snippet.convertedCode).toBe('Ljk.Ilk(Tr.Format("Hello, {0}!", name));');
|
|
163
|
+
expect(snippet.literals).toEqual(['Hello, {0}!']);
|
|
164
|
+
expect(snippet.isChanged).toBe(true);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('should convert string.Format to Tr.Format', () => {
|
|
168
|
+
const code = 'string.Format("Hello, {0}!", name);';
|
|
169
|
+
const snippets = extractor.extractStrings(code);
|
|
170
|
+
|
|
171
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
172
|
+
const snippet = snippets[0];
|
|
173
|
+
expect(snippet.originalCode).toBe('string.Format("Hello, {0}!", name);');
|
|
174
|
+
expect(snippet.convertedCode).toBe('Tr.Format("Hello, {0}!", name);');
|
|
175
|
+
expect(snippet.literals).toEqual(['Hello, {0}!']);
|
|
176
|
+
expect(snippet.isChanged).toBe(true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('should handle .text = assignments', () => {
|
|
180
|
+
const code = 'label.text = "Test";';
|
|
181
|
+
const snippets = extractor.extractStrings(code);
|
|
182
|
+
|
|
183
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
184
|
+
const snippet = snippets[0];
|
|
185
|
+
expect(snippet.originalCode).toBe('label.text = "Test";');
|
|
186
|
+
expect(snippet.convertedCode).toBe('label.text = "Test".TR();');
|
|
187
|
+
expect(snippet.literals).toEqual(['Test']);
|
|
188
|
+
expect(snippet.isChanged).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('should handle string concatenations', () => {
|
|
192
|
+
const code = '"Hello, " + name + "!";';
|
|
193
|
+
const snippets = extractor.extractStrings(code);
|
|
194
|
+
|
|
195
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
196
|
+
const snippet = snippets[0];
|
|
197
|
+
expect(snippet.originalCode).toBe('"Hello, " + name + "!";');
|
|
198
|
+
expect(snippet.convertedCode).toBe('"Hello, ".TR() + name.TR() + "!".TR();');
|
|
199
|
+
expect(snippet.literals).toEqual(['Hello, ', '!']);
|
|
200
|
+
expect(snippet.isChanged).toBe(true);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('should not add .TR() to strings already having it', () => {
|
|
204
|
+
const code = '"Hello".TR();';
|
|
205
|
+
const snippets = extractor.extractStrings(code);
|
|
206
|
+
|
|
207
|
+
const snippet = snippets[0];
|
|
208
|
+
expect(snippet.originalCode).toBe('"Hello".TR();');
|
|
209
|
+
expect(snippet.convertedCode).toBe('"Hello".TR();');
|
|
210
|
+
expect(snippet.literals).toEqual(['Hello']);
|
|
211
|
+
expect(snippet.isChanged).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('should handle complex text assignments', () => {
|
|
215
|
+
const code = 'label.text = string.Format("pre{0}sub", Func()) + other;';
|
|
216
|
+
const snippets = extractor.extractStrings(code);
|
|
217
|
+
|
|
218
|
+
const snippet = snippets[0];
|
|
219
|
+
expect(snippet.originalCode).toBe('label.text = string.Format("pre{0}sub", Func()) + other;');
|
|
220
|
+
expect(snippet.convertedCode).toBe('label.text = Tr.Format("pre{0}sub", Func()) + other.TR();');
|
|
221
|
+
expect(snippet.literals).toEqual(['pre{0}sub']);
|
|
222
|
+
expect(snippet.isChanged).toBe(true);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('should handle escaped strings', () => {
|
|
226
|
+
const code = 'a.text = "aaa\\"bbb\\"c\\"d\\\\\\"cc";';
|
|
227
|
+
const snippets = extractor.extractStrings(code);
|
|
228
|
+
|
|
229
|
+
const snippet = snippets[0];
|
|
230
|
+
expect(snippet.originalCode).toBe('a.text = "aaa\\"bbb\\"c\\"d\\\\\\"cc";');
|
|
231
|
+
expect(snippet.convertedCode).toBe('a.text = "aaa\\"bbb\\"c\\"d\\\\\\"cc".TR();');
|
|
232
|
+
expect(snippet.literals).toEqual(['aaa\\"bbb\\"c\\"d\\\\\\"cc']);
|
|
233
|
+
expect(snippet.isChanged).toBe(true);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('should handle @$"" and $@"" formats', () => {
|
|
237
|
+
const code = 'Fcx.Kjl(@$"Hello, {name}!");';
|
|
238
|
+
const snippets = extractor.extractStrings(code);
|
|
239
|
+
|
|
240
|
+
const snippet = snippets[0];
|
|
241
|
+
expect(snippet.originalCode).toBe('Fcx.Kjl(@$"Hello, {name}!");');
|
|
242
|
+
expect(snippet.convertedCode).toBe('Fcx.Kjl(Tr.Format("Hello, {0}!", name));');
|
|
243
|
+
expect(snippet.literals).toEqual(['Hello, {0}!']);
|
|
244
|
+
expect(snippet.isChanged).toBe(true);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('should handle function calls with string arguments', () => {
|
|
248
|
+
const code = 'CallFunc("Hello", "World");';
|
|
249
|
+
const snippets = extractor.extractStrings(code);
|
|
250
|
+
|
|
251
|
+
const snippet = snippets[0];
|
|
252
|
+
expect(snippet.originalCode).toBe('CallFunc("Hello", "World");');
|
|
253
|
+
expect(snippet.convertedCode).toBe('CallFunc("Hello", "World");');
|
|
254
|
+
expect(snippet.literals).toEqual(['Hello', 'World']);
|
|
255
|
+
expect(snippet.isChanged).toBe(false);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test('should handle .text = with Tr.Format', () => {
|
|
259
|
+
const code = 'label.text = Tr.Format("pre", Func(), "sub") + other;';
|
|
260
|
+
const snippets = extractor.extractStrings(code);
|
|
261
|
+
|
|
262
|
+
const snippet = snippets[0];
|
|
263
|
+
expect(snippet.originalCode).toBe('label.text = Tr.Format("pre", Func(), "sub") + other;');
|
|
264
|
+
expect(snippet.convertedCode).toBe('label.text = Tr.Format("pre", Func(), "sub") + other.TR();');
|
|
265
|
+
expect(snippet.literals).toEqual(['pre', 'sub']);
|
|
266
|
+
expect(snippet.isChanged).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('should handle .text = with Tr.Format 2', () => {
|
|
270
|
+
const code = 'm_text_lastAward.text = $"[color=#FFFFFF]上期奖励:[/color][color=#FFE97E][/color][color=#FFFFFF]暂无获奖[/color]";';
|
|
271
|
+
const snippets = extractor.extractStrings(code);
|
|
272
|
+
|
|
273
|
+
const snippet = snippets[0];
|
|
274
|
+
expect(snippet.originalCode).toBe('m_text_lastAward.text = $"[color=#FFFFFF]上期奖励:[/color][color=#FFE97E][/color][color=#FFFFFF]暂无获奖[/color]";');
|
|
275
|
+
expect(snippet.convertedCode).toBe('m_text_lastAward.text = $"[color=#FFFFFF]上期奖励:[/color][color=#FFE97E][/color][color=#FFFFFF]暂无获奖[/color]";');
|
|
276
|
+
expect(snippet.literals).toEqual(['[color=#FFFFFF]上期奖励:[/color][color=#FFE97E][/color][color=#FFFFFF]暂无获奖[/color]']);
|
|
277
|
+
expect(snippet.isChanged).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('should handle non string assignment 1', () => {
|
|
281
|
+
const code = 'var d1 = 12;var d2 = 13;var d3 = d1 + d2;var aa = "aaa";';
|
|
282
|
+
const snippets = extractor.extractStrings(code);
|
|
283
|
+
{
|
|
284
|
+
const snippet = snippets[0];
|
|
285
|
+
expect(snippet.originalCode).toBe('var aa = "aaa";');
|
|
286
|
+
expect(snippet.convertedCode).toBe('var aa = "aaa";');
|
|
287
|
+
expect(snippet.literals).toEqual(['aaa']);
|
|
288
|
+
expect(snippet.isChanged).toBe(false);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('should handle non string assignment 2', () => {
|
|
293
|
+
const code = 'var d3 = d1 + d2;var aa = "aaa";';
|
|
294
|
+
const snippets = extractor.extractStrings(code);
|
|
295
|
+
{
|
|
296
|
+
const snippet = snippets[0];
|
|
297
|
+
expect(snippet.originalCode).toBe('var aa = "aaa";');
|
|
298
|
+
expect(snippet.convertedCode).toBe('var aa = "aaa";');
|
|
299
|
+
expect(snippet.literals).toEqual(['aaa']);
|
|
300
|
+
expect(snippet.isChanged).toBe(false);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test('should handle multilne content1', () => {
|
|
305
|
+
const code = 'var aa = "aaa";\nvar bb = "bbb";\nvar cc = "ccc";';
|
|
306
|
+
const snippets = extractor.extractStrings(code);
|
|
307
|
+
{
|
|
308
|
+
const snippet = snippets[0];
|
|
309
|
+
expect(snippet.originalCode).toBe('var aa = "aaa";');
|
|
310
|
+
expect(snippet.convertedCode).toBe('var aa = "aaa";');
|
|
311
|
+
expect(snippet.literals).toEqual(['aaa']);
|
|
312
|
+
expect(snippet.isChanged).toBe(false);
|
|
313
|
+
}
|
|
314
|
+
{
|
|
315
|
+
const snippet = snippets[1];
|
|
316
|
+
expect(snippet.originalCode).toBe('var bb = "bbb";');
|
|
317
|
+
expect(snippet.convertedCode).toBe('var bb = "bbb";');
|
|
318
|
+
expect(snippet.literals).toEqual(['bbb']);
|
|
319
|
+
expect(snippet.isChanged).toBe(false);
|
|
320
|
+
}
|
|
321
|
+
{
|
|
322
|
+
const snippet = snippets[2];
|
|
323
|
+
expect(snippet.originalCode).toBe('var cc = "ccc";');
|
|
324
|
+
expect(snippet.convertedCode).toBe('var cc = "ccc";');
|
|
325
|
+
expect(snippet.literals).toEqual(['ccc']);
|
|
326
|
+
expect(snippet.isChanged).toBe(false);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test('should handle multilne content2', () => {
|
|
331
|
+
const code = 'var d1 = 12;var d2 = 13;var d3 = d1 + d2;var aa = "aaa";\nvar bb = "bbb";\nvar dd = aa + bb;\nvar hh = aa + bb + "hhh";\ncc.text = "ccc" + aa + bb;var ii = "iii";jj.text = "jjj";CallFunc("jjj");CallFunc2("jjj", "kkk");jj.text = "jjj" + ll;';
|
|
332
|
+
const snippets = extractor.extractStrings(code);
|
|
333
|
+
{
|
|
334
|
+
const snippet = snippets[0];
|
|
335
|
+
expect(snippet.originalCode).toBe('var aa = "aaa";');
|
|
336
|
+
expect(snippet.convertedCode).toBe('var aa = "aaa";');
|
|
337
|
+
expect(snippet.literals).toEqual(['aaa']);
|
|
338
|
+
expect(snippet.isChanged).toBe(false);
|
|
339
|
+
}
|
|
340
|
+
{
|
|
341
|
+
const snippet = snippets[1];
|
|
342
|
+
expect(snippet.originalCode).toBe('var bb = "bbb";');
|
|
343
|
+
expect(snippet.convertedCode).toBe('var bb = "bbb";');
|
|
344
|
+
expect(snippet.literals).toEqual(['bbb']);
|
|
345
|
+
expect(snippet.isChanged).toBe(false);
|
|
346
|
+
}
|
|
347
|
+
{
|
|
348
|
+
const snippet = snippets[2];
|
|
349
|
+
expect(snippet.originalCode).toBe('var hh = aa + bb + "hhh";');
|
|
350
|
+
expect(snippet.convertedCode).toBe('var hh = aa.TR() + bb.TR() + "hhh".TR();');
|
|
351
|
+
expect(snippet.literals).toEqual(['hhh']);
|
|
352
|
+
expect(snippet.isChanged).toBe(true);
|
|
353
|
+
}
|
|
354
|
+
{
|
|
355
|
+
const snippet = snippets[3];
|
|
356
|
+
expect(snippet.originalCode).toBe('cc.text = "ccc" + aa + bb;');
|
|
357
|
+
expect(snippet.convertedCode).toBe('cc.text = "ccc".TR() + aa.TR() + bb.TR();');
|
|
358
|
+
expect(snippet.literals).toEqual(['ccc']);
|
|
359
|
+
expect(snippet.isChanged).toBe(true);
|
|
360
|
+
}
|
|
361
|
+
{
|
|
362
|
+
const snippet = snippets[4];
|
|
363
|
+
expect(snippet.originalCode).toBe('var ii = "iii";');
|
|
364
|
+
expect(snippet.convertedCode).toBe('var ii = "iii";');
|
|
365
|
+
expect(snippet.literals).toEqual(['iii']);
|
|
366
|
+
expect(snippet.isChanged).toBe(false);
|
|
367
|
+
}
|
|
368
|
+
{
|
|
369
|
+
const snippet = snippets[5];
|
|
370
|
+
expect(snippet.originalCode).toBe('jj.text = "jjj";');
|
|
371
|
+
expect(snippet.convertedCode).toBe('jj.text = "jjj".TR();');
|
|
372
|
+
expect(snippet.literals).toEqual(['jjj']);
|
|
373
|
+
expect(snippet.isChanged).toBe(true);
|
|
374
|
+
}
|
|
375
|
+
{
|
|
376
|
+
const snippet = snippets[6];
|
|
377
|
+
expect(snippet.originalCode).toBe('CallFunc("jjj");');
|
|
378
|
+
expect(snippet.convertedCode).toBe('CallFunc("jjj");');
|
|
379
|
+
expect(snippet.literals).toEqual(['jjj']);
|
|
380
|
+
expect(snippet.isChanged).toBe(false);
|
|
381
|
+
}
|
|
382
|
+
{
|
|
383
|
+
const snippet = snippets[7];
|
|
384
|
+
expect(snippet.originalCode).toBe('CallFunc2("jjj", "kkk");');
|
|
385
|
+
expect(snippet.convertedCode).toBe('CallFunc2("jjj", "kkk");');
|
|
386
|
+
expect(snippet.literals).toEqual(['jjj', 'kkk']);
|
|
387
|
+
expect(snippet.isChanged).toBe(false);
|
|
388
|
+
}
|
|
389
|
+
{
|
|
390
|
+
const snippet = snippets[8];
|
|
391
|
+
expect(snippet.originalCode).toBe('jj.text = "jjj" + ll;');
|
|
392
|
+
expect(snippet.convertedCode).toBe('jj.text = "jjj".TR() + ll.TR();');
|
|
393
|
+
expect(snippet.literals).toEqual(['jjj']);
|
|
394
|
+
expect(snippet.isChanged).toBe(true);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test('should handle multilne content3', () => {
|
|
399
|
+
const code = 'label.text = Tr.Format("pre", Func(), "sub") + other;\nlabel2.text = Tr.Format("pre2", Func(), "sub2") + other2;';
|
|
400
|
+
const snippets = extractor.extractStrings(code);
|
|
401
|
+
{
|
|
402
|
+
const snippet = snippets[0];
|
|
403
|
+
expect(snippet.originalCode).toBe('label.text = Tr.Format("pre", Func(), "sub") + other;');
|
|
404
|
+
expect(snippet.convertedCode).toBe('label.text = Tr.Format("pre", Func(), "sub") + other.TR();');
|
|
405
|
+
expect(snippet.literals).toEqual(['pre', 'sub']);
|
|
406
|
+
expect(snippet.isChanged).toBe(true);
|
|
407
|
+
}
|
|
408
|
+
{
|
|
409
|
+
const snippet = snippets[1];
|
|
410
|
+
expect(snippet.originalCode).toBe('label2.text = Tr.Format("pre2", Func(), "sub2") + other2;');
|
|
411
|
+
expect(snippet.convertedCode).toBe('label2.text = Tr.Format("pre2", Func(), "sub2") + other2.TR();');
|
|
412
|
+
expect(snippet.literals).toEqual(['pre2', 'sub2']);
|
|
413
|
+
expect(snippet.isChanged).toBe(true);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test('should handle multilne content4', () => {
|
|
418
|
+
const code = 'label.text =\n Tr.Format(\n\t"pre", Func(),\n\t\t "sub") + other;';
|
|
419
|
+
const snippets = extractor.extractStrings(code);
|
|
420
|
+
{
|
|
421
|
+
const snippet = snippets[0];
|
|
422
|
+
expect(snippet.originalCode).toBe('label.text =\n Tr.Format(\n\t"pre", Func(),\n\t\t "sub") + other;');
|
|
423
|
+
expect(snippet.convertedCode).toBe('label.text =\n Tr.Format(\n\t"pre", Func(),\n\t\t "sub") + other.TR();');
|
|
424
|
+
expect(snippet.literals).toEqual(['pre', 'sub']);
|
|
425
|
+
expect(snippet.isChanged).toBe(true);
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
test('should handle multilne content5', () => {
|
|
430
|
+
const code = `
|
|
431
|
+
//注释不需要包含在捕获部分里
|
|
432
|
+
m_text_name.text = cardTable.Name;
|
|
433
|
+
`;
|
|
434
|
+
const snippets = extractor.extractStrings(code);
|
|
435
|
+
{
|
|
436
|
+
const snippet = snippets[0];
|
|
437
|
+
expect(snippet.originalCode).toBe('m_text_name.text = cardTable.Name;');
|
|
438
|
+
expect(snippet.convertedCode).toBe('m_text_name.text = cardTable.Name.TR();');
|
|
439
|
+
expect(snippet.literals).toEqual([]);
|
|
440
|
+
expect(snippet.isChanged).toBe(true);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test('should handle multilne content6', () => {
|
|
445
|
+
const code = `
|
|
446
|
+
if (condition)
|
|
447
|
+
{
|
|
448
|
+
Toast.Info("卸载成功");
|
|
449
|
+
}
|
|
450
|
+
`;
|
|
451
|
+
const snippets = extractor.extractStrings(code);
|
|
452
|
+
{
|
|
453
|
+
const snippet = snippets[0];
|
|
454
|
+
expect(snippet.originalCode).toBe('Toast.Info("卸载成功");');
|
|
455
|
+
expect(snippet.convertedCode).toBe('Toast.Info("卸载成功");');
|
|
456
|
+
expect(snippet.literals).toEqual(['卸载成功']);
|
|
457
|
+
expect(snippet.originalIndex).toBe(code.indexOf('Toast.Info("卸载成功");'));
|
|
458
|
+
expect(snippet.isChanged).toBe(false);
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
test('should handle multilne content7', () => {
|
|
463
|
+
const code = `
|
|
464
|
+
while (condition)
|
|
465
|
+
{
|
|
466
|
+
TT1.Fn1("卸载成功");
|
|
467
|
+
}
|
|
468
|
+
`;
|
|
469
|
+
const snippets = extractor.extractStrings(code);
|
|
470
|
+
{
|
|
471
|
+
const snippet = snippets[0];
|
|
472
|
+
expect(snippet.originalCode).toBe('TT1.Fn1("卸载成功");');
|
|
473
|
+
expect(snippet.convertedCode).toBe('TT1.Fn1("卸载成功");');
|
|
474
|
+
expect(snippet.literals).toEqual(['卸载成功']);
|
|
475
|
+
expect(snippet.originalIndex).toBe(code.indexOf('TT1.Fn1("卸载成功");'));
|
|
476
|
+
expect(snippet.isChanged).toBe(false);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
test('should handle multilne content8', () => {
|
|
481
|
+
const code = `
|
|
482
|
+
for (scope;condition;continuex)
|
|
483
|
+
{
|
|
484
|
+
QR2.Fn2("卸载成功");
|
|
485
|
+
}
|
|
486
|
+
`;
|
|
487
|
+
const snippets = extractor.extractStrings(code);
|
|
488
|
+
{
|
|
489
|
+
const snippet = snippets[0];
|
|
490
|
+
expect(snippet.originalCode).toBe('QR2.Fn2("卸载成功");');
|
|
491
|
+
expect(snippet.convertedCode).toBe('QR2.Fn2("卸载成功");');
|
|
492
|
+
expect(snippet.literals).toEqual(['卸载成功']);
|
|
493
|
+
expect(snippet.isChanged).toBe(false);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
test('should handle multilne content9', () => {
|
|
498
|
+
const code = `
|
|
499
|
+
{
|
|
500
|
+
KK3.Ca3("卸载成功");
|
|
501
|
+
}
|
|
502
|
+
`;
|
|
503
|
+
const snippets = extractor.extractStrings(code);
|
|
504
|
+
{
|
|
505
|
+
const snippet = snippets[0];
|
|
506
|
+
expect(snippet.originalCode).toBe('KK3.Ca3("卸载成功");');
|
|
507
|
+
expect(snippet.convertedCode).toBe('KK3.Ca3("卸载成功");');
|
|
508
|
+
expect(snippet.literals).toEqual(['卸载成功']);
|
|
509
|
+
expect(snippet.isChanged).toBe(false);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
test('should handle multilne content10', () => {
|
|
514
|
+
const code = `
|
|
515
|
+
var lambda1 = () => {
|
|
516
|
+
LJN4.Fn4("卸载成功");
|
|
517
|
+
};
|
|
518
|
+
`;
|
|
519
|
+
const snippets = extractor.extractStrings(code);
|
|
520
|
+
{
|
|
521
|
+
const snippet = snippets[0];
|
|
522
|
+
expect(snippet.originalCode).toBe('LJN4.Fn4("卸载成功");');
|
|
523
|
+
expect(snippet.convertedCode).toBe('LJN4.Fn4("卸载成功");');
|
|
524
|
+
expect(snippet.literals).toEqual(['卸载成功']);
|
|
525
|
+
expect(snippet.isChanged).toBe(false);
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
test('should handle multilne content11', () => {
|
|
530
|
+
const code = `
|
|
531
|
+
void lambda1() {
|
|
532
|
+
KK5.Call5("卸载成功");
|
|
533
|
+
}
|
|
534
|
+
`;
|
|
535
|
+
const snippets = extractor.extractStrings(code);
|
|
536
|
+
{
|
|
537
|
+
const snippet = snippets[0];
|
|
538
|
+
expect(snippet.originalCode).toBe('KK5.Call5("卸载成功");');
|
|
539
|
+
expect(snippet.convertedCode).toBe('KK5.Call5("卸载成功");');
|
|
540
|
+
expect(snippet.literals).toEqual(['卸载成功']);
|
|
541
|
+
expect(snippet.isChanged).toBe(false);
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
test('should handle multilne content12', () => {
|
|
546
|
+
const code = `
|
|
547
|
+
//星级
|
|
548
|
+
m_list_star.RemoveChildrenToPool();
|
|
549
|
+
for (int i = 0; i < _sutraCardData.LevelStar; i++)
|
|
550
|
+
{
|
|
551
|
+
var item = m_list_star.AddItemFromPool() as ItemSutraStarSComp;
|
|
552
|
+
if (item == null) continue;
|
|
553
|
+
item.SetSutraStar(_sutraCardData.Level);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
m_text_quality.text = Tr.Format("{0}阶", _sutraCardData.Quality);
|
|
557
|
+
|
|
558
|
+
//设置通玄值
|
|
559
|
+
m_text_tongXuan.text = "通玄:".TR() + (_sutraCardData.InheritAtkPercent / 100).ToString("0.0") + "%".TR();
|
|
560
|
+
|
|
561
|
+
`;
|
|
562
|
+
const snippets = extractor.extractStrings(code);
|
|
563
|
+
{
|
|
564
|
+
const snippet = snippets[0];
|
|
565
|
+
expect(snippet.originalCode).toBe('m_text_quality.text = Tr.Format("{0}阶", _sutraCardData.Quality);');
|
|
566
|
+
expect(snippet.convertedCode).toBe('m_text_quality.text = Tr.Format("{0}阶", _sutraCardData.Quality);');
|
|
567
|
+
expect(snippet.literals).toEqual(['{0}阶']);
|
|
568
|
+
expect(snippet.isChanged).toBe(false);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
test('should handle multilne content13', () => {
|
|
572
|
+
const code = `
|
|
573
|
+
Toast.Info("卸载成功");
|
|
574
|
+
Toast.Info("卸载成功");
|
|
575
|
+
`;
|
|
576
|
+
const snippets = extractor.extractStrings(code);
|
|
577
|
+
{
|
|
578
|
+
const snippet = snippets[0];
|
|
579
|
+
expect(snippet.originalIndex).toBe(code.indexOf('Toast.Info("卸载成功");'));
|
|
580
|
+
expect(snippet.originalCode).toBe('Toast.Info("卸载成功");');
|
|
581
|
+
expect(snippet.convertedCode).toBe('Toast.Info("卸载成功");');
|
|
582
|
+
expect(snippet.literals).toEqual(['卸载成功']);
|
|
583
|
+
expect(snippet.isChanged).toBe(false);
|
|
584
|
+
}
|
|
585
|
+
{
|
|
586
|
+
const snippet = snippets[1];
|
|
587
|
+
expect(snippet.originalIndex).toBe(code.indexOf('Toast.Info("卸载成功");', snippets[0].originalIndex + 1));
|
|
588
|
+
expect(snippet.originalCode).toBe('Toast.Info("卸载成功");');
|
|
589
|
+
expect(snippet.convertedCode).toBe('Toast.Info("卸载成功");');
|
|
590
|
+
expect(snippet.literals).toEqual(['卸载成功']);
|
|
591
|
+
expect(snippet.isChanged).toBe(false);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
test('should handle multilne content14', () => {
|
|
596
|
+
const code = readFileSync('./test/MainSutraDetailDialog.cs', 'utf8');
|
|
597
|
+
const snippets = extractor.extractStrings(code);
|
|
598
|
+
|
|
599
|
+
// 验证提取的片段数量
|
|
600
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
601
|
+
|
|
602
|
+
// 针对每个snippet展开对每个属性值的断言
|
|
603
|
+
|
|
604
|
+
// Snippet 1
|
|
605
|
+
expect(snippets[0].originalIndex).toBe(2807);
|
|
606
|
+
expect(snippets[0].originalCode).toBe('m_text_name.text = cardTable.Name.TR();');
|
|
607
|
+
expect(snippets[0].convertedCode).toBe('m_text_name.text = cardTable.Name.TR();');
|
|
608
|
+
expect(snippets[0].literals).toEqual([]);
|
|
609
|
+
expect(snippets[0].isChanged).toBe(false);
|
|
610
|
+
|
|
611
|
+
// Snippet 2
|
|
612
|
+
expect(snippets[1].originalIndex).toBe(3550);
|
|
613
|
+
expect(snippets[1].originalCode).toBe('m_text_potrem1.text = sutraConfig.Poetry[0].TR();');
|
|
614
|
+
expect(snippets[1].convertedCode).toBe('m_text_potrem1.text = sutraConfig.Poetry[0].TR();');
|
|
615
|
+
expect(snippets[1].literals).toEqual([]);
|
|
616
|
+
expect(snippets[1].isChanged).toBe(false);
|
|
617
|
+
|
|
618
|
+
// Snippet 3
|
|
619
|
+
expect(snippets[2].originalIndex).toBe(3612);
|
|
620
|
+
expect(snippets[2].originalCode).toBe('m_text_potrem2.text = sutraConfig.Poetry[1].TR();');
|
|
621
|
+
expect(snippets[2].convertedCode).toBe('m_text_potrem2.text = sutraConfig.Poetry[1].TR();');
|
|
622
|
+
expect(snippets[2].literals).toEqual([]);
|
|
623
|
+
expect(snippets[2].isChanged).toBe(false);
|
|
624
|
+
|
|
625
|
+
// Snippet 4
|
|
626
|
+
expect(snippets[3].originalIndex).toBe(3912);
|
|
627
|
+
expect(snippets[3].originalCode).toBe('m_text_atkAdd.text = (_sutraCardData.AttackUp() / 100).ToString("0.0") + "%".TR();');
|
|
628
|
+
expect(snippets[3].convertedCode).toBe('m_text_atkAdd.text = (_sutraCardData.AttackUp() / 100).ToString("0.0").TR() + "%".TR();');
|
|
629
|
+
expect(snippets[3].literals).toEqual(['0.0', '%']);
|
|
630
|
+
expect(snippets[3].isChanged).toBe(true);
|
|
631
|
+
|
|
632
|
+
// Snippet 5
|
|
633
|
+
expect(snippets[4].originalIndex).toBe(4007);
|
|
634
|
+
expect(snippets[4].originalCode).toBe('m_text_hpAdd.text = (_sutraCardData.HpUp() / 100).ToString("0.0") + "%".TR();');
|
|
635
|
+
expect(snippets[4].convertedCode).toBe('m_text_hpAdd.text = (_sutraCardData.HpUp() / 100).ToString("0.0").TR() + "%".TR();');
|
|
636
|
+
expect(snippets[4].literals).toEqual(['0.0', '%']);
|
|
637
|
+
expect(snippets[4].isChanged).toBe(true);
|
|
638
|
+
|
|
639
|
+
// Snippet 6
|
|
640
|
+
expect(snippets[5].originalIndex).toBe(4187);
|
|
641
|
+
expect(snippets[5].originalCode).toBe('m_text_skillName.text = skillConfig.Name.TR();');
|
|
642
|
+
expect(snippets[5].convertedCode).toBe('m_text_skillName.text = skillConfig.Name.TR();');
|
|
643
|
+
expect(snippets[5].literals).toEqual([]);
|
|
644
|
+
expect(snippets[5].isChanged).toBe(false);
|
|
645
|
+
|
|
646
|
+
// Snippet 7
|
|
647
|
+
expect(snippets[6].originalIndex).toBe(4324);
|
|
648
|
+
expect(snippets[6].originalCode).toBe('m_text_skill.text = passiveSkillConfig != null ? passiveSkillConfig.Description.TR() : "被动技能未解锁".TR();');
|
|
649
|
+
expect(snippets[6].convertedCode).toBe('m_text_skill.text = passiveSkillConfig != null ? passiveSkillConfig.Description.TR() : "被动技能未解锁".TR();');
|
|
650
|
+
expect(snippets[6].literals).toEqual(['被动技能未解锁']);
|
|
651
|
+
expect(snippets[6].isChanged).toBe(false);
|
|
652
|
+
|
|
653
|
+
// Snippet 8
|
|
654
|
+
expect(snippets[7].originalIndex).toBe(4505);
|
|
655
|
+
expect(snippets[7].originalCode).toBe('m_effect_skillUnlock.ShowEffect("Effect_FaBao_Unlock");');
|
|
656
|
+
expect(snippets[7].convertedCode).toBe('m_effect_skillUnlock.ShowEffect("Effect_FaBao_Unlock");');
|
|
657
|
+
expect(snippets[7].literals).toEqual(['Effect_FaBao_Unlock']);
|
|
658
|
+
expect(snippets[7].isChanged).toBe(false);
|
|
659
|
+
|
|
660
|
+
// Snippet 9
|
|
661
|
+
expect(snippets[8].originalIndex).toBe(4952);
|
|
662
|
+
expect(snippets[8].originalCode).toBe('m_text_quality.text = Tr.Format("{0}阶", _sutraCardData.Quality);');
|
|
663
|
+
expect(snippets[8].convertedCode).toBe('m_text_quality.text = Tr.Format("{0}阶", _sutraCardData.Quality);');
|
|
664
|
+
expect(snippets[8].literals).toEqual(['{0}阶']);
|
|
665
|
+
expect(snippets[8].isChanged).toBe(false);
|
|
666
|
+
|
|
667
|
+
// Snippet 10
|
|
668
|
+
expect(snippets[9].originalIndex).toBe(5050);
|
|
669
|
+
expect(snippets[9].originalCode).toBe('m_text_tongXuan.text = "通玄:".TR() + (_sutraCardData.InheritAtkPercent / 100).ToString("0.0") + "%".TR();');
|
|
670
|
+
expect(snippets[9].convertedCode).toBe('m_text_tongXuan.text = "通玄:".TR() + (_sutraCardData.InheritAtkPercent / 100).ToString("0.0").TR() + "%".TR();');
|
|
671
|
+
expect(snippets[9].literals).toEqual(['通玄:', '0.0', '%']);
|
|
672
|
+
expect(snippets[9].isChanged).toBe(true);
|
|
673
|
+
|
|
674
|
+
// Snippet 11
|
|
675
|
+
expect(snippets[10].originalIndex).toBe(5943);
|
|
676
|
+
expect(snippets[10].originalCode).toBe(`m_text_cost.text = enough
|
|
677
|
+
? Tr.Format("[color=#1B8049]{0}/{1}[/color]", curCount, costCount)
|
|
678
|
+
: Tr.Format("[color=#E55E5A]{0}/{1}[/color]", curCount, costCount);`);
|
|
679
|
+
expect(snippets[10].convertedCode).toBe(`m_text_cost.text = enough
|
|
680
|
+
? Tr.Format("[color=#1B8049]{0}/{1}[/color]", curCount, costCount)
|
|
681
|
+
: Tr.Format("[color=#E55E5A]{0}/{1}[/color]", curCount, costCount);`);
|
|
682
|
+
expect(snippets[10].literals).toEqual(['[color=#1B8049]{0}/{1}[/color]', '[color=#E55E5A]{0}/{1}[/color]']);
|
|
683
|
+
expect(snippets[10].isChanged).toBe(false);
|
|
684
|
+
|
|
685
|
+
// Snippet 12
|
|
686
|
+
expect(snippets[11].originalIndex).toBe(6370);
|
|
687
|
+
expect(snippets[11].originalCode).toBe('m_text_upgradeTip.text = dependLockInfo.Item2.TR();');
|
|
688
|
+
expect(snippets[11].convertedCode).toBe('m_text_upgradeTip.text = dependLockInfo.Item2.TR();');
|
|
689
|
+
expect(snippets[11].literals).toEqual([]);
|
|
690
|
+
expect(snippets[11].isChanged).toBe(false);
|
|
691
|
+
|
|
692
|
+
// Snippet 13
|
|
693
|
+
expect(snippets[12].originalIndex).toBe(7951);
|
|
694
|
+
expect(snippets[12].originalCode).toBe('m_effect_fateUnlock.ShowEffect("Effect_FaBao_Unlock");');
|
|
695
|
+
expect(snippets[12].convertedCode).toBe('m_effect_fateUnlock.ShowEffect("Effect_FaBao_Unlock");');
|
|
696
|
+
expect(snippets[12].literals).toEqual(['Effect_FaBao_Unlock']);
|
|
697
|
+
expect(snippets[12].isChanged).toBe(false);
|
|
698
|
+
|
|
699
|
+
// Snippet 14
|
|
700
|
+
expect(snippets[13].originalIndex).toBe(8033);
|
|
701
|
+
expect(snippets[13].originalCode).toBe('#region 灵纹信息\n\n m_text_runeSlot.text = Tr.Format("({0}/6)", _sutraCardData.Card.RuneOpenCount);');
|
|
702
|
+
expect(snippets[13].convertedCode).toBe('#region 灵纹信息\n\n m_text_runeSlot.text = Tr.Format("({0}/6)", _sutraCardData.Card.RuneOpenCount);');
|
|
703
|
+
expect(snippets[13].literals).toEqual([]);
|
|
704
|
+
expect(snippets[13].isChanged).toBe(false);
|
|
705
|
+
|
|
706
|
+
// Snippet 15
|
|
707
|
+
expect(snippets[14].originalIndex).toBe(9680);
|
|
708
|
+
expect(snippets[14].originalCode).toBe('Log.Error($"Can not find tagId in sutra : {_sutraCardData.Card.Id}");');
|
|
709
|
+
expect(snippets[14].convertedCode).toBe('Log.Error(Tr.Format("Can not find tagId in sutra : {0}", _sutraCardData.Card.Id));');
|
|
710
|
+
expect(snippets[14].literals).toEqual(['Can not find tagId in sutra : {0}']);
|
|
711
|
+
expect(snippets[14].isChanged).toBe(true);
|
|
712
|
+
|
|
713
|
+
// Snippet 16
|
|
714
|
+
expect(snippets[15].originalIndex).toBe(11955);
|
|
715
|
+
expect(snippets[15].originalCode).toBe('Toast.Info("卸载成功");');
|
|
716
|
+
expect(snippets[15].convertedCode).toBe('Toast.Info("卸载成功");');
|
|
717
|
+
expect(snippets[15].literals).toEqual(['卸载成功']);
|
|
718
|
+
expect(snippets[15].isChanged).toBe(false);
|
|
719
|
+
|
|
720
|
+
// Snippet 17
|
|
721
|
+
expect(snippets[16].originalIndex).toBe(12549);
|
|
722
|
+
expect(snippets[16].originalCode).toBe('Toast.Info("卸载成功");');
|
|
723
|
+
expect(snippets[16].convertedCode).toBe('Toast.Info("卸载成功");');
|
|
724
|
+
expect(snippets[16].literals).toEqual(['卸载成功']);
|
|
725
|
+
expect(snippets[16].isChanged).toBe(false);
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
test('should handle multilne content15', () => {
|
|
729
|
+
const code = readFileSync('./test/GuildDonateDialog.cs', 'utf8');
|
|
730
|
+
const snippets = extractor.extractStrings(code);
|
|
731
|
+
|
|
732
|
+
// 验证提取的片段数量
|
|
733
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
734
|
+
|
|
735
|
+
// 针对每个snippet展开对每个属性值的断言
|
|
736
|
+
|
|
737
|
+
// 查找包含目标URL的snippet
|
|
738
|
+
const targetSnippet = snippets.find(snippet => snippet.originalCode.includes('ui://a0w66rlc7bhfusff'));
|
|
739
|
+
expect(targetSnippet).toBeDefined();
|
|
740
|
+
|
|
741
|
+
if (targetSnippet) {
|
|
742
|
+
expect(targetSnippet.originalIndex).toBe(2685);
|
|
743
|
+
expect(targetSnippet.originalCode).toBe(`m_btn_paid.text = $"<img src='ui://a0w66rlc7bhfusff'/ width = '70' height = '70'>{paidConfig.Quantity}";`);
|
|
744
|
+
expect(targetSnippet.convertedCode).toBe(`m_btn_paid.text = Tr.Format("<img src='ui://a0w66rlc7bhfusff'/ width = '70' height = '70'>{0}", paidConfig.Quantity);`);
|
|
745
|
+
expect(targetSnippet.literals).toEqual(["<img src='ui://a0w66rlc7bhfusff'/ width = '70' height = '70'>{0}"]);
|
|
746
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
test('should handle multilne content16', () => {
|
|
752
|
+
const code = `m_btn_paid.text = "//";`
|
|
753
|
+
const snippets = extractor.extractStrings(code);
|
|
754
|
+
|
|
755
|
+
// 验证提取的片段数量
|
|
756
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
757
|
+
|
|
758
|
+
let targetSnippet = snippets[0];
|
|
759
|
+
expect(targetSnippet.originalCode).toBe(`m_btn_paid.text = "//";`);
|
|
760
|
+
expect(targetSnippet.convertedCode).toBe(`m_btn_paid.text = "//".TR();`);
|
|
761
|
+
expect(targetSnippet.literals).toEqual(['//']);
|
|
762
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
763
|
+
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
test('should handle string template with format specifier', () => {
|
|
767
|
+
const code = `infoStr += $"最终抗性: {resistReduce:F}\\n";`
|
|
768
|
+
const snippets = extractor.extractStrings(code);
|
|
769
|
+
|
|
770
|
+
// 验证提取的片段数量
|
|
771
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
772
|
+
|
|
773
|
+
let targetSnippet = snippets[0];
|
|
774
|
+
expect(targetSnippet.originalCode).toBe(`infoStr += $"最终抗性: {resistReduce:F}\\n";`);
|
|
775
|
+
expect(targetSnippet.convertedCode).toBe(`infoStr += Tr.Format("最终抗性: {0:F}\\n", resistReduce);`);
|
|
776
|
+
expect(targetSnippet.literals).toEqual(['最终抗性: {0:F}\\n']);
|
|
777
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
test('should handle multilne content17', () => {
|
|
781
|
+
const code = `
|
|
782
|
+
infoStr += $"aaa: {aa}\n" +
|
|
783
|
+
$"bbb = {bb}";
|
|
784
|
+
`
|
|
785
|
+
const snippets = extractor.extractStrings(code);
|
|
786
|
+
|
|
787
|
+
// 验证提取的片段数量
|
|
788
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
789
|
+
|
|
790
|
+
let targetSnippet = snippets[0];
|
|
791
|
+
expect(targetSnippet.originalCode).toBe(`infoStr += $"aaa: {aa}\n" +
|
|
792
|
+
$"bbb = {bb}";`);
|
|
793
|
+
expect(targetSnippet.convertedCode).toBe(`infoStr += Tr.Format("aaa: {0}\n", aa) +
|
|
794
|
+
Tr.Format("bbb = {0}", bb);`);
|
|
795
|
+
expect(targetSnippet.literals).toEqual([
|
|
796
|
+
'aaa: {0}\n',
|
|
797
|
+
'bbb = {0}'
|
|
798
|
+
]);
|
|
799
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
test('should handle multilne content19', () => {
|
|
803
|
+
const code = `
|
|
804
|
+
infoStr += $"aaa: {aa}\\n" +
|
|
805
|
+
$"bbb = {bb}";
|
|
806
|
+
`
|
|
807
|
+
const snippets = extractor.extractStrings(code);
|
|
808
|
+
|
|
809
|
+
// 验证提取的片段数量
|
|
810
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
811
|
+
|
|
812
|
+
let targetSnippet = snippets[0];
|
|
813
|
+
expect(targetSnippet.originalCode).toBe(`infoStr += $"aaa: {aa}\\n" +
|
|
814
|
+
$"bbb = {bb}";`);
|
|
815
|
+
expect(targetSnippet.convertedCode).toBe(`infoStr += Tr.Format("aaa: {0}\\n", aa) +
|
|
816
|
+
Tr.Format("bbb = {0}", bb);`);
|
|
817
|
+
expect(targetSnippet.literals).toEqual([
|
|
818
|
+
'aaa: {0}\\n',
|
|
819
|
+
'bbb = {0}'
|
|
820
|
+
]);
|
|
821
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
test('should handle multilne content18', () => {
|
|
825
|
+
const code = `
|
|
826
|
+
infoStr += "伤害公式: \\n" +
|
|
827
|
+
$"最终伤害[color={colorCode}][{(float)damageValue:F}][/color] = \\n" +
|
|
828
|
+
$"基础伤害[b][{baseValue:F}][/b] X \\n" +
|
|
829
|
+
$"暴击伤害加成[b][{damageInfo.CritDamageRatio:F}][/b] X \\n" +
|
|
830
|
+
$"最终伤害加成[b][{1 + damageInfo.FinalDamageRatio:F}][/b] X \\n" +
|
|
831
|
+
$"最终承伤加成[b][{1 + damageInfo.FinalInjuryRatio:F}][/b] / \\n" +
|
|
832
|
+
$"最终伤害减免[b][{1 + damageInfo.FinalDamageReduce:F}][/b] X \\n" +
|
|
833
|
+
$"抗性减免[b][{resistReduce:F}]";
|
|
834
|
+
`
|
|
835
|
+
const snippets = extractor.extractStrings(code);
|
|
836
|
+
|
|
837
|
+
// 验证提取的片段数量
|
|
838
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
839
|
+
|
|
840
|
+
let targetSnippet = snippets[0];
|
|
841
|
+
expect(targetSnippet.originalCode).toBe(`infoStr += "伤害公式: \\n" +
|
|
842
|
+
$"最终伤害[color={colorCode}][{(float)damageValue:F}][/color] = \\n" +
|
|
843
|
+
$"基础伤害[b][{baseValue:F}][/b] X \\n" +
|
|
844
|
+
$"暴击伤害加成[b][{damageInfo.CritDamageRatio:F}][/b] X \\n" +
|
|
845
|
+
$"最终伤害加成[b][{1 + damageInfo.FinalDamageRatio:F}][/b] X \\n" +
|
|
846
|
+
$"最终承伤加成[b][{1 + damageInfo.FinalInjuryRatio:F}][/b] / \\n" +
|
|
847
|
+
$"最终伤害减免[b][{1 + damageInfo.FinalDamageReduce:F}][/b] X \\n" +
|
|
848
|
+
$"抗性减免[b][{resistReduce:F}]";`);
|
|
849
|
+
expect(targetSnippet.convertedCode).toBe(`infoStr += "伤害公式: \\n".TR() +
|
|
850
|
+
Tr.Format("最终伤害[color={0}][{1:F}][/color] = \\n", colorCode, (float)damageValue) +
|
|
851
|
+
Tr.Format("基础伤害[b][{0:F}][/b] X \\n", baseValue) +
|
|
852
|
+
Tr.Format("暴击伤害加成[b][{0:F}][/b] X \\n", damageInfo.CritDamageRatio) +
|
|
853
|
+
Tr.Format("最终伤害加成[b][{0:F}][/b] X \\n", 1 + damageInfo.FinalDamageRatio) +
|
|
854
|
+
Tr.Format("最终承伤加成[b][{0:F}][/b] / \\n", 1 + damageInfo.FinalInjuryRatio) +
|
|
855
|
+
Tr.Format("最终伤害减免[b][{0:F}][/b] X \\n", 1 + damageInfo.FinalDamageReduce) +
|
|
856
|
+
Tr.Format("抗性减免[b][{0:F}]", resistReduce);`);
|
|
857
|
+
expect(targetSnippet.literals).toEqual([
|
|
858
|
+
'伤害公式: \\n',
|
|
859
|
+
'最终伤害[color={0}][{1:F}][/color] = \\n',
|
|
860
|
+
'基础伤害[b][{2:F}][/b] X \\n',
|
|
861
|
+
'暴击伤害加成[b][{3:F}][/b] X \\n',
|
|
862
|
+
'最终伤害加成[b][{4:F}][/b] X \\n',
|
|
863
|
+
'最终承伤加成[b][{5:F}][/b] / \\n',
|
|
864
|
+
'最终伤害减免[b][{6:F}][/b] X \\n',
|
|
865
|
+
'抗性减免[b][{7:F}]'
|
|
866
|
+
]);
|
|
867
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
test('should handle lack bracket 1', () => {
|
|
871
|
+
const code = `m_text_time.text = $"下一轮神兽出现倒计时: {Date.GetIntweerpolatedTime(ServerTimer.Instance.Time, _startGameStamp)}";`
|
|
872
|
+
const snippets = extractor.extractStrings(code);
|
|
873
|
+
|
|
874
|
+
// 验证提取的片段数量
|
|
875
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
876
|
+
|
|
877
|
+
let targetSnippet = snippets[0];
|
|
878
|
+
expect(targetSnippet.originalCode).toBe(`m_text_time.text = $"下一轮神兽出现倒计时: {Date.GetIntweerpolatedTime(ServerTimer.Instance.Time, _startGameStamp)}";`);
|
|
879
|
+
expect(targetSnippet.convertedCode).toBe(`m_text_time.text = Tr.Format("下一轮神兽出现倒计时: {0}", Date.GetIntweerpolatedTime(ServerTimer.Instance.Time, _startGameStamp));`);
|
|
880
|
+
expect(targetSnippet.literals).toEqual([
|
|
881
|
+
'下一轮神兽出现倒计时: {0}'
|
|
882
|
+
]);
|
|
883
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
test('should handle lack bracket 2', () => {
|
|
887
|
+
const code = `m_text_time.text = $"神兽离去时间: {Date.FeGetInterpolatedTime(ServerTimer.Instance.Time, _endGameStamp)}";`
|
|
888
|
+
const snippets = extractor.extractStrings(code);
|
|
889
|
+
|
|
890
|
+
// 验证提取的片段数量
|
|
891
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
892
|
+
|
|
893
|
+
let targetSnippet = snippets[0];
|
|
894
|
+
expect(targetSnippet.originalCode).toBe(`m_text_time.text = $"神兽离去时间: {Date.FeGetInterpolatedTime(ServerTimer.Instance.Time, _endGameStamp)}";`);
|
|
895
|
+
expect(targetSnippet.convertedCode).toBe(`m_text_time.text = Tr.Format("神兽离去时间: {0}", Date.FeGetInterpolatedTime(ServerTimer.Instance.Time, _endGameStamp));`);
|
|
896
|
+
expect(targetSnippet.literals).toEqual([
|
|
897
|
+
'神兽离去时间: {0}'
|
|
898
|
+
]);
|
|
899
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
test('should handle lack bracket 3', () => {
|
|
903
|
+
const code = `desc += $"剩余{ToGetInterpolatedTime(_cardPoolData.FinishTime * 1000, ServerTimer.Instance.Time)}";`
|
|
904
|
+
const snippets = extractor.extractStrings(code);
|
|
905
|
+
|
|
906
|
+
// 验证提取的片段数量
|
|
907
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
908
|
+
|
|
909
|
+
let targetSnippet = snippets[0];
|
|
910
|
+
expect(targetSnippet.originalCode).toBe(`desc += $"剩余{ToGetInterpolatedTime(_cardPoolData.FinishTime * 1000, ServerTimer.Instance.Time)}";`);
|
|
911
|
+
expect(targetSnippet.convertedCode).toBe(`desc += Tr.Format("剩余{0}", ToGetInterpolatedTime(_cardPoolData.FinishTime * 1000, ServerTimer.Instance.Time));`);
|
|
912
|
+
expect(targetSnippet.literals).toEqual([
|
|
913
|
+
'剩余{0}'
|
|
914
|
+
]);
|
|
915
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
test('should handle lack bracket 4', () => {
|
|
919
|
+
const code = `desc += $"剩余{ToGetInterpolatedTime(FF(_cardPoolData.FinishTime() * 1000, ServerTimer.Instance.Time()))}";`
|
|
920
|
+
const snippets = extractor.extractStrings(code);
|
|
921
|
+
|
|
922
|
+
// 验证提取的片段数量
|
|
923
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
924
|
+
|
|
925
|
+
let targetSnippet = snippets[0];
|
|
926
|
+
expect(targetSnippet.originalCode).toBe(`desc += $"剩余{ToGetInterpolatedTime(FF(_cardPoolData.FinishTime() * 1000, ServerTimer.Instance.Time()))}";`);
|
|
927
|
+
expect(targetSnippet.convertedCode).toBe(`desc += Tr.Format("剩余{0}", ToGetInterpolatedTime(FF(_cardPoolData.FinishTime() * 1000, ServerTimer.Instance.Time())));`);
|
|
928
|
+
expect(targetSnippet.literals).toEqual([
|
|
929
|
+
'剩余{0}'
|
|
930
|
+
]);
|
|
931
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
test('should handle duplicate tr handle 1', () => {
|
|
935
|
+
const code = `infoStr = $"+={colorCode}";`
|
|
936
|
+
const snippets = extractor.extractStrings(code);
|
|
937
|
+
|
|
938
|
+
// 验证提取的片段数量
|
|
939
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
940
|
+
|
|
941
|
+
let targetSnippet = snippets[0];
|
|
942
|
+
expect(targetSnippet.originalCode).toBe(`infoStr = $"+={colorCode}";`);
|
|
943
|
+
expect(targetSnippet.convertedCode).toBe(`infoStr = Tr.Format("+={0}", colorCode);`);
|
|
944
|
+
expect(targetSnippet.literals).toEqual([
|
|
945
|
+
'+={0}'
|
|
946
|
+
]);
|
|
947
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
test('should handle duplicate tr handle 2', () => {
|
|
951
|
+
const code = `infoStr += $"={colorCode}";`
|
|
952
|
+
const snippets = extractor.extractStrings(code);
|
|
953
|
+
|
|
954
|
+
// 验证提取的片段数量
|
|
955
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
956
|
+
|
|
957
|
+
let targetSnippet = snippets[0];
|
|
958
|
+
expect(targetSnippet.originalCode).toBe(`infoStr += $"={colorCode}";`);
|
|
959
|
+
expect(targetSnippet.convertedCode).toBe(`infoStr += Tr.Format("={0}", colorCode);`);
|
|
960
|
+
expect(targetSnippet.literals).toEqual([
|
|
961
|
+
'={0}'
|
|
962
|
+
]);
|
|
963
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
964
|
+
});
|
|
965
|
+
|
|
966
|
+
test('should handle duplicate tr handle 3', () => {
|
|
967
|
+
const code = `infoStr += $"+={colorCode}";`
|
|
968
|
+
const snippets = extractor.extractStrings(code);
|
|
969
|
+
|
|
970
|
+
// 验证提取的片段数量
|
|
971
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
972
|
+
|
|
973
|
+
let targetSnippet = snippets[0];
|
|
974
|
+
expect(targetSnippet.originalCode).toBe(`infoStr += $"+={colorCode}";`);
|
|
975
|
+
expect(targetSnippet.convertedCode).toBe(`infoStr += Tr.Format("+={0}", colorCode);`);
|
|
976
|
+
expect(targetSnippet.literals).toEqual([
|
|
977
|
+
'+={0}'
|
|
978
|
+
]);
|
|
979
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
test('should handle duplicate tr handle 4', () => {
|
|
983
|
+
const code = `infoStr += $"伤害类型: [color={colorCode}][b]{_damageInfo.DamageType}[/b][/color]\n";`
|
|
984
|
+
const snippets = extractor.extractStrings(code);
|
|
985
|
+
|
|
986
|
+
// 验证提取的片段数量
|
|
987
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
988
|
+
|
|
989
|
+
let targetSnippet = snippets[0];
|
|
990
|
+
expect(targetSnippet.originalCode).toBe(`infoStr += $"伤害类型: [color={colorCode}][b]{_damageInfo.DamageType}[/b][/color]\n";`);
|
|
991
|
+
expect(targetSnippet.convertedCode).toBe(`infoStr += Tr.Format("伤害类型: [color={0}][b]{1}[/b][/color]\n", colorCode, _damageInfo.DamageType);`);
|
|
992
|
+
expect(targetSnippet.literals).toEqual([
|
|
993
|
+
'伤害类型: [color={0}][b]{1}[/b][/color]\n'
|
|
994
|
+
]);
|
|
995
|
+
expect(targetSnippet.isChanged).toBe(true);
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
test('should handle para 1', () => {
|
|
999
|
+
const code = `SetData("等级", level + 1);`
|
|
1000
|
+
const snippets = extractor.extractStrings(code);
|
|
1001
|
+
|
|
1002
|
+
// 验证提取的片段数量
|
|
1003
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
1004
|
+
|
|
1005
|
+
let targetSnippet = snippets[0];
|
|
1006
|
+
expect(targetSnippet.originalCode).toBe(`SetData("等级", level + 1);`);
|
|
1007
|
+
expect(targetSnippet.convertedCode).toBe(`SetData("等级", level + 1);`);
|
|
1008
|
+
expect(targetSnippet.literals).toEqual([
|
|
1009
|
+
"等级"
|
|
1010
|
+
]);
|
|
1011
|
+
expect(targetSnippet.isChanged).toBe(false);
|
|
1012
|
+
});
|
|
1013
|
+
|
|
1014
|
+
test('should handle para 2', () => {
|
|
1015
|
+
const code = `bbb.Func2("等级", level, level + 1, false, isMax);`
|
|
1016
|
+
const snippets = extractor.extractStrings(code);
|
|
1017
|
+
|
|
1018
|
+
// 验证提取的片段数量
|
|
1019
|
+
expect(snippets.length).toBeGreaterThan(0);
|
|
1020
|
+
|
|
1021
|
+
let targetSnippet = snippets[0];
|
|
1022
|
+
expect(targetSnippet.originalCode).toBe(`bbb.Func2("等级", level, level + 1, false, isMax);`);
|
|
1023
|
+
expect(targetSnippet.convertedCode).toBe(`bbb.Func2("等级", level, level + 1, false, isMax);`);
|
|
1024
|
+
expect(targetSnippet.literals).toEqual([
|
|
1025
|
+
"等级"
|
|
1026
|
+
]);
|
|
1027
|
+
expect(targetSnippet.isChanged).toBe(false);
|
|
1028
|
+
});
|
|
1029
|
+
});
|