add field test/update filter test

master
Oliver Tonnhofer 2013-05-21 07:08:24 +02:00
parent c4fb0d8a21
commit 564344096b
2 changed files with 57 additions and 6 deletions

37
mapping/fields_test.go Normal file
View File

@ -0,0 +1,37 @@
package mapping
import (
"testing"
)
func TestBool(t *testing.T) {
match := Match{}
if false != Bool("", nil, match) {
t.Fatal()
}
if false != Bool("false", nil, match) {
t.Fatal()
}
if false != Bool("no", nil, match) {
t.Fatal()
}
if false != Bool("0", nil, match) {
t.Fatal()
}
if true != Bool("yes", nil, match) {
t.Fatal()
}
if true != Bool("1", nil, match) {
t.Fatal()
}
if true != Bool("true", nil, match) {
t.Fatal()
}
// Bool defaults to true
if true != Bool("other", nil, match) {
t.Fatal()
}
}

View File

@ -23,7 +23,7 @@ func TestFilterNodes(t *testing.T) {
tags["name"] = "foo"
points := mapping.NodeTagFilter()
if points.Filter(tags) != false {
if points.Filter(&tags) != false {
t.Fatal("Filter result not false")
}
if len(tags) != 0 {
@ -35,23 +35,37 @@ func TestFilterNodes(t *testing.T) {
tags["name"] = "foo"
tags["boring"] = "true"
if points.Filter(tags) != false {
if points.Filter(&tags) != false {
t.Fatal("Filter result not false")
}
if len(tags) != 0 {
t.Fatal("Filter result not empty")
}
// test __any__
// test fields only, but no mapping
tags = make(element.Tags)
tags["population"] = "0"
tags["name"] = "foo"
tags["boring"] = "true"
if points.Filter(tags) != true {
if points.Filter(&tags) != false {
t.Fatal("Filter result true", tags)
}
if len(tags) != 2 && tags["population"] == "0" && tags["name"] == "foo" {
if len(tags) != 0 {
t.Fatal("Filter result not empty", tags)
}
// ... not with mapped tag (place)
tags = make(element.Tags)
tags["population"] = "0"
tags["name"] = "foo"
tags["boring"] = "true"
tags["place"] = "village"
if points.Filter(&tags) != true {
t.Fatal("Filter result true", tags)
}
if len(tags) != 3 && tags["population"] == "0" && tags["name"] == "foo" && tags["place"] == "village" {
t.Fatal("Filter result not expected", tags)
}
@ -68,7 +82,7 @@ func BenchmarkFilterNodes(b *testing.B) {
tags["boring"] = "true"
points := mapping.NodeTagFilter()
if points.Filter(tags) != true {
if points.Filter(&tags) != true {
b.Fatal("Filter result true", tags)
}
if len(tags) != 2 && tags["population"] == "0" && tags["name"] == "foo" {