hot_fix_001_test.go 2.4 KB

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