scancscode 1.0.33 → 1.0.35

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.
@@ -1396,35 +1396,20 @@ describe('CSharpStringExtractor', () => {
1396
1396
 
1397
1397
  });
1398
1398
 
1399
- // // 测试处理C#字符串表达式中包含各种特殊字符的情况
1400
- // test('should handle special characters in string expression 1', () => {
1401
- // const code = `return "abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\";`;
1402
- // const snippets = extractor.extractStrings(code);
1403
-
1404
- // let targetSnippet = snippets[0];
1405
- // expect(targetSnippet.originalIndex).toBe(code.indexOf(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`));
1406
- // expect(targetSnippet.originalCode).toBe(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`);
1407
- // expect(targetSnippet.convertedCode).toBe(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`);
1408
- // expect(targetSnippet.literals).toEqual([
1409
- // 'abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\'
1410
- // ]);
1411
- // expect(targetSnippet.isChanged).toBe(false);
1412
- // });
1413
-
1414
- // // 测试处理C#字符串表达式中包含各种特殊字符的情况
1415
- // test('should handle special characters in string expression 2', () => {
1416
- // const code = readFileSync("test/TestSpecialString.cs", "utf8");
1417
- // const snippets = extractor.extractStrings(code);
1418
-
1419
- // let targetSnippet = snippets[0];
1420
- // expect(targetSnippet.originalIndex).toBe(code.indexOf(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`));
1421
- // expect(targetSnippet.originalCode).toBe(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`);
1422
- // expect(targetSnippet.convertedCode).toBe(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`);
1423
- // expect(targetSnippet.literals).toEqual([
1424
- // 'abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\'
1425
- // ]);
1426
- // expect(targetSnippet.isChanged).toBe(false);
1427
- // });
1399
+ // 测试处理C#字符串表达式中包含各种特殊字符的情况
1400
+ test('should handle special characters in string expression 1', () => {
1401
+ const code = `return "abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\";`;
1402
+ const snippets = extractor.extractStrings(code);
1403
+
1404
+ let targetSnippet = snippets[0];
1405
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`));
1406
+ expect(targetSnippet.originalCode).toBe(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`);
1407
+ expect(targetSnippet.convertedCode).toBe(`"abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\"`);
1408
+ expect(targetSnippet.literals).toEqual([
1409
+ 'abcdefghijklmnopqrstuvwxyz\`-=[];\',./~!@#$%^&*()_+{}|:\\"<>?1234567890\\\\'
1410
+ ]);
1411
+ expect(targetSnippet.isChanged).toBe(false);
1412
+ });
1428
1413
 
1429
1414
  // 测试处理在C#类成员初始赋值语句中, 字符串表达式中包含各种特殊字符的情况, 工具中需要统一处理C#字符串边界识别和捕获
1430
1415
  test('should handle member initial assignment', () => {
@@ -2331,55 +2316,179 @@ namespace FaBao.UI.MainUI
2331
2316
  expect(snippets.length).toBe(1);
2332
2317
  });
2333
2318
 
