diff --git a/mapping/fields_test.go b/mapping/fields_test.go new file mode 100644 index 0000000..54a3412 --- /dev/null +++ b/mapping/fields_test.go @@ -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() + } + +} diff --git a/mapping/filter_test.go b/mapping/filter_test.go index 0c91ce9..d2d1a17 100644 --- a/mapping/filter_test.go +++ b/mapping/filter_test.go @@ -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" {