mirror of
https://github.com/rumanzo/bt2qbt.git
synced 2024-11-25 20:02:28 +01:00
fda659db74
* cesu8 handler * resume file cesu8 handle * utf8 emoji filepaths * cesu8 emoji filepaths and torrent names * cesu8 emoji filepaths and torrent names handling improve tests * add fastresume Name field * update golang ver * handle torrent files with cesu8 encoded file paths and handle them as NoSubfolder torrents for better compatibility * fix cesu8 named single file torrents
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package helpers
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetStrings(t *testing.T) {
|
|
testTrackers := []interface{}{
|
|
"test1",
|
|
"test2",
|
|
[]interface{}{
|
|
"test3",
|
|
"test4",
|
|
[]interface{}{
|
|
"test5",
|
|
"test6",
|
|
},
|
|
},
|
|
[]interface{}{
|
|
[]interface{}{"test7", "test8"},
|
|
},
|
|
}
|
|
expect := []string{"test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8"}
|
|
trackers := GetStrings(testTrackers)
|
|
if !reflect.DeepEqual(trackers, expect) {
|
|
t.Fatalf("Unexpected error: opts isn't equal:\n Got: %#v\n Expect %#v\n", trackers, expect)
|
|
}
|
|
}
|
|
|
|
func TestDecodeTorrentFile(t *testing.T) {
|
|
type PathJoinCase struct {
|
|
name string
|
|
mustFail bool
|
|
path string
|
|
}
|
|
cases := []PathJoinCase{
|
|
{
|
|
name: "001 not existing file",
|
|
path: "notexists.torrent",
|
|
mustFail: true,
|
|
},
|
|
{
|
|
name: "002 existing file",
|
|
path: "../../test/data/testfileset.torrent",
|
|
},
|
|
}
|
|
for _, testCase := range cases {
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
var decoded interface{}
|
|
err := DecodeTorrentFile(testCase.path, &decoded)
|
|
if err != nil && !testCase.mustFail {
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
} else if err == nil && testCase.mustFail {
|
|
t.Fatalf("Test must fail, but it doesn't")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
func TestEmojiCesu8(t *testing.T) {
|
|
cesu8 := "normal_text \xed\xa0\xbc\xed\xb6\x95 normal_text \xed\xa0\xbd\xed\xba\x9c.txt.torrent"
|
|
utf8 := "normal_text \xf0\x9f\x86\x95 normal_text \xf0\x9f\x9a\x9c.txt.torrent"
|
|
if utf8 != HandleCesu8(cesu8) {
|
|
t.Fatalf("Cesu8 to utf-8 transformation fail")
|
|
}
|
|
}
|