2334
- // // 需要正确识别C#代码中类成员初始化赋值时, 给成员赋值匿名函数时, 匿名函数中的字符串表达式也需要提取
2335
- // test('should handle class member initialization assignment with anonymous function', () => {
2336
- // const code = `
2337
- // FUISys.Instance.ShowLayer<MainConfirmDialog>(UISceneType.Main, new MainConfirmDialog.MainConfirmDialogParam()
2338
- // {
2339
- // Title = "提示",
2340
- // ConfirmCallback = async () =>
2341
- // {
2342
- // //灵纹一键下阵
2343
- // if (await this.GetModel<CardModel>().DispatchAction(new Rune_Action_CleanRune(_sutraCardData.Card.Id)))
2344
- // {
2345
- // Toast.Info("卸载成功");
2346
- // }
2347
- // },
2348
- // CancelText = "取消",
2349
- // }).Forget();
2350
- // `;
2351
- // const snippets = extractor.extractStrings(code);
2352
- // {
2353
- // let targetSnippet = snippets[0];
2354
- // expect(targetSnippet.originalIndex).toBe(code.indexOf(`提示`));
2355
- // expect(targetSnippet.originalCode).toBe(`提示`);
2356
- // expect(targetSnippet.convertedCode).toBe(`提示`);
2357
- // expect(targetSnippet.literals).toEqual([
2358
- // '提示'
2359
- // ]);
2360
- // expect(targetSnippet.isChanged).toBe(false);
2361
- // }
2362
- // {
2363
- // let targetSnippet = snippets[0];
2364
- // // 需要正确识别C#代码中类成员初始化赋值时, 给成员赋值匿名函数时, 匿名函数中的字符串表达式也需要提取
2365
- // expect(targetSnippet.originalIndex).toBe(code.indexOf(`卸载成功`));
2366
- // expect(targetSnippet.originalCode).toBe(`卸载成功`);
2367
- // expect(targetSnippet.convertedCode).toBe(`卸载成功`);
2368
- // expect(targetSnippet.literals).toEqual([
2369
- // '卸载成功'
2370
- // ]);
2371
- // expect(targetSnippet.isChanged).toBe(false);
2372
- // }
2373
- // {
2374
- // let targetSnippet = snippets[0];
2375
- // expect(targetSnippet.originalIndex).toBe(code.indexOf(`取消`));
2376
- // expect(targetSnippet.originalCode).toBe(`取消`);
2377
- // expect(targetSnippet.convertedCode).toBe(`取消`);
2378
- // expect(targetSnippet.literals).toEqual([
2379
- // '取消'
2380
- // ]);
2381
- // expect(targetSnippet.isChanged).toBe(false);
2382
- // }
2383
- // });
2319
+ // 需要正确识别C#代码中的匿名函数, 匿名函数中的字符串表达式也同样需要提取; 匿名函数通常以 `0到多个修饰词 (可选参数列表) => { ... }` 或者 `0到多个修饰词 (可选参数列表) => 一句表达式` 形式定义实现.
2320
+ test('should handle class member initialization assignment with anonymous function 1', () => {
2321
+ const code = `
2322
+ FUISys.Instance.ShowLayer<MainConfirmDialog>(UISceneType.Main, new MainConfirmDialog.MainConfirmDialogParam()
2323
+ {
2324
+ Title = "提示",
2325
+ ConfirmCallback = async () =>
2326
+ {
2327
+ //灵纹一键下阵
2328
+ if (await this.GetModel<CardModel>().DispatchAction(new Rune_Action_CleanRune(_sutraCardData.Card.Id)))
2329
+ {
2330
+ Toast.Info("卸载成功");
2331
+ }
2332
+ },
2333
+ CancelText = "取消",
2334
+ }).Forget();
2335
+ `;
2336
+ const snippets = extractor.extractStrings(code);
2337
+ {
2338
+ let targetSnippet = snippets[0];
2339
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`"提示"`));
2340
+ expect(targetSnippet.originalCode).toBe(`"提示"`);
2341
+ expect(targetSnippet.convertedCode).toBe(`"提示"`);
2342
+ expect(targetSnippet.literals).toEqual([
2343
+ '提示'
2344
+ ]);
2345
+ expect(targetSnippet.isChanged).toBe(false);
2346
+ }
2347
+ {
2348
+ let targetSnippet = snippets[1];
2349
+ // 需要正确识别C#代码中类成员初始化赋值时, 给成员赋值匿名函数时, 匿名函数中的字符串表达式也需要提取
2350
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`"卸载成功"`));
2351
+ expect(targetSnippet.originalCode).toBe(`"卸载成功"`);
2352
+ expect(targetSnippet.convertedCode).toBe(`"卸载成功"`);
2353
+ expect(targetSnippet.literals).toEqual([
2354
+ '卸载成功'
2355
+ ]);
2356
+ expect(targetSnippet.isChanged).toBe(false);
2357
+ }
2358
+ {
2359
+ let targetSnippet = snippets[2];
2360
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`"取消"`));
2361
+ expect(targetSnippet.originalCode).toBe(`"取消"`);
2362
+ expect(targetSnippet.convertedCode).toBe(`"取消"`);
2363
+ expect(targetSnippet.literals).toEqual([
2364
+ '取消'
2365
+ ]);
2366
+ expect(targetSnippet.isChanged).toBe(false);
2367
+ }
2368
+ });
2369
+
2370
+ // 需要正确识别C#代码中的匿名函数, 匿名函数中的字符串表达式也同样需要提取; 匿名函数通常以 `0到多个修饰词 (可选参数列表) => { ... }` 或者 `0到多个修饰词 (可选参数列表) => 一句表达式` 形式定义实现.
2371
+ test('should handle class member initialization assignment with anonymous function 2', () => {
2372
+ const code = `
2373
+ FUISys.Instance.ShowLayer<MainConfirmDialog>(UISceneType.Main, new MainConfirmDialog.MainConfirmDialogParam()
2374
+ {
2375
+ ConfirmCallback = async () =>
2376
+ {
2377
+ Toast.Info("卸载成功");
2378
+ },
2379
+ }).Forget();
2380
+ `;
2381
+ const snippets = extractor.extractStrings(code);
2382
+ {
2383
+ let targetSnippet = snippets[0];
2384
+ // 需要正确识别C#代码中类成员初始化赋值时, 给成员赋值匿名函数时, 匿名函数中的字符串表达式也需要提取
2385
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`"卸载成功"`));
2386
+ expect(targetSnippet.originalCode).toBe(`"卸载成功"`);
2387
+ expect(targetSnippet.convertedCode).toBe(`"卸载成功"`);
2388
+ expect(targetSnippet.literals).toEqual([
2389
+ '卸载成功'
2390
+ ]);
2391
+ expect(targetSnippet.isChanged).toBe(false);
2392
+ }
2393
+ });
2394
+
2395
+ // 需要正确识别C#代码中的匿名函数, 匿名函数中的字符串表达式也同样需要提取; 匿名函数通常以 `0到多个修饰词 (可选参数列表) => { ... }` 或者 `0到多个修饰词 (可选参数列表) => 一句表达式` 形式定义实现.
2396
+ test('should handle class member initialization assignment with anonymous function 2', () => {
2397
+ const code = `
2398
+ FUISys.Instance.ShowLayer<MainConfirmDialog>(UISceneType.Main, new MainConfirmDialog.MainConfirmDialogParam()
2399
+ {
2400
+ ConfirmCallback = (int qwfewe) =>
2401
+ {
2402
+ Toast.Info($"卸载成功: {qwfewe}");
2403
+ },
2404
+ }).Forget();
2405
+ `;
2406
+ const snippets = extractor.extractStrings(code);
2407
+ {
2408
+ let targetSnippet = snippets[0];
2409
+ // 需要正确识别C#代码中类成员初始化赋值时, 给成员赋值匿名函数时, 匿名函数中的字符串表达式也需要提取
2410
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`$"卸载成功: {qwfewe}"`));
2411
+ expect(targetSnippet.originalCode).toBe(`$"卸载成功: {qwfewe}"`);
2412
+ expect(targetSnippet.convertedCode).toBe(`Tr.Format("卸载成功: {0}", qwfewe)`);
2413
+ expect(targetSnippet.literals).toEqual([
2414
+ '卸载成功: {0}'
2415
+ ]);
2416
+ expect(targetSnippet.isChanged).toBe(true);
2417
+ }
2418
+ });
2419
+
2420
+ // 需要正确识别C#代码中的匿名函数, 匿名函数中的字符串表达式也同样需要提取; 匿名函数通常以 `0到多个修饰词 (可选参数列表) => { ... }` 或者 `0到多个修饰词 (可选参数列表) => 一句表达式` 形式定义实现.
2421
+ test('should handle class member initialization assignment with anonymous function 3', () => {
2422
+ const code = `
2423
+ FUISys.Instance.ShowLayer<MainConfirmDialog>(UISceneType.Main, new MainConfirmDialog.MainConfirmDialogParam()
2424
+ {
2425
+ ConfirmCallback = async () => Toast.Info("卸载成功"),
2426
+ }).Forget();
2427
+ `;
2428
+ const snippets = extractor.extractStrings(code);
2429
+ {
2430
+ let targetSnippet = snippets[0];
2431
+ // 需要正确识别C#代码中类成员初始化赋值时, 给成员赋值匿名函数时, 匿名函数中的字符串表达式也需要提取
2432
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`"卸载成功"`));
2433
+ expect(targetSnippet.originalCode).toBe(`"卸载成功"`);
2434
+ expect(targetSnippet.convertedCode).toBe(`"卸载成功"`);
2435
+ expect(targetSnippet.literals).toEqual([
2436
+ '卸载成功'
2437
+ ]);
2438
+ expect(targetSnippet.isChanged).toBe(false);
2439
+ }
2440
+ });
2441
+
2442
+ // 需要正确识别C#代码中的匿名函数, 匿名函数中的字符串表达式也同样需要提取; 匿名函数通常以 `0到多个修饰词 (可选参数列表) => { ... }` 或者 `0到多个修饰词 (可选参数列表) => 一句表达式` 形式定义实现.
2443
+ test('should handle class member initialization assignment with anonymous function 4', () => {
2444
+ const code = `
2445
+ FUISys.Instance.ShowLayer<MainConfirmDialog>(UISceneType.Main, new MainConfirmDialog.MainConfirmDialogParam()
2446
+ {
2447
+ ConfirmCallback = () => Toast.Info("卸载成功"),
2448
+ }).Forget();
2449
+ `;
2450
+ const snippets = extractor.extractStrings(code);
2451
+ {
2452
+ let targetSnippet = snippets[0];
2453
+ // 需要正确识别C#代码中类成员初始化赋值时, 给成员赋值匿名函数时, 匿名函数中的字符串表达式也需要提取
2454
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`"卸载成功"`));
2455
+ expect(targetSnippet.originalCode).toBe(`"卸载成功"`);
2456
+ expect(targetSnippet.convertedCode).toBe(`"卸载成功"`);
2457
+ expect(targetSnippet.literals).toEqual([
2458
+ '卸载成功'
2459
+ ]);
2460
+ expect(targetSnippet.isChanged).toBe(false);
2461
+ }
2462
+ });
2463
+
2464
+ // 测试处理 `xxx.text = yyy` 形式赋值语句, 以 `.text =` 给 `text` 成员赋值的表达式中, `yyy` 部分必定是字符串表达式; 如果`yyy`中不存在字符串, 则`yyy` 中以 `+` 连接的表达式需要加上 `.TR()`; 如果 `yyy` 是作为值表达式整体(必定返回字符串类型值), 也需要追加 `.TR()`。
2465
+ test('should handle .text = format 1', () => {
2466
+ const code = `m_text_iwff.text = info ;`;
2467
+ const snippets = extractor.extractStrings(code);
2468
+ {
2469
+ let targetSnippet = snippets[0];
2470
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`info`));
2471
+ expect(targetSnippet.originalCode).toBe(`info`);
2472
+ expect(targetSnippet.convertedCode).toBe(`info.TR()`);
2473
+ expect(targetSnippet.literals).toEqual([
2474
+ ]);
2475
+ expect(targetSnippet.isChanged).toBe(true);
2476
+ }
2477
+ });
2478
+
2479
+ // 测试处理 `xxx.text = yyy` 形式赋值语句, 以 `.text =` 给 `text` 成员赋值的表达式中, `yyy` 部分必定是字符串表达式; 如果`yyy`中不存在字符串, 则`yyy` 中以 `+` 连接的表达式需要加上 `.TR()`; 如果 `yyy` 是作为值表达式整体(必定返回字符串类型值), 也需要追加 `.TR()`。
2480
+ test('should handle .text = format 1', () => {
2481
+ const code = `m_text_info.text = info1.member1 + info2.member2;`;
2482
+ const snippets = extractor.extractStrings(code);
2483
+ {
2484
+ let targetSnippet = snippets[0];
2485
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`info1.member1 + info2.member2`));
2486
+ expect(targetSnippet.originalCode).toBe(`info1.member1 + info2.member2`);
2487
+ expect(targetSnippet.convertedCode).toBe(`info1.member1.TR() + info2.member2.TR()`);
2488
+ expect(targetSnippet.literals).toEqual([
2489
+ ]);
2490
+ expect(targetSnippet.isChanged).toBe(true);
2491
+ }
2492
+ });
2384
2493
 
