scancscode 1.0.39 → 1.0.40

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.
@@ -235,7 +235,7 @@ class CSharpStringExtractor {
235
235
  snippet.originalCode = valueExpression;
236
236
  snippet.originalContext = valueExpression;
237
237
  this.variableIndex = 0;
238
- if (isCaseOrDefault) {
238
+ if (isCaseOrDefault && !isTextAssignment) {
239
239
  this.processSingleArgument(snippet, valueExpression, trClass, trFormatMethod, trMethod);
240
240
  }
241
241
  else {
@@ -2561,4 +2561,71 @@ namespace FaBao
2561
2561
  ]);
2562
2562
  }
2563
2563
  });
2564
+ // 测试`m_btn_xxx.title = yyy;` 形式的赋值语句要和`xxx.text = yyy;`形式的赋值语句完全等同处理
2565
+ test('should handle .text = assignments contains chinese', () => {
2566
+ const code = `
2567
+ switch (_roomData.RoomState)
2568
+ {
2569
+ case Data.Match.RoomState.IsDismiss:
2570
+ m_btn_join.title = "已解散";
2571
+ m_btn_join.enabled = false;
2572
+ grayed = true;
2573
+ break;
2574
+ case Data.Match.RoomState.Rejected:
2575
+ {
2576
+ m_btn_join.title = $"被拒绝{Kff}";
2577
+ m_btn_join.enabled = false;
2578
+ break;
2579
+ }
2580
+ case Data.Match.RoomState.OutOfDate:
2581
+ m_dd_join.text = "已到期";
2582
+ break;
2583
+ default:
2584
+ m_btn_join.title = "申请";
2585
+ m_btn_joi23n.title = $"申请{Kjf}";
2586
+ break;
2587
+ }
2588
+ `;
2589
+ const snippets = extractor.extractStrings(code);
2590
+ {
2591
+ let snippet = snippets[0];
2592
+ expect(snippet.originalCode).toBe('"已解散"');
2593
+ expect(snippet.convertedCode).toBe('"已解散".TR()');
2594
+ expect(snippet.literals).toEqual([
2595
+ '已解散'
2596
+ ]);
2597
+ }
2598
+ {
2599
+ let snippet = snippets[1];
2600
+ expect(snippet.originalCode).toBe('$"被拒绝{Kff}"');
2601
+ expect(snippet.convertedCode).toBe('Tr.Format("被拒绝{0}", Kff)');
2602
+ expect(snippet.literals).toEqual([
2603
+ '被拒绝{0}'
2604
+ ]);
2605
+ }
2606
+ {
2607
+ let snippet = snippets[2];
2608
+ expect(snippet.originalCode).toBe('"已到期"');
2609
+ expect(snippet.convertedCode).toBe('"已到期".TR()');
2610
+ expect(snippet.literals).toEqual([
2611
+ '已到期'
2612
+ ]);
2613
+ }
2614
+ {
2615
+ let snippet = snippets[3];
2616
+ expect(snippet.originalCode).toBe('"申请"');
2617
+ expect(snippet.convertedCode).toBe('"申请".TR()');
2618
+ expect(snippet.literals).toEqual([
2619
+ '申请'
2620
+ ]);
2621
+ }
2622
+ {
2623
+ let snippet = snippets[4];
2624
+ expect(snippet.originalCode).toBe('$"申请{Kjf}"');
2625
+ expect(snippet.convertedCode).toBe('Tr.Format("申请{0}", Kjf)');
2626
+ expect(snippet.literals).toEqual([
2627
+ '申请{0}'
2628
+ ]);
2629
+ }
2630
+ });
2564
2631
  });
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const CmdExecutor_1 = require("../src/CmdExecutor");
3
4
  describe('TestCmdExecutor', () => {
4
5
  test("test convert", async () => {
5
- // await CmdExecutor.testConvert();
6
+ await CmdExecutor_1.CmdExecutor.testConvert();
6
7
  expect(true).toBe(true);
7
8
  }, 50000);
8
9
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scancscode",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {
@@ -254,7 +254,7 @@ export class CSharpStringExtractor {
254
254
 
255
255
  this.variableIndex = 0;
256
256
 
257
- if (isCaseOrDefault) {
257
+ if (isCaseOrDefault && !isTextAssignment) {
258
258
  this.processSingleArgument(snippet, valueExpression, trClass, trFormatMethod, trMethod);
259
259
  } else {
260
260
  this.processStatementAndExtractValue(snippet, statement, valueExpression, trClass, trFormatMethod, trMethod);
@@ -2802,4 +2802,72 @@ namespace FaBao
2802
2802
  }
2803
2803
  });
2804
2804
 
2805
+ // 测试`m_btn_xxx.title = yyy;` 形式的赋值语句要和`xxx.text = yyy;`形式的赋值语句完全等同处理
2806
+ test('should handle .text = assignments contains chinese', () => {
2807
+ const code = `
2808
+ switch (_roomData.RoomState)
2809
+ {
2810
+ case Data.Match.RoomState.IsDismiss:
2811
+ m_btn_join.title = "已解散";
2812
+ m_btn_join.enabled = false;
2813
+ grayed = true;
2814
+ break;
2815
+ case Data.Match.RoomState.Rejected:
2816
+ {
2817
+ m_btn_join.title = $"被拒绝{Kff}";
2818
+ m_btn_join.enabled = false;
2819
+ break;
2820
+ }
2821
+ case Data.Match.RoomState.OutOfDate:
2822
+ m_dd_join.text = "已到期";
2823
+ break;
2824
+ default:
2825
+ m_btn_join.title = "申请";
2826
+ m_btn_joi23n.title = $"申请{Kjf}";
2827
+ break;
2828
+ }
2829
+ `;
2830
+ const snippets = extractor.extractStrings(code);
2831
+ {
2832
+ let snippet = snippets[0];
2833
+ expect(snippet.originalCode).toBe('"已解散"');
2834
+ expect(snippet.convertedCode).toBe('"已解散".TR()');
2835
+ expect(snippet.literals).toEqual([
2836
+ '已解散'
2837
+ ]);
2838
+ }
2839
+ {
2840
+ let snippet = snippets[1];
2841
+ expect(snippet.originalCode).toBe('$"被拒绝{Kff}"');
2842
+ expect(snippet.convertedCode).toBe('Tr.Format("被拒绝{0}", Kff)');
2843
+ expect(snippet.literals).toEqual([
2844
+ '被拒绝{0}'
2845
+ ]);
2846
+ }
2847
+ {
2848
+ let snippet = snippets[2];
2849
+ expect(snippet.originalCode).toBe('"已到期"');
2850
+ expect(snippet.convertedCode).toBe('"已到期".TR()');
2851
+ expect(snippet.literals).toEqual([
2852
+ '已到期'
2853
+ ]);
2854
+ }
2855
+ {
2856
+ let snippet = snippets[3];
2857
+ expect(snippet.originalCode).toBe('"申请"');
2858
+ expect(snippet.convertedCode).toBe('"申请".TR()');
2859
+ expect(snippet.literals).toEqual([
2860
+ '申请'
2861
+ ]);
2862
+ }
2863
+ {
2864
+ let snippet = snippets[4];
2865
+ expect(snippet.originalCode).toBe('$"申请{Kjf}"');
2866
+ expect(snippet.convertedCode).toBe('Tr.Format("申请{0}", Kjf)');
2867
+ expect(snippet.literals).toEqual([
2868
+ '申请{0}'
2869
+ ]);
2870
+ }
2871
+ });
2872
+
2805
2873
  });
@@ -2,7 +2,7 @@ import { CmdExecutor } from "../src/CmdExecutor";
2
2
 
3
3
  describe('TestCmdExecutor', () => {
4
4
  test("test convert", async () => {
5
- // await CmdExecutor.testConvert();
5
+ await CmdExecutor.testConvert();
6
6
  expect(true).toBe(true);
7
7
  }, 50000);
8
8
  });