| 1 |
var tape = require("tape"), |
| 2 |
geomify = require("../lib/topojson/geomify"); |
| 3 |
|
| 4 |
tape("geomify replaces LineString Feature with LineString Geometry", function(test) { |
| 5 |
test.deepEqual(geomify({ |
| 6 |
foo: { |
| 7 |
type: "Feature", |
| 8 |
geometry: { |
| 9 |
type: "LineString", |
| 10 |
coordinates: [[0, 0]] |
| 11 |
} |
| 12 |
} |
| 13 |
}), { |
| 14 |
foo: { |
| 15 |
type: "LineString", |
| 16 |
coordinates: [[0, 0]] |
| 17 |
} |
| 18 |
}); |
| 19 |
test.end(); |
| 20 |
}); |
| 21 |
|
| 22 |
tape("geomify replaces GeometryCollection Feature with GeometryCollection", function(test) { |
| 23 |
test.deepEqual(geomify({ |
| 24 |
foo: { |
| 25 |
type: "Feature", |
| 26 |
geometry: { |
| 27 |
type: "GeometryCollection", |
| 28 |
geometries: [{ |
| 29 |
type: "LineString", |
| 30 |
coordinates: [[0, 0]] |
| 31 |
}] |
| 32 |
} |
| 33 |
} |
| 34 |
}), { |
| 35 |
foo: { |
| 36 |
type: "GeometryCollection", |
| 37 |
geometries: [{ |
| 38 |
type: "LineString", |
| 39 |
coordinates: [[0, 0]] |
| 40 |
}] |
| 41 |
} |
| 42 |
}); |
| 43 |
test.end(); |
| 44 |
}); |
| 45 |
|
| 46 |
tape("geomify replaces FeatureCollection with GeometryCollection", function(test) { |
| 47 |
test.deepEqual(geomify({ |
| 48 |
foo: { |
| 49 |
type: "FeatureCollection", |
| 50 |
features: [{ |
| 51 |
type: "Feature", |
| 52 |
geometry: { |
| 53 |
type: "LineString", |
| 54 |
coordinates: [[0, 0]] |
| 55 |
} |
| 56 |
}] |
| 57 |
} |
| 58 |
}), { |
| 59 |
foo: { |
| 60 |
type: "GeometryCollection", |
| 61 |
geometries: [{ |
| 62 |
type: "LineString", |
| 63 |
coordinates: [[0, 0]] |
| 64 |
}] |
| 65 |
} |
| 66 |
}); |
| 67 |
test.end(); |
| 68 |
}); |
| 69 |
|
| 70 |
tape("geomify replaces Feature with null Geometry with null-type Geometry", function(test) { |
| 71 |
test.deepEqual(geomify({ |
| 72 |
foo: { |
| 73 |
type: "Feature", |
| 74 |
geometry: null |
| 75 |
} |
| 76 |
}), { |
| 77 |
foo: { |
| 78 |
type: null |
| 79 |
} |
| 80 |
}); |
| 81 |
test.end(); |
| 82 |
}); |
| 83 |
|
| 84 |
tape("geomify replaces top-level null Geometry with null-type Geometry", function(test) { |
| 85 |
test.deepEqual(geomify({ |
| 86 |
foo: null |
| 87 |
}), { |
| 88 |
foo: { |
| 89 |
type: null |
| 90 |
} |
| 91 |
}); |
| 92 |
test.end(); |
| 93 |
}); |
| 94 |
|
| 95 |
tape("geomify replaces null Geometry in GeometryCollection with null-type Geometry", function(test) { |
| 96 |
test.deepEqual(geomify({ |
| 97 |
foo: { |
| 98 |
type: "GeometryCollection", |
| 99 |
geometries: [null] |
| 100 |
} |
| 101 |
}), { |
| 102 |
foo: { |
| 103 |
type: "GeometryCollection", |
| 104 |
geometries: [{ |
| 105 |
type: null |
| 106 |
}] |
| 107 |
} |
| 108 |
}); |
| 109 |
test.end(); |
| 110 |
}); |
| 111 |
|
| 112 |
tape("geomify preserves id", function(test) { |
| 113 |
test.deepEqual(geomify({ |
| 114 |
foo: { |
| 115 |
id: "foo", |
| 116 |
type: "Feature", |
| 117 |
geometry: { |
| 118 |
type: "LineString", |
| 119 |
coordinates: [[0, 0]] |
| 120 |
} |
| 121 |
} |
| 122 |
}), { |
| 123 |
foo: { |
| 124 |
id: "foo", |
| 125 |
type: "LineString", |
| 126 |
coordinates: [[0, 0]] |
| 127 |
} |
| 128 |
}); |
| 129 |
test.end(); |
| 130 |
}); |
| 131 |
|
| 132 |
tape("geomify preserves properties", function(test) { |
| 133 |
test.deepEqual(geomify({ |
| 134 |
foo: { |
| 135 |
properties: { |
| 136 |
"foo": 42 |
| 137 |
}, |
| 138 |
type: "Feature", |
| 139 |
geometry: { |
| 140 |
type: "LineString", |
| 141 |
coordinates: [[0, 0]] |
| 142 |
} |
| 143 |
} |
| 144 |
}), { |
| 145 |
foo: { |
| 146 |
properties: { |
| 147 |
"foo": 42 |
| 148 |
}, |
| 149 |
type: "LineString", |
| 150 |
coordinates: [[0, 0]] |
| 151 |
} |
| 152 |
}); |
| 153 |
test.end(); |
| 154 |
}); |
| 155 |
|
| 156 |
tape("geomify does not delete empty properties", function(test) { |
| 157 |
test.deepEqual(geomify({ |
| 158 |
foo: { |
| 159 |
properties: {}, |
| 160 |
type: "Feature", |
| 161 |
geometry: { |
| 162 |
type: "LineString", |
| 163 |
coordinates: [[0, 0]] |
| 164 |
} |
| 165 |
} |
| 166 |
}), { |
| 167 |
foo: { |
| 168 |
properties: {}, |
| 169 |
type: "LineString", |
| 170 |
coordinates: [[0, 0]] |
| 171 |
} |
| 172 |
}); |
| 173 |
test.end(); |
| 174 |
}); |
| 175 |
|
| 176 |
tape("geomify converts singular multipoints to points", function(test) { |
| 177 |
test.deepEqual(geomify({ |
| 178 |
foo: { |
| 179 |
type: "MultiPoint", |
| 180 |
coordinates: [[0, 0]] |
| 181 |
} |
| 182 |
}), { |
| 183 |
foo: { |
| 184 |
type: "Point", |
| 185 |
coordinates: [0, 0] |
| 186 |
} |
| 187 |
}); |
| 188 |
test.end(); |
| 189 |
}); |
| 190 |
|
| 191 |
tape("geomify converts empty multipoints to null", function(test) { |
| 192 |
test.deepEqual(geomify({ |
| 193 |
foo: { |
| 194 |
type: "MultiPoint", |
| 195 |
coordinates: [] |
| 196 |
} |
| 197 |
}), { |
| 198 |
foo: { |
| 199 |
type: null |
| 200 |
} |
| 201 |
}); |
| 202 |
test.end(); |
| 203 |
}); |
| 204 |
|
| 205 |
tape("geomify converts singular multilines to lines", function(test) { |
| 206 |
test.deepEqual(geomify({ |
| 207 |
foo: { |
| 208 |
type: "MultiLineString", |
| 209 |
coordinates: [[[0, 0], [0, 1]]] |
| 210 |
} |
| 211 |
}), { |
| 212 |
foo: { |
| 213 |
type: "LineString", |
| 214 |
coordinates: [[0, 0], [0, 1]] |
| 215 |
} |
| 216 |
}); |
| 217 |
test.end(); |
| 218 |
}); |
| 219 |
|
| 220 |
tape("geomify converts empty lines to null", function(test) { |
| 221 |
test.deepEqual(geomify({ |
| 222 |
foo: { |
| 223 |
type: "LineString", |
| 224 |
coordinates: [] |
| 225 |
} |
| 226 |
}), { |
| 227 |
foo: { |
| 228 |
type: null |
| 229 |
} |
| 230 |
}); |
| 231 |
test.end(); |
| 232 |
}); |
| 233 |
|
| 234 |
tape("geomify converts empty multilines to null", function(test) { |
| 235 |
test.deepEqual(geomify({ |
| 236 |
foo: { |
| 237 |
type: "MultiLineString", |
| 238 |
coordinates: [] |
| 239 |
}, |
| 240 |
bar: { |
| 241 |
type: "MultiLineString", |
| 242 |
coordinates: [[]] |
| 243 |
} |
| 244 |
}), { |
| 245 |
foo: { |
| 246 |
type: null |
| 247 |
}, |
| 248 |
bar: { |
| 249 |
type: null |
| 250 |
} |
| 251 |
}); |
| 252 |
test.end(); |
| 253 |
}); |
| 254 |
|
| 255 |
tape("geomify strips empty rings in polygons", function(test) { |
| 256 |
test.deepEqual(geomify({ |
| 257 |
foo: { |
| 258 |
type: "Polygon", |
| 259 |
coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]], []] |
| 260 |
} |
| 261 |
}), { |
| 262 |
foo: { |
| 263 |
type: "Polygon", |
| 264 |
coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]] |
| 265 |
} |
| 266 |
}); |
| 267 |
test.end(); |
| 268 |
}); |
| 269 |
|
| 270 |
tape("geomify strips empty lines in multilines", function(test) { |
| 271 |
test.deepEqual(geomify({ |
| 272 |
foo: { |
| 273 |
type: "MultiLineString", |
| 274 |
coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]], [], [[0, 0], [1, 0]]] |
| 275 |
} |
| 276 |
}), { |
| 277 |
foo: { |
| 278 |
type: "MultiLineString", |
| 279 |
coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]], [[0, 0], [1, 0]]] |
| 280 |
} |
| 281 |
}); |
| 282 |
test.end(); |
| 283 |
}); |
| 284 |
|
| 285 |
tape("geomify converts empty polygons to null", function(test) { |
| 286 |
test.deepEqual(geomify({ |
| 287 |
foo: { |
| 288 |
type: "Polygon", |
| 289 |
coordinates: [] |
| 290 |
}, |
| 291 |
bar: { |
| 292 |
type: "Polygon", |
| 293 |
coordinates: [[]] |
| 294 |
} |
| 295 |
}), { |
| 296 |
foo: { |
| 297 |
type: null |
| 298 |
}, |
| 299 |
bar: { |
| 300 |
type: null |
| 301 |
} |
| 302 |
}); |
| 303 |
test.end(); |
| 304 |
}); |
| 305 |
|
| 306 |
tape("geomify strips empty polygons in multipolygons", function(test) { |
| 307 |
test.deepEqual(geomify({ |
| 308 |
foo: { |
| 309 |
type: "MultiPolygon", |
| 310 |
coordinates: [[[[0, 0], [1, 0], [1, 1], [0, 0]], []], [], [[]]] |
| 311 |
} |
| 312 |
}), { |
| 313 |
foo: { |
| 314 |
type: "Polygon", |
| 315 |
coordinates: [[[0, 0], [1, 0], [1, 1], [0, 0]]] |
| 316 |
} |
| 317 |
}); |
| 318 |
test.end(); |
| 319 |
}); |
| 320 |
|
| 321 |
tape("geomify converts singular multipolygons to polygons", function(test) { |
| 322 |
test.deepEqual(geomify({ |
| 323 |
foo: { |
| 324 |
type: "MultiPolygon", |
| 325 |
coordinates: [[[[0, 0], [0, 1], [1, 0], [0, 0]]]] |
| 326 |
} |
| 327 |
}), { |
| 328 |
foo: { |
| 329 |
type: "Polygon", |
| 330 |
coordinates: [[[0, 0], [0, 1], [1, 0], [0, 0]]] |
| 331 |
} |
| 332 |
}); |
| 333 |
test.end(); |
| 334 |
}); |