sub_helper_test.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package sub_helper
  2. import (
  3. "fmt"
  4. "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/ass"
  5. "github.com/allanpk716/ChineseSubFinder/internal/logic/sub_parser/srt"
  6. "github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
  7. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_parser_hub"
  8. "path/filepath"
  9. "testing"
  10. )
  11. func TestDeleteOneSeasonSubCacheFolder(t *testing.T) {
  12. testDataPath := "../../../TestData/sub_helper"
  13. testRootDir, err := my_util.CopyTestData(testDataPath)
  14. if err != nil {
  15. t.Fatal(err)
  16. }
  17. err = DeleteOneSeasonSubCacheFolder(testRootDir)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. if my_util.IsDir(filepath.Join(testRootDir, "Sub_S1E0")) == true {
  22. t.Fatal("Sub_S1E0 not delete")
  23. }
  24. }
  25. func TestGetVADInfosFromSub(t *testing.T) {
  26. // 这两个字幕是一样的,只不过是格式不同而已
  27. subParserHub := sub_parser_hub.NewSubParserHub(ass.NewParser(), srt.NewParser())
  28. baseSubFile := "C:\\Tmp\\Rick and Morty - S05E01\\英_2.srt"
  29. srcSubFile := "C:\\Tmp\\Rick and Morty - S05E01\\英_2.ass"
  30. bFind, infoBase, err := subParserHub.DetermineFileTypeFromFile(baseSubFile)
  31. if err != nil {
  32. t.Fatal(err)
  33. }
  34. if bFind == false {
  35. t.Fatal("sub not match")
  36. }
  37. bFind, infoSrc, err := subParserHub.DetermineFileTypeFromFile(srcSubFile)
  38. if err != nil {
  39. t.Fatal(err)
  40. }
  41. if bFind == false {
  42. t.Fatal("sub not match")
  43. }
  44. if len(infoBase.DialoguesFilterEx) != len(infoSrc.DialoguesFilterEx) {
  45. t.Fatal(fmt.Sprintf("info Base And Src Parse Error, infoBase.DialoguesFilterEx Len = %v, infoSrc.DialoguesFilterEx Len = %v",
  46. len(infoBase.DialoguesFilterEx), len(infoSrc.DialoguesFilterEx)))
  47. }
  48. baseSubUnit, err := GetVADInfoFeatureFromSubNew(infoBase, FrontAndEndPerBase)
  49. if err != nil {
  50. t.Fatal(err)
  51. }
  52. srcSubUnit, err := GetVADInfoFeatureFromSubNew(infoSrc, FrontAndEndPerBase)
  53. if err != nil {
  54. t.Fatal(err)
  55. }
  56. if len(baseSubUnit.VADList) != len(srcSubUnit.VADList) {
  57. t.Fatal(fmt.Sprintf("info Base And Src Parse Error, infoBase.VADList Len = %v, infoSrc.VADList Len = %v",
  58. len(baseSubUnit.VADList), len(srcSubUnit.VADList)))
  59. }
  60. for i := 0; i < len(baseSubUnit.VADList); i++ {
  61. if baseSubUnit.VADList[i] != srcSubUnit.VADList[i] {
  62. println(fmt.Sprintf("base src VADList i=%v, not the same", i))
  63. }
  64. }
  65. }
  66. const FrontAndEndPerBase = 0