scancscode 1.0.56 → 1.0.58

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.
@@ -369,7 +369,7 @@ describe('CSharpStringExtractor', () => {
369
369
  }
370
370
  });
371
371
  // 处理C#多行语句
372
- test('should handle multilne content1', () => {
372
+ test('should handle multilne content 1', () => {
373
373
  const code = 'var aa = "aaa";\nvar bb = "bbb";\nvar cc = "ccc";';
374
374
  const snippets = extractor.extractStrings(code);
375
375
  {
@@ -395,7 +395,7 @@ describe('CSharpStringExtractor', () => {
395
395
  }
396
396
  });
397
397
  // 处理C#多行语句
398
- test('should handle multilne content2', () => {
398
+ test('should handle multilne content 2', () => {
399
399
  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;';
400
400
  const snippets = extractor.extractStrings(code);
401
401
  {
@@ -470,7 +470,7 @@ describe('CSharpStringExtractor', () => {
470
470
  }
471
471
  });
472
472
  // 处理C#多行语句
473
- test('should handle multilne content3', () => {
473
+ test('should handle multilne content 3', () => {
474
474
  const code = 'label.text = Tr.Format("pre", Func(), "sub") + other;\nlabel2.text = Tr.Format("pre2", Func(), "sub2") + other2;';
475
475
  const snippets = extractor.extractStrings(code);
476
476
  {
@@ -489,7 +489,7 @@ describe('CSharpStringExtractor', () => {
489
489
  }
490
490
  });
491
491
  // 处理C#多行语句
492
- test('should handle multilne content4', () => {
492
+ test('should handle multilne content 4', () => {
493
493
  const code = 'label.text =\n Tr.Format(\n\t"pre", Func(),\n\t\t "sub") + other;';
494
494
  const snippets = extractor.extractStrings(code);
495
495
  {
@@ -501,7 +501,7 @@ describe('CSharpStringExtractor', () => {
501
501
  }
502
502
  });
503
503
  // 处理C#多行语句
504
- test('should handle multilne content5', () => {
504
+ test('should handle multilne content 5', () => {
505
505
  const code = `
506
506
  // 注释中无字符串表达式时, 不需要包含在捕获部分里
507
507
  m_text_name.text = cardTable.Name;
@@ -516,7 +516,7 @@ describe('CSharpStringExtractor', () => {
516
516
  }
517
517
  });
518
518
  // 处理C#多行语句
519
- test('should handle multilne content6', () => {
519
+ test('should handle multilne content 6', () => {
520
520
  const code = `
521
521
  if (condition)
522
522
  {
@@ -534,7 +534,7 @@ describe('CSharpStringExtractor', () => {
534
534
  }
535
535
  });
536
536
  // 处理C#多行语句
537
- test('should handle multilne content7', () => {
537
+ test('should handle multilne content 7', () => {
538
538
  const code = `
539
539
  while (condition)
540
540
  {
@@ -552,7 +552,7 @@ describe('CSharpStringExtractor', () => {
552
552
  }
553
553
  });
554
554
  // 处理C#多行语句
555
- test('should handle multilne content8', () => {
555
+ test('should handle multilne content 8', () => {
556
556
  const code = `
557
557
  for (scope;condition;continuex)
558
558
  {
@@ -569,7 +569,7 @@ describe('CSharpStringExtractor', () => {
569
569
  }
570
570
  });
571
571
  // 处理C#多行语句
572
- test('should handle multilne content9', () => {
572
+ test('should handle multilne content 9', () => {
573
573
  const code = `
574
574
  {
575
575
  KK3.Ca3("卸载成功");
@@ -585,7 +585,7 @@ describe('CSharpStringExtractor', () => {
585
585
  }
586
586
  });
587
587
  // 处理C#多行语句
588
- test('should handle multilne content10', () => {
588
+ test('should handle multilne content 10', () => {
589
589
  const code = `
590
590
  var lambda1 = () => {
591
591
  LJN4.Fn4("卸载成功");
@@ -601,7 +601,7 @@ describe('CSharpStringExtractor', () => {
601
601
  }
602
602
  });
603
603
  // 处理C#多行语句
604
- test('should handle multilne content11', () => {
604
+ test('should handle multilne content 11', () => {
605
605
  const code = `
606
606
  void lambda1() {
607
607
  KK5.Call5("卸载成功");
@@ -617,7 +617,7 @@ describe('CSharpStringExtractor', () => {
617
617
  }
618
618
  });
619
619
  // 处理C#多行语句
620
- test('should handle multilne content12', () => {
620
+ test('should handle multilne content 12', () => {
621
621
  const code = `
622
622
  //星级
623
623
  m_list_star.RemoveChildrenToPool();
@@ -644,7 +644,7 @@ describe('CSharpStringExtractor', () => {
644
644
  }
645
645
  });
646
646
  // 处理C#多行语句
647
- test('should handle multilne content13', () => {
647
+ test('should handle multilne content 13', () => {
648
648
  const code = `
649
649
  Toast.Info("卸载成功");
650
650
  Toast.Info("卸载成功");
@@ -668,7 +668,7 @@ describe('CSharpStringExtractor', () => {
668
668
  }
669
669
  });
670
670
  // 处理C#多行语句
671
- test('should handle multilne content14', () => {
671
+ test('should handle multilne content 14', () => {
672
672
  const code = (0, fs_1.readFileSync)('./test/MainSutraDetailDialog.cs', 'utf8');
673
673
  const snippets = extractor.extractStrings(code);
674
674
  // 验证提取的片段数量
@@ -825,7 +825,7 @@ describe('CSharpStringExtractor', () => {
825
825
  expect(snippets[21].isChanged).toBe(false);
826
826
  });
827
827
  // 处理C#多行语句
828
- test('should handle multilne content15', () => {
828
+ test('should handle multilne content 15', () => {
829
829
  const code = (0, fs_1.readFileSync)('./test/GuildDonateDialog.cs', 'utf8');
830
830
  const snippets = extractor.extractStrings(code);
831
831
  // 验证提取的片段数量
@@ -867,7 +867,7 @@ describe('CSharpStringExtractor', () => {
867
867
  expect(targetSnippet.isChanged).toBe(true);
868
868
  });
869
869
  // 处理C#多行语句, 特别是包含 `\n` 的字符串
870
- test('should handle multilne content17', () => {
870
+ test('should handle multilne content 17', () => {
871
871
  const code = `
872
872
  infoStr += $"aaa: {aa}\n" +
873
873
  $"bbb = {bb}";
@@ -887,7 +887,7 @@ describe('CSharpStringExtractor', () => {
887
887
  expect(targetSnippet.isChanged).toBe(true);
888
888
  });
889
889
  // 处理C#多行语句, 特别是包含 `\\n` 的内插字符串
890
- test('should handle multilne content19', () => {
890
+ test('should handle multilne content 19', () => {
891
891
  const code = `
892
892
  infoStr += $"aaa: {aa}\\n" +
893
893
  $"bbb = {bb}";
@@ -907,7 +907,7 @@ describe('CSharpStringExtractor', () => {
907
907
  expect(targetSnippet.isChanged).toBe(true);
908
908
  });
909
909
  // 处理C#中多行字符串拼接成的字符串表达式
910
- test('should handle multilne content18', () => {
910
+ test('should handle multilne content 18', () => {
911
911
  const code = `
912
912
  infoStr += "伤害公式: \\n" +
913
913
  $"最终伤害[color={colorCode}][{(float)damageValue:F}][/color] = \\n" +
@@ -2684,4 +2684,195 @@ namespace FaBao
2684
2684
  ]);
2685
2685
  }
2686
2686
  });
2687
+ // 测试if语句有花括号包围的单句表达式语句中的字符串表达式处理
2688
+ test('should handle assignment expression within if{}else{}', () => {
2689
+ const code = `
2690
+ if (_eventIdx < _table.MainDescription.Length)
2691
+ {
2692
+ m_text_desc.text = _table.MainDescription[_eventIdx];
2693
+ }
2694
+ else
2695
+ {
2696
+ m_text_desc.text = _table.MainDescription[0];
2697
+ }
2698
+ `;
2699
+ const snippets = extractor.extractStrings(code);
2700
+ {
2701
+ let targetSnippet = snippets[0];
2702
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[_eventIdx]`));
2703
+ expect(targetSnippet.originalCode).toBe(`_table.MainDescription[_eventIdx]`);
2704
+ expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[_eventIdx].TR()`);
2705
+ expect(targetSnippet.literals).toEqual([]);
2706
+ expect(targetSnippet.isChanged).toBe(true);
2707
+ }
2708
+ {
2709
+ let targetSnippet = snippets[1];
2710
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[0]`));
2711
+ expect(targetSnippet.originalCode).toBe(`_table.MainDescription[0]`);
2712
+ expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[0].TR()`);
2713
+ expect(targetSnippet.literals).toEqual([]);
2714
+ expect(targetSnippet.isChanged).toBe(true);
2715
+ }
2716
+ expect(snippets.length).toBe(2);
2717
+ });
2718
+ // 测试if语句无花括号包围的单句表达式语句中的字符串表达式处理
2719
+ test('should handle assignment expression within if-else-end', () => {
2720
+ const code = `
2721
+ if (_eventIdx < _table.MainDescription.Length)
2722
+ m_text_desc.text = _table.MainDescription[_eventIdx];
2723
+ else
2724
+ m_text_desc.text = _table.MainDescription[0];
2725
+ `;
2726
+ const snippets = extractor.extractStrings(code);
2727
+ {
2728
+ let targetSnippet = snippets[0];
2729
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[_eventIdx]`));
2730
+ expect(targetSnippet.originalCode).toBe(`_table.MainDescription[_eventIdx]`);
2731
+ expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[_eventIdx].TR()`);
2732
+ expect(targetSnippet.literals).toEqual([]);
2733
+ expect(targetSnippet.isChanged).toBe(true);
2734
+ }
2735
+ {
2736
+ let targetSnippet = snippets[1];
2737
+ expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[0]`));
2738
+ expect(targetSnippet.originalCode).toBe(`_table.MainDescription[0]`);
2739
+ expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[0].TR()`);
2740
+ expect(targetSnippet.literals).toEqual([]);
2741
+ expect(targetSnippet.isChanged).toBe(true);
2742
+ }
2743
+ expect(snippets.length).toBe(2);
2744
+ });
2745
+ // // 测试if语句无花括号包围的单句表达式语句中的字符串表达式处理
2746
+ // test('should handle assignment expression within if-else-end', () => {
2747
+ // const code = `
2748
+ // private void RefreshRedDot()
2749
+ // {
2750
+ // m_redDot.visible = _data.NeedShowRedDot();
2751
+ // }
2752
+ // private void OnSelfClick()
2753
+ // {
2754
+ // this.GetSystem<AudioSys>().PlayAudioByName(AudioName.SoundUI_Button);
2755
+ // if (!_data.IsOpen)
2756
+ // {
2757
+ // string tip = _data.Config.LockTip;
2758
+ // if (_data.Config.TaskIds != null && _data.Config.TaskIds.Count > 0)
2759
+ // {
2760
+ // int taskId = App.Instance.GetModel<MissionModel>().CurGuideMissionConfig.Id;
2761
+ // int remainingTaskCount = _data.Config.TaskIds[0] - taskId + 1;
2762
+ // remainingTaskCount = Mathf.Max(0, remainingTaskCount);
2763
+ // tip = string.Format(_data.Config.LockTip, remainingTaskCount);
2764
+ // }
2765
+ // Toast.Info(tip);
2766
+ // return;
2767
+ // }
2768
+ // `;
2769
+ // const snippets = extractor.extractStrings(code);
2770
+ // {
2771
+ // let targetSnippet = snippets[0];
2772
+ // expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[_eventIdx]`));
2773
+ // expect(targetSnippet.originalCode).toBe(`_table.MainDescription[_eventIdx]`);
2774
+ // expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[_eventIdx].TR()`);
2775
+ // expect(targetSnippet.literals).toEqual([
2776
+ // ]);
2777
+ // expect(targetSnippet.isChanged).toBe(true);
2778
+ // }
2779
+ // {
2780
+ // let targetSnippet = snippets[1];
2781
+ // expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[0]`));
2782
+ // expect(targetSnippet.originalCode).toBe(`_table.MainDescription[0]`);
2783
+ // expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[0].TR()`);
2784
+ // expect(targetSnippet.literals).toEqual([
2785
+ // ]);
2786
+ // expect(targetSnippet.isChanged).toBe(true);
2787
+ // }
2788
+ // expect(snippets.length).toBe(2);
2789
+ // })
2790
+ // // 测试if语句无花括号包围的单句表达式语句中的字符串表达式处理
2791
+ // test('should handle assignment expression within if-else-end', () => {
2792
+ // const code = `
2793
+ // protected override void OnCreate()
2794
+ // {
2795
+ // base.OnCreate();
2796
+ // }
2797
+ // protected override void OnShow(object param)
2798
+ // {
2799
+ // base.OnShow(param);
2800
+ // var mailContent = (MailContentDialogParam)param;
2801
+ // if (mailContent == null) return;
2802
+ // var mailData = this.GetModel<MailModel>().GetMail(mailContent.MailId);
2803
+ // if (mailData == null) return;
2804
+ // _mailId = mailData.MailId;
2805
+ // m_text_title.text = mailData.Title.TR();
2806
+ // m_text_name.text = $"道友如晤:".TR();
2807
+ // m_text_sender.text = Tr.Format("{0}稽首", mailData.Name);
2808
+ // //转换时区
2809
+ // // var dateTimeOffset = TimeZoneInfo.ConvertTime(DateTimeOffset.FromUnixTimeSeconds(mailData.ReceiveTime), TimeZoneInfo.Local);
2810
+ // m_text_time.text = Date.ConvertTimestampToTimeString(mailData.ReceiveTime, "yyyy年M月d日 HH:mm").TR();
2811
+ // m_scroll_content.title = mailData.Content;
2812
+ // `;
2813
+ // const snippets = extractor.extractStrings(code);
2814
+ // {
2815
+ // let targetSnippet = snippets[0];
2816
+ // expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[_eventIdx]`));
2817
+ // expect(targetSnippet.originalCode).toBe(`_table.MainDescription[_eventIdx]`);
2818
+ // expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[_eventIdx].TR()`);
2819
+ // expect(targetSnippet.literals).toEqual([
2820
+ // ]);
2821
+ // expect(targetSnippet.isChanged).toBe(true);
2822
+ // }
2823
+ // {
2824
+ // let targetSnippet = snippets[1];
2825
+ // expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[0]`));
2826
+ // expect(targetSnippet.originalCode).toBe(`_table.MainDescription[0]`);
2827
+ // expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[0].TR()`);
2828
+ // expect(targetSnippet.literals).toEqual([
2829
+ // ]);
2830
+ // expect(targetSnippet.isChanged).toBe(true);
2831
+ // }
2832
+ // expect(snippets.length).toBe(2);
2833
+ // })
2834
+ // // 测试if语句无花括号包围的单句表达式语句中的字符串表达式处理
2835
+ // test('should handle assignment expression within if-else-end', () => {
2836
+ // const code = `
2837
+ // public void BindData(MailData mailData)
2838
+ // {
2839
+ // if (mailData == null) return;
2840
+ // _mailData = mailData;
2841
+ // //状态
2842
+ // m_hasRead.selectedIndex = _mailData.HasRead ? (int)HasRead.True : (int)HasRead.False;
2843
+ // m_hasFetch.selectedIndex = mailData.Rewards.Count > 0 ? (int)HasFetch.True : (int)HasFetch.False;
2844
+ // m_text_title.text = _mailData.Title.TR();
2845
+ // m_text_subTitle.text = _mailData.SubTitle.TR();
2846
+ // //显示时间
2847
+ // long interval = DateTimeOffset.Now.ToUnixTimeSeconds() - mailData.ReceiveTime;
2848
+ // if (interval <= 0) interval = 1;
2849
+ // if (interval < 60) m_text_time.text = "现在";
2850
+ // else if (interval < 3600) m_text_time.text = $"{interval / 60}分钟前";
2851
+ // else if (interval < 86400) m_text_time.text = $"{interval / 3600}小时前";
2852
+ // else if (interval < 2592000) m_text_time.text = $"{interval / 86400}天前";
2853
+ // else if (interval < 31104000) m_text_time.text = $"{interval / 2592000}月前";
2854
+ // else m_text_time.text = Tr.Format("{0}年前", interval / 31104000);
2855
+ // }
2856
+ // `;
2857
+ // const snippets = extractor.extractStrings(code);
2858
+ // {
2859
+ // let targetSnippet = snippets[0];
2860
+ // expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[_eventIdx]`));
2861
+ // expect(targetSnippet.originalCode).toBe(`_table.MainDescription[_eventIdx]`);
2862
+ // expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[_eventIdx].TR()`);
2863
+ // expect(targetSnippet.literals).toEqual([
2864
+ // ]);
2865
+ // expect(targetSnippet.isChanged).toBe(true);
2866
+ // }
2867
+ // {
2868
+ // let targetSnippet = snippets[1];
2869
+ // expect(targetSnippet.originalIndex).toBe(code.indexOf(`_table.MainDescription[0]`));
2870
+ // expect(targetSnippet.originalCode).toBe(`_table.MainDescription[0]`);
2871
+ // expect(targetSnippet.convertedCode).toBe(`_table.MainDescription[0].TR()`);
2872
+ // expect(targetSnippet.literals).toEqual([
2873
+ // ]);
2874
+ // expect(targetSnippet.isChanged).toBe(true);
2875
+ // }
2876
+ // expect(snippets.length).toBe(2);
2877
+ // })
2687
2878
  });