2385
2494
  });
@@ -1,24 +1,24 @@
1
- public class AA{
2
- public string Member2 = "\\";
3
- public string Member3 = "\n";
4
- public string Member4 = $"\t";
5
- public string Test1(){
6
- var wef = new ClassB(){
7
- Member1 = "1. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\",
8
- };
9
- var wefe = "2. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
10
- var wefeF = $"3. {wef}{{}}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
11
- Debug.Log("4. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\");
12
- return "5. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
13
- }
14
- public string Member1 = "6. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
15
- public static string StaticMember1 = "7. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
16
- public static string Test2(){
17
- var wefff = 34;
18
- var vwve = new ClassB(){
19
- Member1 = $"8. {wefff}{{}}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\",
20
- };
21
- Debug.Log($"9. {wefff}{{}}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\");
22
- return $"10. {wefff}{{}}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
23
- }
24
- }
1
+ public class AA{
2
+ public string Member2 = "\\";
3
+ public string Member3 = "\n";
4
+ public string Member4 = $"\t";
5
+ public string Test1(){
6
+ var wef = new ClassB(){
7
+ Member1 = "1. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\",
8
+ };
9
+ var wefe = "2. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
10
+ var wefeF = $"3. {wef}{{}}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
11
+ Debug.Log("4. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\");
12
+ return "5. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
13
+ }
14
+ public string Member1 = "6. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
15
+ public static string StaticMember1 = "7. {}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
16
+ public static string Test2(){
17
+ var wefff = 34;
18
+ var vwve = new ClassB(){
19
+ Member1 = $"8. {wefff}{{}}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\",
20
+ };
21
+ Debug.Log($"9. {wefff}{{}}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\");
22
+ return $"10. {wefff}{{}}abcdefghijklmnopqrstuvwxyz`-=[];',./~!@#$%^&*()_+|:\"<>?1234567890\\";
23
+ }
24
+ }