Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve test coverage, fix issue with toLine and toPolygon

  • Loading branch information...
commit 5dc2f42cd3373f258165e364463c80011c4d902e 1 parent 7c717e4
@tmcw tmcw authored
View
12 index.js
@@ -19,11 +19,11 @@ function autoDelimiter(x) {
for (var i = 0; i < res.length; i++) {
if (keyCount(res[i]) !== count) return;
}
+ results.push({
+ delimiter: delimiter,
+ arity: Object.keys(res[0]).length,
+ });
}
- results.push({
- delimiter: delimiter,
- arity: Object.keys(res[0]).length,
- });
});
if (results.length) {
@@ -148,7 +148,7 @@ function toLine(gj) {
}
line.properties = features[0].properties;
return {
- type: 'FeatureSet',
+ type: 'FeatureCollection',
features: [line]
};
}
@@ -167,7 +167,7 @@ function toPolygon(gj) {
}
poly.properties = features[0].properties;
return {
- type: 'FeatureSet',
+ type: 'FeatureCollection',
features: [poly]
};
}
View
34 test/csv2geojson.js
@@ -130,6 +130,18 @@ describe('csv2geojson', function() {
});
});
});
+
+ it('no match', function(done) {
+ csv2geojson.csv2geojson('', { delimiter: 'auto' },
+ function(err, data) {
+ expect(err).to.eql({
+ type: 'Error',
+ message: 'Could not autodetect delimiter'
+ });
+ expect(data).to.eql(undefined);
+ done();
+ });
+ });
});
});
@@ -139,6 +151,10 @@ describe('csv2geojson', function() {
expect(csv2geojson.auto(textFile(f))).to.eql(jsonFile('simple.json'));
});
});
+
+ it('no match', function() {
+ expect(csv2geojson.auto('')).to.eql(null);
+ });
});
describe('#auto->csv2geojson', function() {
@@ -152,6 +168,24 @@ describe('csv2geojson', function() {
});
});
+ describe('toLine', function() {
+ it('converts a list of points to a line', function(done) {
+ csv2geojson.csv2geojson(csv2geojson.auto(textFile('line.csv')), function(err, data) {
+ expect(csv2geojson.toLine(data)).to.eql(jsonFile('line.geojson'));
+ done();
+ });
+ });
+ });
+
+ describe('toPolygon', function() {
+ it('converts a list of points to a polygon', function(done) {
+ csv2geojson.csv2geojson(csv2geojson.auto(textFile('polygon.csv')), function(err, data) {
+ expect(csv2geojson.toPolygon(data)).to.eql(jsonFile('polygon.geojson'));
+ done();
+ });
+ });
+ });
+
it('custom field names', function(done) {
csv2geojson.csv2geojson('y|x|name\n1|2|3', {
delimiter: '|',
View
4 test/data/line.csv
@@ -0,0 +1,4 @@
+lat,lon,name
+2,1,3
+2,2,3
+2,3,3
View
16 test/data/line.geojson
@@ -0,0 +1,16 @@
+{
+ "type": "FeatureCollection",
+ "features": [{
+ "type": "Feature",
+ "properties": {
+ "name": "3"
+ },
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [1, 2],
+ [2, 2],
+ [3, 2]]
+ }
+ }]
+}
View
4 test/data/polygon.csv
@@ -0,0 +1,4 @@
+lat,lon,name
+2,1,3
+2,2,3
+2,3,3
View
16 test/data/polygon.geojson
@@ -0,0 +1,16 @@
+{
+ "type": "FeatureCollection",
+ "features": [{
+ "type": "Feature",
+ "properties": {
+ "name": "3"
+ },
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [[
+ [1, 2],
+ [2, 2],
+ [3, 2]]]
+ }
+ }]
+}
Please sign in to comment.
Something went wrong with that request. Please try again.