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 713ab02450 Added configor as a new library (#1126)
* Added configor as a new library

Now config is a singleton. You only need to do config.Get() instead of doing config.Conf.

* Forgot godep save 🐤

* Fix accidental removal of }
2017-07-10 22:11:05 +10: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.Reload()
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")
}
}