hot_fix_001_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. newSubFileName, errFiles, err := hf001.Process()
  28. if err != nil {
  29. for _, file := range errFiles {
  30. println("rename error:", file)
  31. }
  32. t.Fatal("Process ", err.Error())
  33. }
  34. if len(newSubFileName) < 1 {
  35. t.Fatal("hf001.Process() not file processed")
  36. }
  37. // 检查修复的结果是否符合预期
  38. var newSubFileNameMap = make(map[string]int)
  39. for i, s := range newSubFileName {
  40. if pkg.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(newSubFileName) != 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. }