sub_helper_test.go 2.9 KB

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