| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package language
- import (
- "github.com/allanpk716/ChineseSubFinder/internal/pkg/unit_test_helper"
- "os"
- "path/filepath"
- "reflect"
- "testing"
- )
- func TestChangeFileCoding2UTF8(t *testing.T) {
- type args struct {
- subFileFPath string
- }
- tests := []struct {
- name string
- args args
- wantDesSubFileFPath string
- wantErr bool
- }{
- {
- name: "00",
- args: args{
- subFileFPath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"change_sub_encode", "org-utf-8"}, 4, true),
- "Seven.Worlds.One.Planet.S01E01.Antarctica.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT.chinese(简英,subhd).ass"),
- },
- wantDesSubFileFPath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"change_sub_encode", "org-utf-8"}, 4, true),
- "Seven.Worlds.One.Planet.S01E01.Antarctica.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT.chinese(简英,subhd-utf-8).ass"),
- wantErr: false,
- },
- {
- name: "01",
- args: args{
- subFileFPath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"change_sub_encode", "org-utf-8"}, 4, true),
- "Seven.Worlds.One.Planet.S01E07.Africa.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT.chinese(简英,zimuku).default.srt"),
- },
- wantDesSubFileFPath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"change_sub_encode", "org-utf-8"}, 4, true),
- "Seven.Worlds.One.Planet.S01E07.Africa.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT.chinese(简英,zimuku-utf-8).default.srt"),
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- fBytes, err := os.ReadFile(tt.args.subFileFPath)
- if err != nil {
- t.Fatal(err)
- }
- got, err := ChangeFileCoding2UTF8(fBytes)
- if (err != nil) != tt.wantErr {
- t.Errorf("ChangeFileCoding2UTF8() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- wantDesFBytes, err := os.ReadFile(tt.wantDesSubFileFPath)
- if err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(got, wantDesFBytes) {
- t.Errorf("ChangeFileCoding2UTF8() got = %v, want %v", got, wantDesFBytes)
- }
- })
- }
- }
- func TestChangeFileCoding2GBK(t *testing.T) {
- type args struct {
- subFileFPath string
- }
- tests := []struct {
- name string
- args args
- wantDesSubFileFPath string
- wantErr bool
- }{
- {
- name: "00",
- args: args{
- subFileFPath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"change_sub_encode", "org-utf-8"}, 4, true),
- "Seven.Worlds.One.Planet.S01E01.Antarctica.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT.chinese(简英,subhd).ass"),
- },
- wantDesSubFileFPath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"change_sub_encode", "org-utf-8"}, 4, true),
- "Seven.Worlds.One.Planet.S01E01.Antarctica.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT.chinese(简英,subhd-gbk).ass"),
- wantErr: false,
- },
- {
- name: "01",
- args: args{
- subFileFPath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"change_sub_encode", "org-utf-8"}, 4, true),
- "Seven.Worlds.One.Planet.S01E07.Africa.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT.chinese(简英,zimuku).default.srt"),
- },
- wantDesSubFileFPath: filepath.Join(unit_test_helper.GetTestDataResourceRootPath([]string{"change_sub_encode", "org-utf-8"}, 4, true),
- "Seven.Worlds.One.Planet.S01E07.Africa.2160p.BluRay.REMUX.HEVC.DTS-HD.MA.TrueHD.7.1.Atmos-FGT.chinese(简英,zimuku-gbk).default.srt"),
- wantErr: false,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- fBytes, err := os.ReadFile(tt.args.subFileFPath)
- if err != nil {
- t.Fatal(err)
- }
- got, err := ChangeFileCoding2GBK(fBytes)
- if (err != nil) != tt.wantErr {
- t.Errorf("ChangeFileCoding2GBK() error = %v, wantErr %v", err, tt.wantErr)
- return
- }
- wantDesFBytes, err := os.ReadFile(tt.wantDesSubFileFPath)
- if err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(got, wantDesFBytes) {
- t.Errorf("ChangeFileCoding2GBK() got = %v, want %v", got, wantDesFBytes)
- }
- })
- }
- }
|