|
| 1 | +// |
| 2 | +// ForeignMemberTest.swift |
| 3 | +// |
| 4 | +// |
| 5 | +// Created by Adrian Schönig on 1/6/2022. |
| 6 | +// |
| 7 | + |
| 8 | +import Foundation |
| 9 | + |
| 10 | +import XCTest |
| 11 | + |
| 12 | +@testable import GeoJSONKit |
| 13 | + |
| 14 | +@available(iOS 10.0, *) |
| 15 | +class ForeignMemberTest: XCTestCase { |
| 16 | + |
| 17 | + func testForeignMemberCoding(in geoJSON: GeoJSON) throws { |
| 18 | + let today = ISO8601DateFormatter().string(from: Date()) |
| 19 | + |
| 20 | + var json = geoJSON.toJSON() |
| 21 | + |
| 22 | + // Convert the GeoJSON object to valid GeoJSON-T <https://github.com/kgeographer/geojson-t/>. |
| 23 | + XCTAssert(json["when"] == nil) |
| 24 | + let foreigner: [String: AnyHashable] = [ |
| 25 | + "timespans": [ |
| 26 | + [ |
| 27 | + // Starts and ends sometime today. |
| 28 | + "start": [ |
| 29 | + "in": today, |
| 30 | + ], |
| 31 | + "end": [ |
| 32 | + "in": today, |
| 33 | + ], |
| 34 | + ], |
| 35 | + ], |
| 36 | + "duration": "PT1M", // 1 minute long |
| 37 | + "label": "Today", |
| 38 | + ] |
| 39 | + json["when"] = foreigner |
| 40 | + |
| 41 | + let modifiedData = try JSONSerialization.data(withJSONObject: json, options: []) |
| 42 | + let modifiedObject = try GeoJSON(data: modifiedData) |
| 43 | + |
| 44 | + let roundTrippedJSON = modifiedObject.toJSON() |
| 45 | + |
| 46 | + let when = try XCTUnwrap(roundTrippedJSON["when"] as? [String: Any?]) |
| 47 | + XCTAssertEqual(when as NSDictionary, json["when"] as? NSDictionary) |
| 48 | + } |
| 49 | + |
| 50 | + func testForeignMemberCoding() throws { |
| 51 | + let nullIsland = GeoJSON.Position(latitude: 0, longitude: 0) |
| 52 | + try testForeignMemberCoding(in: .init(geometry: .single(.point(nullIsland)))) |
| 53 | + try testForeignMemberCoding(in: .init(geometry: .single(.lineString(.init(positions: [nullIsland, nullIsland]))))) |
| 54 | + try testForeignMemberCoding(in: .init(geometry: .single(.polygon(.init([[nullIsland, nullIsland]]))))) |
| 55 | + try testForeignMemberCoding(in: .init(feature: .init(geometry: .single(.point(nullIsland))))) |
| 56 | + try testForeignMemberCoding(in: .init(features: [])) |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments