hot_fix_001_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package hot_fix
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  4. "path/filepath"
  5. "testing"
  6. )
  7. func TestHotFix001_GetKey(t *testing.T) {
  8. hf001 := NewHotFix001("", "")
  9. if hf001.GetKey() != "001" {
  10. t.Fatal("GetKey() != 001")
  11. }
  12. }
  13. func TestHotFix001_Process(t *testing.T) {
  14. testDataPath := "../../../TestData/hotfix/001"
  15. movieDir := "movies"
  16. seriesDir := "series"
  17. testRootDir, err := my_util.CopyTestData(testDataPath)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. // 测试文件夹
  22. testMovieDir := filepath.Join(testRootDir, movieDir)
  23. testSeriesDir := filepath.Join(testRootDir, seriesDir)
  24. // 开始修复
  25. hf001 := NewHotFix001(testMovieDir, testSeriesDir)
  26. outData, err := hf001.Process()
  27. outStruct := outData.(OutStruct001)
  28. if err != nil {
  29. for _, file := range outStruct.ErrFiles {
  30. println("rename error:", file)
  31. }
  32. t.Fatal("Process ", err.Error())
  33. }
  34. if len(outStruct.RenamedFiles) < 1 {
  35. t.Fatal("hf001.Process() not file processed")
  36. }
  37. // 检查修复的结果是否符合预期
  38. var newSubFileNameMap = make(map[string]int)
  39. for i, s := range outStruct.RenamedFiles {
  40. if my_util.IsFile(s) == false {
  41. t.Fatal("renamed file not found:", s)
  42. }
  43. newSubFileNameMap[filepath.Base(s)] = i
  44. }
  45. // 21座桥 (2019) 720p AAC.chs[subhd].ass
  46. // 21座桥 (2019) 720p AAC.chs_en[zimuku].ass
  47. // 无罪之最 - S01E01 - 重建生活.chs[shooter].ass
  48. // 无罪之最 - S01E01 - 重建生活.chs[subhd].ass
  49. // 无罪之最 - S01E01 - 重建生活.chs[zimuku].ass
  50. // Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chs_en[zimuku].srt
  51. // Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.cht_en[shooter].ass
  52. var checkResults = []string{
  53. "21座桥 (2019) 720p AAC.chinese(简,subhd).ass",
  54. "21座桥 (2019) 720p AAC.chinese(简英,zimuku).ass",
  55. "无罪之最 - S01E01 - 重建生活.chinese(简,shooter).ass",
  56. "无罪之最 - S01E01 - 重建生活.chinese(简,subhd).ass",
  57. "无罪之最 - S01E01 - 重建生活.chinese(简,zimuku).ass",
  58. "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(简英,zimuku).srt",
  59. "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(繁英,shooter).ass",
  60. }
  61. if len(outStruct.RenamedFiles) != len(checkResults) {
  62. t.Fatal("newSubFileName.len != checkResults.len")
  63. }
  64. for _, result := range checkResults {
  65. _, bok := newSubFileNameMap[result]
  66. if bok == false {
  67. t.Fatal("renamed file name not fit:", result)
  68. }
  69. }
  70. }