Skip to content

Commit

Permalink
add tests + make errors consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Nov 9, 2015
1 parent ecbcb0c commit 542334a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 601 deletions.
26 changes: 15 additions & 11 deletions lib/geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ module.exports = GeoJSON;

function GeoJSON(filepath) {
this.filepath = filepath;
this.datasource = new mapnik.Datasource({
type: 'geojson',
file: filepath,
cache_features: false
});
this.extent = this.datasource.extent();
this.center = [
0.5 * (this.extent[0] + this.extent[2]),
0.5 * (this.extent[1] + this.extent[3])
];
this.layers = [path.basename(this.filepath, path.extname(this.filepath))];
try {
this.datasource = new mapnik.Datasource({
type: 'geojson',
file: filepath,
cache_features: false
});
this.extent = this.datasource.extent();
this.center = [
0.5 * (this.extent[0] + this.extent[2]),
0.5 * (this.extent[1] + this.extent[3])
];
this.layers = [path.basename(this.filepath, path.extname(this.filepath))];
} catch (err) {
throw new invalid('Invalid geojson');
}
}

GeoJSON.validFileType = ['geojson'];
Expand Down
26 changes: 13 additions & 13 deletions test/fixtures/invalid-geojson/parseinvalid-min.geojson
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "NAME": null, "TM_CAT": "pACHARE_7" }, "geometry": { "type": "Point", "coordinates": [ -74.014325954999947, 45.428254783000057 ] } },
{ "type": "Feature", "properties": { "NAME": null, "TM_CAT": "pACHARE_7" }, "geometry": { "type": "Point", "coordinates": [ -74.22829995799998, 45.485650487000044 ] } },
{ "type": "Feature", "properties": { "NAME": null, "TM_CAT": "pACHARE_7" }, "geometry": { "type": "Point", "coordinates": [ -74.348988593999934, 45.522009528000069 ] } },
{ "type": "Feature", "properties": { "NAME": null, "TM_CAT": "pACHARE_7" }, "geometry": { "type": "Point", "coordinates": [ -74.119734845999972, 45.456868624000037 ] } },
{ "type": "Feature", "properties": { "TM_CAT": "pWRECKS_2" }, "geometry": { "type": "Point", "coordinates": [ -73.978615778999938, 45.485249387000067 ] } },
{ "type": "Feature", "properties": { "TM_CAT": "pWRECKS_2" }, "geometry": { "type": "Point", "coordinates": [ -73.964693979999936, 45.494334135000031 ] } },
{ "type": "Feature", "properties": { "TM_CAT": "lNAVLNE_0" }, "geometry": { "type": "LineString", "coordinates": [ [ -74.159155663999968, 45.495072965000077 ], [ -74.158455968999988, 45.498466468000061 ] ] } },
{ "type": "Feature", "properties": { "TM_CAT": "lNAVLNE_0" }, "geometry": { "type": "LineString", "coordinates": [ [ -74.158172578999938, 45.498999769000079 ], [ -74.158512212999938, 45.497775414000046 ] ] } },
{ "type": "Feature", "properties": { "TM_CAT": aDEPARE, "DRVAL1": -99, "DRVAL2": 0 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -73.894235392999917, 45.530895268000165 ] ] ] } }
]
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": invalid
},
"geometry": {
"type": "Point",
"coordinates": [ 0,0 ]
}
}
]
}
25 changes: 25 additions & 0 deletions test/fixtures/invalid-geojson/parseinvalid-min2.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "valid"
},
"geometry": {
"type": "Point",
"coordinates": [ 0,0 ]
}
},
{
"type": "Feature",
"properties": {
"name": invalid,
},
"geometry": {
"type": "Point",
"coordinates": [ 0,0 ]
}
}
]
}

0 comments on commit 542334a

Please sign in to comment.