-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
executable file
·137 lines (133 loc) · 3.45 KB
/
test.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* eslint-env mocha */
// from http://geojson.org/geojson-spec.html#examples
var gml = require('./dist/common.js').geomToGml;
// var assert = require('assert');
var validate = require('xsd-schema-validator').validateXML;
// create geojson examples
var point = {'type': 'Point', 'coordinates': [102.0, 0.5]};
var line = {
'type': 'LineString',
'coordinates': [
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
]
};
var polygon = {
'type': 'Polygon',
'coordinates': [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]
};
//http://geojson.org/geojson-spec.html#id5
var multipoint = {
'type': 'MultiPoint',
'coordinates': [ [100.0, 0.0], [101.0, 1.0] ]
};
// http://geojson.org/geojson-spec.html#id6
var multilinestring = {
'type': 'MultiLineString',
'coordinates': [
[ [100.0, 0.0], [101.0, 1.0] ],
[ [102.0, 2.0], [103.0, 3.0] ]
]
};
//http://geojson.org/geojson-spec.html#id7
var multipolygon = {
'type': 'MultiPolygon',
'coordinates': [
[
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
],
[
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.2, 0.2],
[100.8, 0.2],
[100.8, 0.8],
[100.2, 0.8],
[100.2, 0.2]
]
]
]
};
//http://geojson.org/geojson-spec.html#geometrycollection
var geometrycollection = {
'type': 'GeometryCollection',
'geometries': [
{ 'type': 'Point',
'coordinates': [100.0, 0.0]
},
{ 'type': 'LineString',
'coordinates': [ [101.0, 0.0], [102.0, 1.0] ]
}
]
};
function validateGml(xml){
return new Promise(function(resolve, reject){
validate(xml, 'gml.xsd', function(err, result){
if (err) reject(err);
resolve(result);
});
});
}
function addNs3(xml){
var xmlns = ' xmlns:gml="http://www.opengis.net/gml/3.2"';
var index = />/.exec(xml).index;
return xml.substr(0, index) + xmlns + xml.substr(index);
}
describe('geomToGml-3.2.1', function(){
describe('visual inspection', function(){
it('should look right, or at least visible', function(){
[point, line, polygon, multipoint,
multilinestring, multipolygon, geometrycollection].map(
/* eslint-disable no-console */
(e)=>console.log(
addNs3(gml(e, 'ab.1')),
'\n------------------------\n'
)
);
});
});
describe('validation tests', function(){
it('Point', function(){
var xml = addNs3(gml(point, 'ab.1'));
return validateGml(xml);
});
it('LineString', function(){
var xml = addNs3(gml(line, 'ab.1'));
return validateGml(xml);
});
it('Polygon', function(){
var xml = addNs3(gml(polygon, 'ab.1'));
return validateGml(xml);
});
it('MultiPoint', function(){
var xml = addNs3(gml(multipoint,'ab.0', {gmlIds:['ab.1', 'cd.2']}));
return validateGml(xml);
});
it('MultiLineString', function(){
var xml = addNs3(gml(multilinestring,'ab.0', {gmlIds:['ab.1', 'cd.2']}));
return validateGml(xml);
});
it('MultiPolygon', function(){
var xml = addNs3(gml(multipolygon,'ab.0', {gmlIds:['ab.1', 'cd.2']}));
return validateGml(xml);
});
it('GeometryCollecion', function(){
var xml = addNs3(gml(geometrycollection, 'ab.0', {gmlIds:['ab.1', 'cd.2']}));
return validateGml(xml);
});
});
});