Debian Codegraph @

topojson/test/topojson-command-test.js

raw
1 var fs = require("fs"),
2 child = require("child_process"),
3 tape = require("tape");
4
5 require("./inDelta");
6
7 testConversion(
8 "Polygons",
9 "polygon",
10 "-- polygon=test/geojson/polygon-clockwise.json"
11 );
12
13 testConversion(
14 "Polygons with --no-force-clockwise",
15 "polygon-counterclockwise",
16 "--no-force-clockwise"
17 + " -- clockwise=test/geojson/polygon-clockwise.json"
18 + " counterclockwise=test/geojson/polygon-counterclockwise.json"
19 );
20
21 testConversion(
22 "Polygons with --projection",
23 "polygon-mercator",
24 "--projection 'd3.geo.mercator()'"
25 + " --width 960"
26 + " --height 500"
27 + " --margin 20"
28 + " -- clockwise=test/geojson/polygon-clockwise.json"
29 + " counterclockwise=test/geojson/polygon-counterclockwise.json"
30 );
31
32 testConversion(
33 "Polygons with --no-quantization",
34 "polygon-no-quantization",
35 "--no-quantization"
36 + " -- polygon=test/geojson/polygon-clockwise.json"
37 );
38
39 testConversion(
40 "Empty geometries",
41 "empty",
42 "-- multilinestring=test/geojson/empty-multilinestring.json"
43 + " multipoint=test/geojson/empty-multipoint.json"
44 + " multipolygon=test/geojson/empty-multipolygon.json"
45 + " multipolygon2=test/geojson/empty-multipolygon2.json"
46 + " polygon=test/geojson/empty-polygon.json"
47 );
48
49 testConversion(
50 "Empty geometries with --allow-empty",
51 "empty-allowed",
52 "--allow-empty"
53 + " -- multilinestring=test/geojson/empty-multilinestring.json"
54 + " multipoint=test/geojson/empty-multipoint.json"
55 + " multipolygon=test/geojson/empty-multipolygon.json"
56 + " multipolygon2=test/geojson/empty-multipolygon2.json"
57 + " polygon=test/geojson/empty-polygon.json"
58 );
59
60 testConversion(
61 "Pass-through properties",
62 "properties",
63 "--no-quantization"
64 + " --filter=none"
65 + " --properties"
66 + " -- properties=test/geojson/properties.json"
67 );
68
69 testConversion(
70 "Computed property from coerced number",
71 "properties-number",
72 "--no-quantization"
73 + " --filter=none"
74 + " --properties=+boolean"
75 + " -- properties=test/geojson/properties.json"
76 );
77
78 testConversion(
79 "Computed property from expression",
80 "properties-number",
81 "--no-quantization"
82 + " --filter=none"
83 + " --properties='boolean=boolean?1:null'"
84 + " -- properties=test/geojson/properties.json"
85 );
86
87 testConversion(
88 "Computed id property from multiple candidates",
89 "properties-id-fallback",
90 "--no-quantization"
91 + " --filter=none"
92 + " --id-property=number,boolean,string"
93 + " -- properties=test/geojson/properties.json"
94 );
95
96 testConversion(
97 "Computed id property from expression",
98 "properties-id-computed",
99 "--no-quantization"
100 + " --filter=none"
101 + " --id-property='string.toUpperCase()'"
102 + " -- properties=test/geojson/properties.json"
103 );
104
105 testConversion(
106 "Join external properties with default id",
107 "properties-external-default-id",
108 "--no-quantization"
109 + " --filter=none"
110 + " --external-properties=test/tsv/properties-external.tsv"
111 + " --properties=smörgåsbord=smörgåsbord"
112 + " -- properties=test/geojson/no-properties.json"
113 );
114
115 function testConversion(name, output, options) {
116 if (!options) options = "";
117 tape(name, function(test) {
118 child.exec("bin/topojson " + options + " | cat", function(error, stdout, stderr) {
119 if (error) throw error;
120 var actual = JSON.parse(stdout),
121 expected = JSON.parse(fs.readFileSync("test/topojson/" + output + ".json", "utf-8"));
122 test.inDelta(actual, expected);
123 test.end();
124 });
125 });
126 }