Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/utils/search/structs/structs_test.go
akuma06 97b3a1d7ea Remove common package
Common is no more a thing
Use of TorrentParam instead of SearchParam now
Common structs for search are exported in utils/search/structs
Util has been renamed utils
2017-07-02 16:54:55 +02:00

56 lignes
1,3 Kio
Go

package structs
import (
"path"
"testing"
"reflect"
"github.com/NyaaPantsu/nyaa/config"
)
// run before config/parse.go:init()
var _ = func() (_ struct{}) {
config.ConfigPath = path.Join("..", "..", "..", config.ConfigPath)
config.DefaultConfigPath = path.Join("..", "..", "..", config.DefaultConfigPath)
config.Parse()
return
}()
func TestParseCategories(t *testing.T) {
cat := ParseCategories("")
if len(cat) > 0 {
t.Fatal("ParseCategories with empty arg doesn't return an empty array")
}
cat = ParseCategories("5050")
if len(cat) > 0 {
t.Fatal("ParseCategories with wrong arg doesn't return an empty array")
}
cat = ParseCategories("50_50")
if len(cat) > 0 {
t.Fatal("ParseCategories with wrong arg doesn't return an empty array")
}
cat = ParseCategories("3_13")
if len(cat) == 0 {
t.Fatal("ParseCategories with good arg return an empty array")
}
cat = ParseCategories("3_13,3_5")
catEqual := []*Category{
&Category{
Main: 3,
Sub: 13,
},
&Category{
Main: 3,
Sub: 5,
},
}
if !reflect.DeepEqual(cat, catEqual) {
t.Fatal("ParseCategories with good arg doesn't return the right array")
}
cat = ParseCategories("3_13,3_5,5_50")
if !reflect.DeepEqual(cat, catEqual) {
t.Fatal("ParseCategories doesn't filter the wrong categories")
}
}