2013-05-07 12:13:09 +04:00
|
|
|
package mapping
|
|
|
|
|
|
|
|
import (
|
2015-07-17 11:07:55 +03:00
|
|
|
"reflect"
|
2013-05-07 12:13:09 +04:00
|
|
|
"testing"
|
2015-07-17 11:07:55 +03:00
|
|
|
|
|
|
|
"github.com/omniscale/imposm3/element"
|
2013-05-07 12:13:09 +04:00
|
|
|
)
|
|
|
|
|
2013-05-17 17:55:31 +04:00
|
|
|
var mapping *Mapping
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var err error
|
2015-08-11 20:22:01 +03:00
|
|
|
mapping, err = NewMapping("./test_mapping.yml")
|
2013-05-17 17:55:31 +04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 16:55:21 +03:00
|
|
|
func stringMapEqual(expected, actual map[string]string) bool {
|
|
|
|
if len(expected) != len(actual) {
|
|
|
|
return false
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range expected {
|
|
|
|
if actualV, ok := actual[k]; ok {
|
|
|
|
if actualV != v {
|
2017-05-09 16:55:21 +03:00
|
|
|
return false
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-09 16:55:21 +03:00
|
|
|
return false
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
}
|
2017-05-09 16:55:21 +03:00
|
|
|
return true
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
func matchesEqual(expected []Match, actual []Match) bool {
|
2013-05-27 13:24:22 +04:00
|
|
|
expectedMatches := make(map[DestTable]Match)
|
|
|
|
actualMatches := make(map[DestTable]Match)
|
2013-05-23 16:05:09 +04:00
|
|
|
|
|
|
|
if len(expected) != len(actual) {
|
2017-05-10 15:23:32 +03:00
|
|
|
return false
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, match := range expected {
|
|
|
|
expectedMatches[match.Table] = match
|
|
|
|
}
|
|
|
|
for _, match := range actual {
|
|
|
|
actualMatches[match.Table] = match
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, expectedMatch := range expectedMatches {
|
|
|
|
if actualMatch, ok := actualMatches[name]; ok {
|
|
|
|
if expectedMatch.Table != actualMatch.Table ||
|
|
|
|
expectedMatch.Key != actualMatch.Key ||
|
|
|
|
expectedMatch.Value != actualMatch.Value {
|
2017-05-10 15:23:32 +03:00
|
|
|
return false
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-10 15:23:32 +03:00
|
|
|
return false
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
}
|
2017-05-10 15:23:32 +03:00
|
|
|
return true
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTagFilterNodes(t *testing.T) {
|
2017-05-09 16:55:21 +03:00
|
|
|
tests := []struct {
|
|
|
|
tags element.Tags
|
|
|
|
expected element.Tags
|
|
|
|
}{
|
|
|
|
{tags: element.Tags{}, expected: element.Tags{}},
|
|
|
|
{tags: element.Tags{"name": "foo"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "unknown": "foo"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "place": "unknown"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "place": "unknown", "population": "1000"}, expected: element.Tags{"name": "foo", "population": "1000"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "place": "village"}, expected: element.Tags{"name": "foo", "place": "village"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "place": "village", "population": "1000"}, expected: element.Tags{"name": "foo", "place": "village", "population": "1000"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "place": "village", "unknown": "foo"}, expected: element.Tags{"name": "foo", "place": "village"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "place": "village", "highway": "bus_stop"}, expected: element.Tags{"name": "foo", "place": "village", "highway": "bus_stop"}},
|
2013-05-24 15:24:02 +04:00
|
|
|
}
|
|
|
|
|
2017-05-09 16:55:21 +03:00
|
|
|
nodes := mapping.NodeTagFilter()
|
|
|
|
for i, test := range tests {
|
|
|
|
nodes.Filter(&test.tags)
|
|
|
|
if !stringMapEqual(test.tags, test.expected) {
|
|
|
|
t.Errorf("unexpected result for case %d: %v != %v", i+1, test.tags, test.expected)
|
|
|
|
}
|
2013-05-24 15:24:02 +04:00
|
|
|
}
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTagFilterWays(t *testing.T) {
|
2017-05-09 16:55:21 +03:00
|
|
|
tests := []struct {
|
|
|
|
tags element.Tags
|
|
|
|
expected element.Tags
|
|
|
|
}{
|
|
|
|
{tags: element.Tags{}, expected: element.Tags{}},
|
|
|
|
{tags: element.Tags{"name": "foo"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "unknown": "foo"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "highway": "unknown"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "highway": "track"}, expected: element.Tags{"name": "foo", "highway": "track"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "building": "whatever"}, expected: element.Tags{"name": "foo", "building": "whatever"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "highway": "track", "unknown": "foo"}, expected: element.Tags{"name": "foo", "highway": "track"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "place": "village", "highway": "track"}, expected: element.Tags{"name": "foo", "highway": "track"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "highway": "track", "oneway": "yes", "tunnel": "1"}, expected: element.Tags{"name": "foo", "highway": "track", "oneway": "yes", "tunnel": "1"}},
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
2017-05-09 16:55:21 +03:00
|
|
|
ways := mapping.WayTagFilter()
|
|
|
|
for i, test := range tests {
|
|
|
|
ways.Filter(&test.tags)
|
|
|
|
if !stringMapEqual(test.tags, test.expected) {
|
|
|
|
t.Errorf("unexpected result for case %d: %v != %v", i+1, test.tags, test.expected)
|
|
|
|
}
|
2013-05-24 15:24:02 +04:00
|
|
|
}
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTagFilterRelations(t *testing.T) {
|
2017-05-09 16:55:21 +03:00
|
|
|
tests := []struct {
|
|
|
|
tags element.Tags
|
|
|
|
expected element.Tags
|
|
|
|
}{
|
|
|
|
{tags: element.Tags{}, expected: element.Tags{}},
|
|
|
|
{tags: element.Tags{"name": "foo"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "unknown": "foo"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "landuse": "unknown"}, expected: element.Tags{"name": "foo"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "landuse": "farm"}, expected: element.Tags{"name": "foo", "landuse": "farm"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "landuse": "farm", "type": "multipolygon"}, expected: element.Tags{"name": "foo", "landuse": "farm", "type": "multipolygon"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "type": "multipolygon"}, expected: element.Tags{"name": "foo", "type": "multipolygon"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "type": "boundary"}, expected: element.Tags{"name": "foo", "type": "boundary"}},
|
|
|
|
{tags: element.Tags{"name": "foo", "landuse": "farm", "type": "boundary"}, expected: element.Tags{"name": "foo", "landuse": "farm", "type": "boundary"}},
|
2013-05-24 15:24:02 +04:00
|
|
|
}
|
|
|
|
|
2017-05-09 16:55:21 +03:00
|
|
|
relations := mapping.RelationTagFilter()
|
|
|
|
for i, test := range tests {
|
|
|
|
relations.Filter(&test.tags)
|
|
|
|
if !stringMapEqual(test.tags, test.expected) {
|
|
|
|
t.Errorf("unexpected result for case %d: %v != %v", i+1, test.tags, test.expected)
|
|
|
|
}
|
2013-05-24 15:24:02 +04:00
|
|
|
}
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPointMatcher(t *testing.T) {
|
2017-05-10 15:23:32 +03:00
|
|
|
tests := []struct {
|
|
|
|
tags element.Tags
|
|
|
|
matches []Match
|
|
|
|
}{
|
|
|
|
{element.Tags{"unknown": "baz"}, []Match{}},
|
|
|
|
{element.Tags{"place": "unknown"}, []Match{}},
|
|
|
|
{element.Tags{"place": "city"}, []Match{{"place", "city", DestTable{Name: "places"}, nil}}},
|
|
|
|
{element.Tags{"place": "city", "highway": "unknown"}, []Match{{"place", "city", DestTable{Name: "places"}, nil}}},
|
|
|
|
{element.Tags{"place": "city", "highway": "bus_stop"}, []Match{
|
2015-09-25 12:27:56 +03:00
|
|
|
{"place", "city", DestTable{Name: "places"}, nil},
|
|
|
|
{"highway", "bus_stop", DestTable{Name: "transport_points"}, nil}},
|
2017-05-10 15:23:32 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
elem := element.Node{}
|
|
|
|
m := mapping.PointMatcher()
|
|
|
|
for i, test := range tests {
|
|
|
|
elem.Tags = test.tags
|
|
|
|
actual := m.MatchNode(&elem)
|
|
|
|
if !matchesEqual(actual, test.matches) {
|
|
|
|
t.Errorf("unexpected result for case %d: %v != %v", i+1, actual, test.matches)
|
|
|
|
}
|
|
|
|
}
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLineStringMatcher(t *testing.T) {
|
2017-05-10 15:23:32 +03:00
|
|
|
tests := []struct {
|
|
|
|
tags element.Tags
|
|
|
|
matches []Match
|
|
|
|
}{
|
|
|
|
{element.Tags{"unknown": "baz"}, []Match{}},
|
|
|
|
{element.Tags{"highway": "unknown"}, []Match{}},
|
|
|
|
{element.Tags{"highway": "pedestrian"},
|
|
|
|
[]Match{{"highway", "pedestrian", DestTable{Name: "roads", SubMapping: "roads"}, nil}}},
|
|
|
|
|
|
|
|
// exclude_tags area=yes
|
|
|
|
{element.Tags{"highway": "pedestrian", "area": "yes"}, []Match{}},
|
|
|
|
|
|
|
|
{element.Tags{"barrier": "hedge"},
|
|
|
|
[]Match{{"barrier", "hedge", DestTable{Name: "barrierways"}, nil}}},
|
|
|
|
{element.Tags{"barrier": "hedge", "area": "yes"}, []Match{}},
|
|
|
|
|
|
|
|
{element.Tags{"aeroway": "runway"}, []Match{}},
|
|
|
|
{element.Tags{"aeroway": "runway", "area": "no"},
|
|
|
|
[]Match{{"aeroway", "runway", DestTable{Name: "aeroways"}, nil}}},
|
|
|
|
|
|
|
|
{element.Tags{"highway": "secondary", "railway": "tram"},
|
|
|
|
[]Match{
|
|
|
|
{"highway", "secondary", DestTable{Name: "roads", SubMapping: "roads"}, nil},
|
|
|
|
{"railway", "tram", DestTable{Name: "roads", SubMapping: "railway"}, nil}},
|
|
|
|
},
|
|
|
|
{element.Tags{"highway": "footway", "landuse": "park", "barrier": "hedge"},
|
|
|
|
// landusages not a linestring table
|
|
|
|
[]Match{
|
|
|
|
{"highway", "footway", DestTable{Name: "roads", SubMapping: "roads"}, nil},
|
|
|
|
{"barrier", "hedge", DestTable{Name: "barrierways"}, nil}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2014-06-19 13:51:15 +04:00
|
|
|
elem := element.Way{}
|
2016-11-10 13:00:34 +03:00
|
|
|
// fake closed way for area matching
|
|
|
|
elem.Refs = []int64{1, 2, 3, 4, 1}
|
|
|
|
if !elem.IsClosed() {
|
|
|
|
t.Fatal("way not closed")
|
|
|
|
}
|
2017-05-10 15:23:32 +03:00
|
|
|
m := mapping.LineStringMatcher()
|
|
|
|
for i, test := range tests {
|
|
|
|
elem.Tags = test.tags
|
|
|
|
actual := m.MatchWay(&elem)
|
|
|
|
if !matchesEqual(actual, test.matches) {
|
|
|
|
t.Errorf("unexpected result for case %d: %v != %v", i+1, actual, test.matches)
|
|
|
|
}
|
|
|
|
}
|
2013-05-23 16:05:09 +04:00
|
|
|
}
|
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
func TestPolygonMatcher_MatchWay(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
tags element.Tags
|
|
|
|
matches []Match
|
|
|
|
}{
|
|
|
|
{element.Tags{}, []Match{}},
|
|
|
|
{element.Tags{"unknown": "baz"}, []Match{}},
|
|
|
|
{element.Tags{"landuse": "unknown"}, []Match{}},
|
|
|
|
{element.Tags{"landuse": "unknown", "type": "multipolygon"}, []Match{}},
|
|
|
|
{element.Tags{"building": "yes"}, []Match{{"building", "yes", DestTable{Name: "buildings"}, nil}}},
|
|
|
|
{element.Tags{"building": "residential"}, []Match{{"building", "residential", DestTable{Name: "buildings"}, nil}}},
|
|
|
|
// line type requires area=yes
|
|
|
|
{element.Tags{"barrier": "hedge"}, []Match{}},
|
|
|
|
{element.Tags{"barrier": "hedge", "area": "yes"}, []Match{{"barrier", "hedge", DestTable{Name: "landusages"}, nil}}},
|
|
|
|
|
|
|
|
{element.Tags{"building": "shop"}, []Match{
|
|
|
|
{"building", "shop", DestTable{Name: "buildings"}, nil},
|
|
|
|
{"building", "shop", DestTable{Name: "amenity_areas"}, nil},
|
|
|
|
}},
|
|
|
|
|
|
|
|
{element.Tags{"aeroway": "apron", "landuse": "farm"}, []Match{
|
|
|
|
{"aeroway", "apron", DestTable{Name: "transport_areas"}, nil},
|
|
|
|
{"landuse", "farm", DestTable{Name: "landusages"}, nil},
|
|
|
|
}},
|
|
|
|
|
|
|
|
{element.Tags{"landuse": "farm", "highway": "secondary"}, []Match{
|
|
|
|
{"landuse", "farm", DestTable{Name: "landusages"}, nil},
|
|
|
|
}},
|
|
|
|
|
|
|
|
{element.Tags{"highway": "footway"}, []Match{}},
|
|
|
|
{element.Tags{"highway": "footway", "area": "yes"}, []Match{
|
|
|
|
{"highway", "footway", DestTable{Name: "landusages"}, nil},
|
|
|
|
}},
|
|
|
|
|
|
|
|
{element.Tags{"boundary": "administrative", "admin_level": "8"}, []Match{{"boundary", "administrative", DestTable{Name: "admin"}, nil}}},
|
|
|
|
|
|
|
|
/*
|
|
|
|
landusages mapping has the following order,
|
|
|
|
check that XxxMatcher always uses the first
|
|
|
|
|
|
|
|
amenity:
|
|
|
|
- university
|
|
|
|
landuse:
|
|
|
|
- forest
|
|
|
|
leisure:
|
|
|
|
- park
|
|
|
|
landuse:
|
|
|
|
- park
|
|
|
|
*/
|
|
|
|
|
|
|
|
{element.Tags{"landuse": "forest", "leisure": "park"}, []Match{{"landuse", "forest", DestTable{Name: "landusages"}, nil}}},
|
|
|
|
{element.Tags{"landuse": "park", "leisure": "park"}, []Match{{"leisure", "park", DestTable{Name: "landusages"}, nil}}},
|
|
|
|
{element.Tags{"landuse": "park", "leisure": "park", "amenity": "university"}, []Match{{"amenity", "university", DestTable{Name: "landusages"}, nil}}},
|
|
|
|
}
|
2013-05-23 16:05:09 +04:00
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
elem := element.Way{}
|
|
|
|
// fake closed way for area matching
|
|
|
|
elem.Refs = []int64{1, 2, 3, 4, 1}
|
|
|
|
if !elem.IsClosed() {
|
|
|
|
t.Fatal("way not closed")
|
|
|
|
}
|
|
|
|
m := mapping.PolygonMatcher()
|
|
|
|
for i, test := range tests {
|
|
|
|
elem.Tags = test.tags
|
|
|
|
actual := m.MatchWay(&elem)
|
|
|
|
if !matchesEqual(actual, test.matches) {
|
|
|
|
t.Errorf("unexpected result for case %d: %v != %v", i+1, actual, test.matches)
|
|
|
|
}
|
|
|
|
}
|
2013-05-24 15:24:02 +04:00
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
elem.Refs = nil
|
2014-06-19 13:51:15 +04:00
|
|
|
elem.Tags = element.Tags{"building": "yes"}
|
2017-05-10 15:23:32 +03:00
|
|
|
actual := m.MatchWay(&elem)
|
|
|
|
if !matchesEqual([]Match{}, actual) {
|
|
|
|
t.Error("open way matched as polygon")
|
|
|
|
}
|
|
|
|
}
|
2013-05-24 15:24:02 +04:00
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
func TestPolygonMatcher_MatchRelation(t *testing.T) {
|
|
|
|
// check that only relations with type=multipolygon/boundary are matched as polygon
|
2013-05-24 15:24:02 +04:00
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
tests := []struct {
|
|
|
|
tags element.Tags
|
|
|
|
matches []Match
|
|
|
|
}{
|
|
|
|
{element.Tags{}, []Match{}},
|
|
|
|
{element.Tags{"unknown": "baz"}, []Match{}},
|
|
|
|
{element.Tags{"landuse": "unknown"}, []Match{}},
|
|
|
|
{element.Tags{"landuse": "unknown", "type": "multipolygon"}, []Match{}},
|
|
|
|
{element.Tags{"building": "yes"}, []Match{}},
|
|
|
|
{element.Tags{"building": "yes", "type": "multipolygon"}, []Match{{"building", "yes", DestTable{Name: "buildings"}, nil}}},
|
|
|
|
{element.Tags{"building": "residential", "type": "multipolygon"}, []Match{{"building", "residential", DestTable{Name: "buildings"}, nil}}},
|
|
|
|
// line type requires area=yes
|
|
|
|
{element.Tags{"barrier": "hedge", "type": "multipolygon"}, []Match{}},
|
|
|
|
{element.Tags{"barrier": "hedge", "area": "yes", "type": "multipolygon"}, []Match{{"barrier", "hedge", DestTable{Name: "landusages"}, nil}}},
|
|
|
|
|
|
|
|
{element.Tags{"building": "shop", "type": "multipolygon"}, []Match{
|
|
|
|
{"building", "shop", DestTable{Name: "buildings"}, nil},
|
|
|
|
{"building", "shop", DestTable{Name: "amenity_areas"}, nil},
|
|
|
|
}},
|
|
|
|
|
|
|
|
{element.Tags{"aeroway": "apron", "landuse": "farm", "type": "multipolygon"}, []Match{
|
2015-09-25 12:27:56 +03:00
|
|
|
{"aeroway", "apron", DestTable{Name: "transport_areas"}, nil},
|
2017-05-10 15:23:32 +03:00
|
|
|
{"landuse", "farm", DestTable{Name: "landusages"}, nil},
|
|
|
|
}},
|
2013-05-27 13:24:22 +04:00
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
{element.Tags{"landuse": "farm", "highway": "secondary", "type": "multipolygon"}, []Match{
|
|
|
|
{"landuse", "farm", DestTable{Name: "landusages"}, nil},
|
|
|
|
}},
|
2016-11-10 13:00:34 +03:00
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
{element.Tags{"highway": "footway", "type": "multipolygon"}, []Match{}},
|
|
|
|
{element.Tags{"highway": "footway", "area": "yes", "type": "multipolygon"}, []Match{
|
|
|
|
{"highway", "footway", DestTable{Name: "landusages"}, nil},
|
|
|
|
}},
|
2013-05-24 15:24:02 +04:00
|
|
|
|
2017-05-10 15:23:32 +03:00
|
|
|
{element.Tags{"boundary": "administrative", "admin_level": "8"}, []Match{}},
|
|
|
|
{element.Tags{"boundary": "administrative", "admin_level": "8", "type": "boundary"}, []Match{{"boundary", "administrative", DestTable{Name: "admin"}, nil}}},
|
|
|
|
}
|
2013-05-23 16:05:09 +04:00
|
|
|
|
2015-09-25 14:36:23 +03:00
|
|
|
elem := element.Relation{}
|
2017-05-10 15:23:32 +03:00
|
|
|
m := mapping.PolygonMatcher()
|
|
|
|
for i, test := range tests {
|
|
|
|
elem.Tags = test.tags
|
|
|
|
actual := m.MatchRelation(&elem)
|
|
|
|
if !matchesEqual(actual, test.matches) {
|
|
|
|
t.Errorf("unexpected result for case %d: %v != %v", i+1, actual, test.matches)
|
|
|
|
}
|
|
|
|
}
|
2015-09-25 14:36:23 +03:00
|
|
|
}
|
|
|
|
|
2015-07-17 11:07:55 +03:00
|
|
|
func TestExcludeFilter(t *testing.T) {
|
|
|
|
var f TagFilterer
|
|
|
|
var tags element.Tags
|
|
|
|
|
|
|
|
// no matches
|
|
|
|
f = newExcludeFilter([]Key{})
|
|
|
|
tags = element.Tags{"source": "1", "tiger:foo": "1", "source:foo": "1"}
|
|
|
|
f.Filter(&tags)
|
|
|
|
if !reflect.DeepEqual(tags, element.Tags{"source": "1", "tiger:foo": "1", "source:foo": "1"}) {
|
|
|
|
t.Error("unexpected filter result", tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
// match all
|
|
|
|
f = newExcludeFilter([]Key{"*"})
|
|
|
|
tags = element.Tags{"source": "1", "tiger:foo": "1", "source:foo": "1"}
|
|
|
|
f.Filter(&tags)
|
|
|
|
if !reflect.DeepEqual(tags, element.Tags{}) {
|
|
|
|
t.Error("unexpected filter result", tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fixed string and wildcard match
|
|
|
|
f = newExcludeFilter([]Key{"source", "tiger:*"})
|
|
|
|
tags = element.Tags{"source": "1", "tiger:foo": "1", "source:foo": "1"}
|
|
|
|
f.Filter(&tags)
|
|
|
|
if !reflect.DeepEqual(tags, element.Tags{"source:foo": "1"}) {
|
|
|
|
t.Error("unexpected filter result", tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 12:13:09 +04:00
|
|
|
func BenchmarkFilterNodes(b *testing.B) {
|
|
|
|
var tags element.Tags
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
// test __any__
|
|
|
|
tags = make(element.Tags)
|
|
|
|
tags["population"] = "0"
|
|
|
|
tags["name"] = "foo"
|
|
|
|
tags["boring"] = "true"
|
|
|
|
|
2013-05-17 17:55:31 +04:00
|
|
|
points := mapping.NodeTagFilter()
|
2017-05-09 16:55:21 +03:00
|
|
|
points.Filter(&tags)
|
2013-05-07 12:13:09 +04:00
|
|
|
if len(tags) != 2 && tags["population"] == "0" && tags["name"] == "foo" {
|
|
|
|
b.Fatal("Filter result not expected", tags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|