forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_internal_test.go
93 lines (86 loc) · 2.2 KB
/
util_internal_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
package gpkg
import (
"testing"
"github.com/go-spatial/geom"
)
func TestReplaceTokens(t *testing.T) {
type tcase struct {
qtext string
zoom uint
// TODO: replace with geom.Extent once it's ready
extent *geom.Extent
expected string
}
fn := func(tc tcase) func(*testing.T) {
return func(t *testing.T) {
output := replaceTokens(tc.qtext, tc.zoom, tc.extent)
if tc.expected != output {
t.Errorf("expected %v\n got\n %v", tc.expected, output)
return
}
}
}
tests := map[string]tcase{
"zoom": {
qtext: `
SELECT
fid, geom, featurecla, min_zoom, 22 as max_zoom, minx, miny, maxx, maxy
FROM
ne_110m_land t JOIN rtree_ne_110m_land_geom si ON t.fid = si.id
WHERE
min_zoom <= !ZOOM! AND max_zoom >= !ZOOM!`,
zoom: 9,
expected: `
SELECT
fid, geom, featurecla, min_zoom, 22 as max_zoom, minx, miny, maxx, maxy
FROM
ne_110m_land t JOIN rtree_ne_110m_land_geom si ON t.fid = si.id
WHERE
min_zoom <= 9 AND max_zoom >= 9`,
},
"bbox": {
qtext: `
SELECT
fid, geom, featurecla, min_zoom, 22 as max_zoom, minx, miny, maxx, maxy
FROM
ne_110m_land t JOIN rtree_ne_110m_land_geom si ON t.fid = si.id
WHERE
!BBOX!`,
extent: &geom.Extent{
-180, -85.0511,
180, 85.0511,
},
expected: `
SELECT
fid, geom, featurecla, min_zoom, 22 as max_zoom, minx, miny, maxx, maxy
FROM
ne_110m_land t JOIN rtree_ne_110m_land_geom si ON t.fid = si.id
WHERE
minx <= 180 AND maxx >= -180 AND miny <= 85.0511 AND maxy >= -85.0511`,
},
"bbox zoom": {
qtext: `
SELECT
fid, geom, featurecla, min_zoom, 22 as max_zoom, minx, miny, maxx, maxy
FROM
ne_110m_land t JOIN rtree_ne_110m_land_geom si ON t.fid = si.id
WHERE
!BBOX! AND min_zoom = !ZOOM!`,
extent: &geom.Extent{
-180, -85.0511,
180, 85.0511,
},
zoom: 3,
expected: `
SELECT
fid, geom, featurecla, min_zoom, 22 as max_zoom, minx, miny, maxx, maxy
FROM
ne_110m_land t JOIN rtree_ne_110m_land_geom si ON t.fid = si.id
WHERE
minx <= 180 AND maxx >= -180 AND miny <= 85.0511 AND maxy >= -85.0511 AND min_zoom = 3`,
},
}
for name, tc := range tests {
t.Run(name, fn(tc))
}
}