golifehk/query/query_test.go

80 lines
1.6 KiB
Go

package query
import (
"testing"
)
type TestItem struct {
Searchable
}
func TestQuery( t *testing.T ) {
testItems := [] ISearchable{}
s1234 := "1234"
sApple := "Apple"
s0000 := "0000"
sDat0 := "Dat0"
data0 := [] *string{}
data0 = append( data0, &s1234 )
data0 = append( data0, &sApple )
t0 := TestItem{}
t0.Key = &sDat0
t0.SearchData = &data0
testItems = append( testItems, &t0 )
sDat1 := "Dat1"
data1 := [] *string{}
data1 = append( data1, &s0000 )
data1 = append( data1, &sApple )
t1 := TestItem{}
t1.Key = &sDat1
t1.SearchData = &data1
testItems = append( testItems, &t1 )
sDat2 := "Dat2"
data2 := [] *string{}
data2 = append( data2, &sDat0 )
t2 := TestItem{}
t2.Key = &sDat2
t2.SearchData = &data2
testItems = append( testItems, &t2 )
qo, err := Parse( "Apple", &testItems )
if err != nil {
t.Error( err )
}
if len(*qo.Results) != 2 {
t.Error( "Expected 2 results when searching for \"Apple\"" )
}
qo, err = Parse( "0000", &testItems )
if err != nil {
t.Error( err )
}
if len(*qo.Results) != 1 {
t.Error( "Expected 1 results when searching for \"0000\"" )
}
qo, err = Parse( "Dat0", &testItems )
if err != nil {
t.Error( err )
}
if len(*qo.Results) != 1 {
t.Error( "Expected 1 results when searching for \"Dat0\"" )
}
qo, err = Parse( "Dat2 Dat0", &testItems )
if err != nil {
t.Error( err )
}
if len(*qo.Results) != 1 {
t.Error( "Expected 1 results when searching for \"Dat2 Dat0\"" )
}
}