inst/tinytest/test-errors.R

##"errors are handled", {
expect_error(geojson_sf(1:5), "Numeric vectors are not valid GeoJSON")
expect_error(geojson_sf("a"), "Invalid JSON")
expect_error(geojson_sf())
expect_error(geojson_sf(NULL))
expect_error(geojson_sf(NA), "Invalid JSON")
expect_error(geojson_sf('{ "type" : "Point" }'), "No 'coordinates' member at object index 0 - invalid GeoJSON")
#expect_error(geojson_sf('{"type" : "MultiPoint","coordinates" : [0,0] }'), "Invalid array object")
expect_error(geojson_sf('{"type" : "Point", "coordinates" : null }'), "No 'array' member at object index 0 - invalid GeoJSON")
#expect_error(geojson_sf('{"type" : "LineString", "coordinates" : [ 0, 0 ] }'), "Invalid array object")
expect_error(geojson_sf('{"type" : "MultiLineString", "coordinates" : [ 0, 0 ] }'), "Invalid array object")
#expect_error(geojson_sf('{"type" : "MultiLineString", "coordinates" : [ [0, 0] ] }'), "Invalid array object")
expect_error(geojson_sf('{"type" : "Polygon", "coordinates" : [0, 0] }'), "Invalid array object")
#expect_error(geojson_sf('{"type" : "Polygon", "coordinates" : [ [ 0, 0 ] ] }'), "Invalid array object")
expect_error(geojson_sf('{"type" : "MultiPolygon", "coordinates" : [ [0, 0] ] }'), "Invalid array object")
#expect_error(geojson_sf('{"type" : "MultiPolygon", "coordinates" : [ [ [0, 0] ] ] }'), "Invalid array object")
expect_error(geojson_wkt('{"type" : "LineString", "coordinates" : [ 0, 0 ] }'), "Invalid array object")
expect_error(geojson_wkt('{"type" : "MultiLineString", "coordinates" : [ 0, 0 ] }'), "Invalid array object")
expect_error(geojson_wkt('{"type" : "MultiLineString", "coordinates" : [ [0, 0] ] }'), "Invalid array object")
expect_error(geojson_wkt('{"type" : "Polygon", "coordinates" : [0, 0] }'), "Invalid array object")
expect_error(geojson_wkt('{"type" : "Polygon", "coordinates" : [ [ 0, 0 ] ] }'), "Invalid array object")
expect_error(geojson_wkt('{"type" : "MultiPolygon", "coordinates" : [ [0, 0] ] }'), "Invalid array object")
expect_error(geojson_wkt('{"type" : "MultiPolygon", "coordinates" : [ [ [0, 0] ] ] }'), "Invalid array object")
expect_error(geojson_sf('{"type" : "Point" , "coordinates" : {} }'), "No 'array' member at object index 0 - invalid GeoJSON")

## Issue 95
expect_error(geojson_sf("{\"type\": \"Polygon\", \"coordinates\": [[-70.7355,-33.2402],[-70.7355,-33.2404],[-70.7351,-33.2403],[-70.7351,-33.2401],[-70.7355,-33.2402]]}"), "Invalid array object")

Try the geojsonsf package in your browser

Any scripts or data that you put into this service are public.

geojsonsf documentation built on May 31, 2022, 1:05 a.m.