Skip to content

Commit

Permalink
Made GeoJSONObject idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Oct 6, 2021
1 parent 53910de commit ce7cc2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Turf/GeoJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public protocol GeoJSONObjectConvertible {
var geoJSONObject: GeoJSONObject { get }
}

extension GeoJSONObject: GeoJSONObjectConvertible {
public var geoJSONObject: GeoJSONObject { return self }
}

extension Geometry: GeoJSONObjectConvertible {
public var geoJSONObject: GeoJSONObject { return .geometry(self) }
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/TurfTests/GeoJSONTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ class GeoJSONTests: XCTestCase {
XCTAssertEqual(Geometry(GeometryCollection(geometries: [])),
.geometryCollection(GeometryCollection(geometries: [])))

XCTAssertEqual(Geometry(Geometry(Geometry(Geometry(Point(nullIsland))))), .point(.init(nullIsland)))

XCTAssertEqual(GeoJSONObject(Geometry(Point(nullIsland))), .geometry(.point(.init(nullIsland))))
XCTAssertEqual(GeoJSONObject(Feature(geometry: nil)), .feature(.init(geometry: nil)))
let nullGeometry: Geometry? = nil
XCTAssertEqual(GeoJSONObject(Feature(geometry: nullGeometry)), .feature(.init(geometry: nil)))
XCTAssertEqual(GeoJSONObject(FeatureCollection(features: [])), .featureCollection(.init(features: [])))

XCTAssertEqual(GeoJSONObject(GeoJSONObject(GeoJSONObject(GeoJSONObject(Geometry(Point(nullIsland)))))),
.geometry(.point(.init(nullIsland))))
}

func testPoint() {
Expand Down

0 comments on commit ce7cc2f

Please sign in to comment.