sub_helper_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package sub_helper
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. "testing"
  6. "github.com/ChineseSubFinder/ChineseSubFinder/pkg"
  7. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/log_helper"
  8. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/logic/sub_parser/ass"
  9. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/logic/sub_parser/srt"
  10. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/sub_parser_hub"
  11. "github.com/ChineseSubFinder/ChineseSubFinder/pkg/unit_test_helper"
  12. )
  13. func TestDeleteOneSeasonSubCacheFolder(t *testing.T) {
  14. const testSerName = "XXX"
  15. const needDelFolderName = "Sub_S1E0"
  16. testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_helper", "org", needDelFolderName}, 4, false)
  17. desSerFullPath, err := pkg.GetDebugFolderByName([]string{testSerName})
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. desSeasonFullPath, err := pkg.GetDebugFolderByName([]string{testSerName, filepath.Base(testRootDir)})
  22. if err != nil {
  23. t.Fatal(err)
  24. }
  25. err = pkg.CopyDir(testRootDir, desSeasonFullPath)
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. err = DeleteOneSeasonSubCacheFolder(desSerFullPath)
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. if pkg.IsDir(desSeasonFullPath) == true {
  34. t.Fatal("Sub_S1E0 not delete")
  35. }
  36. }
  37. func TestGetVADInfosFromSub(t *testing.T) {
  38. log := log_helper.GetLogger4Tester()
  39. // 这两个字幕是一样的,只不过是格式不同而已
  40. subParserHub := sub_parser_hub.NewSubParserHub(log, ass.NewParser(log), srt.NewParser(log))
  41. testRootDir := unit_test_helper.GetTestDataResourceRootPath([]string{"sub_helper", "org", "R&M-S05E10"}, 4, false)
  42. baseSubFile := filepath.Join(testRootDir, "Rick and Morty - S05E10 - Rickmurai Jack WEBRip-1080p.chinese(简,zimuku).default.srt")
  43. srcSubFile := filepath.Join(testRootDir, "Rick and Morty - S05E10 - Rickmurai Jack WEBRip-1080p.chinese(简英,zimuku).ass")
  44. bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(baseSubFile)
  45. if err != nil {
  46. t.Fatal(err)
  47. }
  48. if bFind == false {
  49. t.Fatal("sub not match")
  50. }
  51. bFind, infoSrc, err := subParserHub.DetermineFileTypeFromFile(srcSubFile)
  52. if err != nil {
  53. t.Fatal(err)
  54. }
  55. if bFind == false {
  56. t.Fatal("sub not match")
  57. }
  58. if len(infoBase.Dialogues) != len(infoSrc.Dialogues) {
  59. t.Fatal(fmt.Sprintf("info Base And Src Parse Error, infoBase.DialoguesFilterEx Len = %v, infoSrc.DialoguesFilterEx Len = %v",
  60. len(infoBase.Dialogues), len(infoSrc.Dialogues)))
  61. }
  62. baseSubUnit, err := GetVADInfoFeatureFromSubNew(infoBase, FrontAndEndPerBase)
  63. if err != nil {
  64. t.Fatal(err)
  65. }
  66. srcSubUnit, err := GetVADInfoFeatureFromSubNew(infoSrc, FrontAndEndPerBase)
  67. if err != nil {
  68. t.Fatal(err)
  69. }
  70. if len(baseSubUnit.VADList) != len(srcSubUnit.VADList) {
  71. t.Fatal(fmt.Sprintf("info Base And Src Parse Error, infoBase.VADList Len = %v, infoSrc.VADList Len = %v",
  72. len(baseSubUnit.VADList), len(srcSubUnit.VADList)))
  73. }
  74. for i := 0; i < len(baseSubUnit.VADList); i++ {
  75. if baseSubUnit.VADList[i] != srcSubUnit.VADList[i] {
  76. println(fmt.Sprintf("base src VADList i=%v, not the same", i))
  77. }
  78. }
  79. }
  80. const FrontAndEndPerBase = 0