-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyaml_test.go
105 lines (89 loc) · 1.96 KB
/
yaml_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package osmzen
import (
"io/ioutil"
"strings"
"testing"
"github.com/paulmach/osmzen/filter"
"github.com/paulmach/orb/geojson"
"github.com/paulmach/osm"
"github.com/paulmach/osm/osmgeojson"
"github.com/pkg/errors"
)
func TestYAML(t *testing.T) {
files, err := ioutil.ReadDir("config/yaml")
if err != nil {
t.Fatalf("failed to read file: %v", err)
}
o := &osm.OSM{
Nodes: osm.Nodes{
{
ID: 1,
Version: 2,
Tags: osm.Tags{
{Key: "amenity", Value: "restaurant"},
{Key: "cuisine", Value: "burger"},
{Key: "name", Value: "Kronnerburger"},
},
},
},
Ways: osm.Ways{
{
ID: 1,
Version: 2,
Nodes: osm.WayNodes{
{ID: 1, Lat: 0, Lon: 0},
{ID: 2, Lat: 0, Lon: 0.001},
{ID: 3, Lat: 0.001, Lon: 0.001},
{ID: 4, Lat: 0.001, Lon: 0},
{ID: 1, Lat: 0, Lon: 0},
},
Tags: osm.Tags{
{Key: "building", Value: "no"},
{Key: "building:part", Value: "yes"},
},
},
},
}
fc, err := osmgeojson.Convert(o)
if err != nil {
t.Fatalf("failed to convert to geojson: %v", err)
}
for _, f := range files {
if !strings.HasSuffix(f.Name(), ".yaml") {
continue
}
filename := "config/yaml/" + f.Name()
layer, err := loadLayer(filename)
if err != nil {
if err, ok := errors.Cause(err).(*filter.CompileError); ok {
t.Log(err.Error())
t.Logf("yaml: \n%s", err.YAML())
t.Logf("%+v", err.Cause)
}
t.Errorf("load of %v failed: %v", f.Name(), err)
continue
}
t.Logf("checking %s", filename)
for _, f := range fc.Features {
checkLayer(layer, f)
}
}
}
func checkLayer(layer *Layer, feature *geojson.Feature) {
ctx := filter.NewContext(nil, feature)
ctx.Debug = true
for _, f := range layer.filters {
if f.Table != "" && f.Table != "osm" {
// skip natural earth conditions, only osm
continue
}
f.Match(ctx)
if f.MinZoom != nil {
f.MinZoom.EvalNum(ctx)
}
// check the outputs
for _, e := range f.Output {
e.Expr.Eval(ctx)
}
}
}