sub_helper_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package sub_helper
  2. import (
  3. "github.com/allanpk716/ChineseSubFinder/internal/pkg"
  4. "path"
  5. "testing"
  6. )
  7. func TestIsOldVersionSubPrefixName(t *testing.T) {
  8. type args struct {
  9. subFileName string
  10. }
  11. tests := []struct {
  12. name string
  13. args args
  14. want bool
  15. want1 string
  16. want2 string
  17. }{
  18. {name: "chs_en", args: args{subFileName: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chs_en.ass"}, want: true, want1: ".chs_en.ass", want2: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(简英).default.ass"},
  19. {name: "chs[subhd]", args: args{subFileName: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chs[subhd].ass"}, want: true, want1: ".chs[subhd].ass", want2: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(简,subhd).ass"},
  20. {name: "chs_en[shooter]", args: args{subFileName: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chs_en[shooter].ass"}, want: true, want1: ".chs_en[shooter].ass", want2: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(简英,shooter).ass"},
  21. {name: "cht_en[xunlei]", args: args{subFileName: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.cht_en[xunlei].ass"}, want: true, want1: ".cht_en[xunlei].ass", want2: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.chinese(繁英,xunlei).ass"},
  22. {name: "zh", args: args{subFileName: "Loki - S01E01 - Glorious Purpose WEBDL-1080p Proper.zh.ass"}, want: false, want1: "", want2: ""},
  23. }
  24. for _, tt := range tests {
  25. t.Run(tt.name, func(t *testing.T) {
  26. got, got1, got2 := IsOldVersionSubPrefixName(tt.args.subFileName)
  27. if got != tt.want {
  28. t.Errorf("IsOldVersionSubPrefixName() got = %v, want %v", got, tt.want)
  29. }
  30. if got1 != tt.want1 {
  31. t.Errorf("IsOldVersionSubPrefixName() got1 = %v, want %v", got1, tt.want1)
  32. }
  33. if got2 != tt.want2 {
  34. t.Errorf("IsOldVersionSubPrefixName() got2 = %v, want %v", got2, tt.want2)
  35. }
  36. })
  37. }
  38. }
  39. func TestDeleteOneSeasonSubCacheFolder(t *testing.T) {
  40. testDataPath := "..\\..\\..\\TestData\\sub_helper"
  41. testRootDir, err := pkg.CopyTestData(testDataPath)
  42. if err != nil {
  43. t.Fatal(err)
  44. }
  45. err = DeleteOneSeasonSubCacheFolder(testRootDir)
  46. if err != nil {
  47. t.Fatal(err)
  48. }
  49. if pkg.IsDir(path.Join(testRootDir, "Sub_S1E0")) == true {
  50. t.Fatal("Sub_S1E0 not delete")
  51. }
  52. }