-
Notifications
You must be signed in to change notification settings - Fork 74
/
SchemaTools.js
86 lines (69 loc) · 3.22 KB
/
SchemaTools.js
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
var assert = require('assert');
var st = require('../SchemaTools.js');
describe('schema', function() {
it('implicitly pick the right to OSM tag', function() {
assert.deepEqual(
st.generateToOsmTable([["TYP", 1, st.simple('highway=road')]]),
{"TYP":{"1":["highway","road"]}});
// two consistent implicit types does not cause an error.
assert.deepEqual(
st.generateToOsmTable([["TYP", 1, st.simple('highway=road'),
st.isSimilar('highway=road')]]),
{"TYP":{"1":["highway","road"]}});
assert.deepEqual(
st.generateToOsmTable([["TYP", 1, "highway=road", st.simple('highway=road')]]),
{"TYP":{"1":["highway","road"]}});
// override with a specific type
assert.deepEqual(
st.generateToOsmTable([["TYP", 1, "highway=primary",
st.simple('highway=secondary')]]),
{"TYP":{"1":["highway","primary"]}});
// two inconsistent implicit types should throw an error.
assert.throws(
function() { st.generateToOsmTable([["TYP", 1, st.simple('highway=road'),
st.isSimilar('highway=primary')]]); },
Error);
// wild card doesn't implictly specify a type.
assert.throws(function() {
st.generateToOsmTable([["TYP", 1, st.wildcard('highway=.*')]]); },
Error);
// two conflicting implict types.
assert.throws(
function() { st.generateToOsmTable([["TYP", 1,
st.simple('highway=primary'),
st.isSimilar('highway=secondary')]]); },
Error);
});
it('only allow unique OGR rows in to OSM', function() {
assert.throws(
function() { st.generateToOsmTable([
["TYP", 1, st.simple('highway=road')],
["TYP", 1, st.simple('highway=primary')]
]); },
Error);
});
it('throws an error on bad tags', function() {
assert.throws(
function() { st.generateToOsmTable([["TYP", 1, st.simple('invalidkey=foo')]]); },
Error);
assert.throws(
function() { st.generateToOsmTable([["TYP", 1, st.isSimilar('invalidkey=foo')]]); },
Error);
assert.throws(
function() { st.generateToOsmTable([["TYP", 1, st.isA('invalidkey=foo')]]); },
Error);
assert.throws(
function() { st.generateToOsmTable([["TYP", 1, st.wildcard('invalidkey=.*')]]); },
Error);
});
it('handle aliases properly', function() {
// should contain conference_centre and convention_centre
assert.deepEqual(
st.generateToOgrTable([["FFN", 579, st.isSimilar('amenity=convention_centre', .7, .1, .5)]]),
{"amenity":{"convention_centre":["FFN",579,0.5],"conference_centre":["FFN",579,0.5],"exhibition_hall":["FFN",579,0.23333333333333345]}});
// wildcard should match convention_centre and conference_centre
assert.deepEqual(
st.generateToOgrTable([["FFN", 579, st.wildcard('amenity=^con.*_centre', .7, .1, .5)]]),
{"amenity":{"convention_centre":["FFN",579,0.7],"conference_centre":["FFN",579,0.7]}});
}).timeout(3000);
});