From 11c3965f75f8b86c089c6dfbbe955281d5999a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 28 Sep 2021 03:19:57 -0700 Subject: [PATCH] Updated Turf GeoJSON integration --- .../AnimateGeoJSONLineExample.swift | 2 +- .../All Examples/AnimateLayerExample.swift | 6 +- .../All Examples/FeatureStateExample.swift | 8 +- .../All Examples/FeaturesAtPointExample.swift | 2 +- .../All Examples/LineGradientExample.swift | 2 +- .../All Examples/LiveDataExample.swift | 2 +- .../MultipleGeometriesExample.swift | 2 +- .../SymbolClusteringExample.swift | 10 +- CHANGELOG.md | 1 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../Generated/CircleAnnotation.swift | 6 +- .../Generated/PointAnnotation.swift | 6 +- .../Generated/PolygonAnnotation.swift | 6 +- .../Generated/PolylineAnnotation.swift | 6 +- .../Foundation/Extensions/Turf/Feature.swift | 21 +-- Sources/MapboxMaps/Style/Style.swift | 2 +- .../Generated/CircleAnnotationTests.swift | 48 +++++- .../Generated/PointAnnotationTests.swift | 156 +++++++++++++++--- .../Generated/PolygonAnnotationTests.swift | 30 +++- .../Generated/PolylineAnnotationTests.swift | 54 +++++- .../Core/FeatureExtensionValueTests.swift | 4 +- .../Extensions/Turf/FeatureTests.swift | 4 +- .../GeoJSON/FeatureCollectionTests.swift | 50 +++--- .../GeoJSON/Geometry+MBXGeometryTests.swift | 12 +- .../GeoJSON/GeometryCollectionTests.swift | 22 +-- .../Foundation/GeoJSON/LineStringTests.swift | 9 +- .../GeoJSON/MultiLineStringTests.swift | 5 +- .../Foundation/GeoJSON/MultiPointTests.swift | 5 +- .../GeoJSON/MultiPolygonTests.swift | 10 +- .../Foundation/GeoJSON/PointTests.swift | 17 +- .../Foundation/GeoJSON/PolygonTests.swift | 14 +- .../FeatureQueryingTest.swift | 8 +- .../TileRegionLoadOptions+MapboxMaps.swift | 3 +- .../Fixtures/SourceProperties+Fixtures.swift | 3 +- .../Style/GeoJSONSourceDataTests.swift | 2 +- 35 files changed, 362 insertions(+), 184 deletions(-) create mode 100644 MapboxMaps.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift b/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift index 96773158b05c..22d97ccbfab7 100644 --- a/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift +++ b/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift @@ -85,7 +85,7 @@ public class AnimateGeoJSONLineExample: UIViewController, ExampleProtocol { let updatedLine = Feature(geometry: .lineString(LineString(currentCoordinates))) self.routeLineSource.data = .feature(updatedLine) try! self.mapView.mapboxMap.style.updateGeoJSONSource(withId: self.sourceIdentifier, - geoJSON: updatedLine) + geoJSON: .feature(updatedLine)) } } diff --git a/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift b/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift index 2ad4263aee61..eb059bbdfb79 100644 --- a/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift +++ b/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift @@ -108,12 +108,12 @@ public class AnimateLayerExample: UIViewController, ExampleProtocol { // Identify the new coordinate to animate to, and calculate // the bearing between the new coordinate and the following coordinate. - var geoJSON = Feature.init(geometry: Geometry.point(Point(coordinate))) - geoJSON.properties = ["bearing": coordinate.direction(to: nextCoordinate)] + var geoJSON = Feature(geometry: .point(Point(coordinate))) + geoJSON.properties = ["bearing": .number(coordinate.direction(to: nextCoordinate))] // Update the airplane source layer with the new coordinate and bearing. try! self.mapView.mapboxMap.style.updateGeoJSONSource(withId: self.airplaneSymbol.identifier, - geoJSON: geoJSON) + geoJSON: .feature(geoJSON)) runCount += 1 diff --git a/Apps/Examples/Examples/All Examples/FeatureStateExample.swift b/Apps/Examples/Examples/All Examples/FeatureStateExample.swift index 9c943e269ad9..b3fe050bcad4 100644 --- a/Apps/Examples/Examples/All Examples/FeatureStateExample.swift +++ b/Apps/Examples/Examples/All Examples/FeatureStateExample.swift @@ -192,11 +192,11 @@ public class FeatureStateExample: UIViewController, ExampleProtocol { // Extract the earthquake feature from the queried features if let earthquakeFeature = queriedfeatures.first?.feature, - case .number(.double(let earthquakeIdDouble)) = earthquakeFeature.identifier, + case .number(let earthquakeIdDouble) = earthquakeFeature.identifier, case .point(let point) = earthquakeFeature.geometry, - let magnitude = earthquakeFeature.properties?["mag"] as? Double, - let place = earthquakeFeature.properties?["place"] as? String, - let timestamp = earthquakeFeature.properties?["time"] as? Double { + case let .number(magnitude) = earthquakeFeature.properties?["mag"], + case let .string(place) = earthquakeFeature.properties?["place"], + case let .number(timestamp) = earthquakeFeature.properties?["time"] { let earthquakeId = Int(earthquakeIdDouble).description diff --git a/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift b/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift index b43f21735ee7..421159f4d9ad 100644 --- a/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift +++ b/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift @@ -74,7 +74,7 @@ public class FeaturesAtPointExample: UIViewController, ExampleProtocol { switch result { case .success(let queriedfeatures): if let firstFeature = queriedfeatures.first?.feature?.properties, - let stateName = firstFeature["STATE_NAME"] as? String { + case let .string(stateName) = firstFeature["STATE_NAME"] { self?.showAlert(with: "You selected \(stateName)") } case .failure(let error): diff --git a/Apps/Examples/Examples/All Examples/LineGradientExample.swift b/Apps/Examples/Examples/All Examples/LineGradientExample.swift index 1ba01ac1b48d..8c6f5703449e 100644 --- a/Apps/Examples/Examples/All Examples/LineGradientExample.swift +++ b/Apps/Examples/Examples/All Examples/LineGradientExample.swift @@ -34,7 +34,7 @@ public class LineGradientExample: UIViewController, ExampleProtocol { var featureCollection: FeatureCollection? do { let data = try Data(contentsOf: filePath) - featureCollection = try GeoJSON.parse(FeatureCollection.self, from: data) + featureCollection = try JSONDecoder().decode(FeatureCollection.self, from: data) } catch { print("Error parsing data: \(error)") } diff --git a/Apps/Examples/Examples/All Examples/LiveDataExample.swift b/Apps/Examples/Examples/All Examples/LiveDataExample.swift index 2f15d6933d3b..1a80341a98e0 100644 --- a/Apps/Examples/Examples/All Examples/LiveDataExample.swift +++ b/Apps/Examples/Examples/All Examples/LiveDataExample.swift @@ -43,7 +43,7 @@ final class LiveDataExample: UIViewController, ExampleProtocol { self.parseGeoJSON { result in switch result { case .success(let feature): - try! self.mapView.mapboxMap.style.updateGeoJSONSource(withId: self.sourceId, geoJSON: feature) + try! self.mapView.mapboxMap.style.updateGeoJSONSource(withId: self.sourceId, geoJSON: .feature(feature)) case .failure(let error): print("Error: \(error.localizedDescription)") } diff --git a/Apps/Examples/Examples/All Examples/MultipleGeometriesExample.swift b/Apps/Examples/Examples/All Examples/MultipleGeometriesExample.swift index 852da1a25ba9..8c1e81ad38ed 100644 --- a/Apps/Examples/Examples/All Examples/MultipleGeometriesExample.swift +++ b/Apps/Examples/Examples/All Examples/MultipleGeometriesExample.swift @@ -36,7 +36,7 @@ public class MultipleGeometriesExample: UIViewController, ExampleProtocol { do { let data = try Data(contentsOf: filePath) - featureCollection = try GeoJSON.parse(FeatureCollection.self, from: data) + featureCollection = try JSONDecoder().decode(FeatureCollection.self, from: data) } catch { print("Error parsing data: \(error)") } diff --git a/Apps/Examples/Examples/All Examples/SymbolClusteringExample.swift b/Apps/Examples/Examples/All Examples/SymbolClusteringExample.swift index b8d660bbd031..0fc86bc29d91 100644 --- a/Apps/Examples/Examples/All Examples/SymbolClusteringExample.swift +++ b/Apps/Examples/Examples/All Examples/SymbolClusteringExample.swift @@ -152,16 +152,16 @@ class SymbolClusteringExample: UIViewController, ExampleProtocol { // Check whether the feature has values for `ASSETNUM` and `LOCATIONDETAIL`. These properties // come from the fire hydrant dataset and indicate that the selected feature is not clustered. if let selectedFeatureProperties = queriedFeatures.first?.feature?.properties, - let featureInformation = selectedFeatureProperties["ASSETNUM"] as? String, - let location = selectedFeatureProperties["LOCATIONDETAIL"] as? String { + case let .string(featureInformation) = selectedFeatureProperties["ASSETNUM"], + case let .string(location) = selectedFeatureProperties["LOCATIONDETAIL"] { self?.showAlert(withTitle: "Hydrant \(featureInformation)", and: "\(location)") // If the feature is a cluster, it will have `point_count` and `cluster_id` properties. These are assigned // when the cluster is created. } else if let selectedFeatureProperties = queriedFeatures.first?.feature?.properties, - let pointCount = selectedFeatureProperties["point_count"] as? Int, - let clusterId = selectedFeatureProperties["cluster_id"] as? Int { + case let .number(pointCount) = selectedFeatureProperties["point_count"], + case let .number(clusterId) = selectedFeatureProperties["cluster_id"] { // If the tap landed on a cluster, pass the cluster ID and point count to the alert. - self?.showAlert(withTitle: "Cluster ID \(clusterId)", and: "There are \(pointCount) points in this cluster") + self?.showAlert(withTitle: "Cluster ID \(Int(clusterId))", and: "There are \(Int(pointCount)) points in this cluster") } case .failure(let error): self?.showAlert(withTitle: "An error occurred: \(error.localizedDescription)", and: "Please try another hydrant") diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c4cb623768..d44a3e8ed414 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Mapbox welcomes participation and contributions from everyone. * `CameraAnimationsManager.options` has been removed. Use `MapboxMap.cameraBounds` and `MapboxMap.setCameraBounds(with:)` instead. ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712)) * `MapboxMap.setCameraBounds(for:)` has been renamed to `.setCameraBounds(with:)` ([#712](https://github.com/mapbox/mapbox-maps-ios/pull/712)) * Requires [Turf v2.0.0-rc.2](https://github.com/mapbox/turf-swift/releases/tag/v2.0.0-rc.2). ([#715](https://github.com/mapbox/mapbox-maps-ios/pull/715)) +* Renames `Style.updateGeoJSONSource(withId:geoJSON:)` to `Style.updateGeoJSONSource(withId:geoJSON:)`. Instead of passing in the expected GeoJSON object type, you perform pattern matching on the return value using `case let`. ([#715](https://github.com/mapbox/mapbox-maps-ios/pull/715)) ### Features ✨ and improvements 🏁 diff --git a/MapboxMaps.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MapboxMaps.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000000..18d981003d68 --- /dev/null +++ b/MapboxMaps.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Sources/MapboxMaps/Annotations/Generated/CircleAnnotation.swift b/Sources/MapboxMaps/Annotations/Generated/CircleAnnotation.swift index 568d89c7d340..2b5722027956 100644 --- a/Sources/MapboxMaps/Annotations/Generated/CircleAnnotation.swift +++ b/Sources/MapboxMaps/Annotations/Generated/CircleAnnotation.swift @@ -23,9 +23,9 @@ public struct CircleAnnotation: Annotation { internal var feature: Turf.Feature { var feature = Turf.Feature(geometry: geometry) feature.identifier = .string(id) - var properties = [String: Any?]() - properties["layerProperties"] = layerProperties - properties["userInfo"] = userInfo + var properties = JSONObject() + properties["layerProperties"] = JSONValue(rawValue: layerProperties) + properties["userInfo"] = userInfo.flatMap(JSONValue.init(rawValue:)) feature.properties = properties return feature } diff --git a/Sources/MapboxMaps/Annotations/Generated/PointAnnotation.swift b/Sources/MapboxMaps/Annotations/Generated/PointAnnotation.swift index 5bef0db0596a..4840d3d554f1 100644 --- a/Sources/MapboxMaps/Annotations/Generated/PointAnnotation.swift +++ b/Sources/MapboxMaps/Annotations/Generated/PointAnnotation.swift @@ -23,9 +23,9 @@ public struct PointAnnotation: Annotation { internal var feature: Turf.Feature { var feature = Turf.Feature(geometry: geometry) feature.identifier = .string(id) - var properties = [String: Any?]() - properties["layerProperties"] = layerProperties - properties["userInfo"] = userInfo + var properties = JSONObject() + properties["layerProperties"] = JSONValue(rawValue: layerProperties) + properties["userInfo"] = userInfo.flatMap(JSONValue.init(rawValue:)) feature.properties = properties return feature } diff --git a/Sources/MapboxMaps/Annotations/Generated/PolygonAnnotation.swift b/Sources/MapboxMaps/Annotations/Generated/PolygonAnnotation.swift index 954ac5d7edb1..7e16239ef37a 100644 --- a/Sources/MapboxMaps/Annotations/Generated/PolygonAnnotation.swift +++ b/Sources/MapboxMaps/Annotations/Generated/PolygonAnnotation.swift @@ -23,9 +23,9 @@ public struct PolygonAnnotation: Annotation { internal var feature: Turf.Feature { var feature = Turf.Feature(geometry: geometry) feature.identifier = .string(id) - var properties = [String: Any?]() - properties["layerProperties"] = layerProperties - properties["userInfo"] = userInfo + var properties = JSONObject() + properties["layerProperties"] = JSONValue(rawValue: layerProperties) + properties["userInfo"] = userInfo.flatMap(JSONValue.init(rawValue:)) feature.properties = properties return feature } diff --git a/Sources/MapboxMaps/Annotations/Generated/PolylineAnnotation.swift b/Sources/MapboxMaps/Annotations/Generated/PolylineAnnotation.swift index fc248956dc94..71d0989ee7a5 100644 --- a/Sources/MapboxMaps/Annotations/Generated/PolylineAnnotation.swift +++ b/Sources/MapboxMaps/Annotations/Generated/PolylineAnnotation.swift @@ -23,9 +23,9 @@ public struct PolylineAnnotation: Annotation { internal var feature: Turf.Feature { var feature = Turf.Feature(geometry: geometry) feature.identifier = .string(id) - var properties = [String: Any?]() - properties["layerProperties"] = layerProperties - properties["userInfo"] = userInfo + var properties = JSONObject() + properties["layerProperties"] = JSONValue(rawValue: layerProperties) + properties["userInfo"] = userInfo.flatMap(JSONValue.init(rawValue:)) feature.properties = properties return feature } diff --git a/Sources/MapboxMaps/Foundation/Extensions/Turf/Feature.swift b/Sources/MapboxMaps/Foundation/Extensions/Turf/Feature.swift index f4d89b1c6c5e..e004c355a047 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Turf/Feature.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Turf/Feature.swift @@ -18,18 +18,14 @@ extension Turf.Feature { */ switch feature.identifier { case let identifier as NSNumber: - if String(cString: identifier.objCType) == "q" { - self.identifier = .number(.int(identifier.intValue)) - } else { - self.identifier = .number(.double(identifier.doubleValue)) - } + self.identifier = .number(identifier.doubleValue) case let identifier as String: - self.identifier = FeatureIdentifier.string(identifier) + self.identifier = .string(identifier) default: break } - properties = feature.properties + properties = JSONObject(rawValue: feature.properties) } /// Initialize a `Turf.Feature` with a `Point`. @@ -84,9 +80,7 @@ extension MapboxCommon.Feature { // Features may or may not have an identifier. If they have one, // it is either a number or string value. switch feature.identifier { - case let .number(.int(intId)): - identifier = NSNumber(value: intId) - case let .number(.double(doubleId)): + case let .number(doubleId): identifier = NSNumber(value: doubleId) case let .string(stringId): identifier = NSString(string: stringId) @@ -98,10 +92,13 @@ extension MapboxCommon.Feature { #endif } - let geometry = MapboxCommon.Geometry(geometry: feature.geometry) + // A null geometry is valid GeoJSON but not supported by MapboxCommon. + // The closest thing would be an empty GeometryCollection. + let nonNullGeometry = feature.geometry ?? .geometryCollection(.init(geometries: [])) + let geometry = MapboxCommon.Geometry(geometry: nonNullGeometry) self.init(identifier: identifier, geometry: geometry, - properties: (feature.properties as? [String: NSObject]) ?? [:]) + properties: (feature.properties?.rawValue as? [String: NSObject]) ?? [:]) } } diff --git a/Sources/MapboxMaps/Style/Style.swift b/Sources/MapboxMaps/Style/Style.swift index 4aaa2c1ff4e5..eb49409074c6 100644 --- a/Sources/MapboxMaps/Style/Style.swift +++ b/Sources/MapboxMaps/Style/Style.swift @@ -180,7 +180,7 @@ public class Style { /// /// - Attention: This method is only effective with sources of `GeoJSONSource` /// type, and cannot be used to update other source types. - public func updateGeoJSONSource(withId id: String, geoJSON: T) throws { + public func updateGeoJSONSource(withId id: String, geoJSON: GeoJSONObject) throws { guard let sourceInfo = allSourceIdentifiers.first(where: { $0.id == id }), sourceInfo.type == .geoJson else { fatalError("updateGeoJSONSource: Source with id '\(id)' is not a GeoJSONSource.") diff --git a/Tests/MapboxMapsTests/Annotations/Generated/CircleAnnotationTests.swift b/Tests/MapboxMapsTests/Annotations/Generated/CircleAnnotationTests.swift index 99bb99497c89..abdc8695d1cf 100644 --- a/Tests/MapboxMapsTests/Annotations/Generated/CircleAnnotationTests.swift +++ b/Tests/MapboxMapsTests/Annotations/Generated/CircleAnnotationTests.swift @@ -11,7 +11,11 @@ final class CircleAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["circle-sort-key"] as? Double, annotation.circleSortKey) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(circleSortKey) = layerProperties["circle-sort-key"] else { + return XCTFail() + } + XCTAssertEqual(circleSortKey, annotation.circleSortKey) } func testCircleBlur() { @@ -21,7 +25,11 @@ final class CircleAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["circle-blur"] as? Double, annotation.circleBlur) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(circleBlur) = layerProperties["circle-blur"] else { + return XCTFail() + } + XCTAssertEqual(circleBlur, annotation.circleBlur) } func testCircleColor() { @@ -31,7 +39,11 @@ final class CircleAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["circle-color"] as? String, annotation.circleColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(circleColor) = layerProperties["circle-color"] else { + return XCTFail() + } + XCTAssertEqual(circleColor, annotation.circleColor.flatMap { $0.rgbaString }) } func testCircleOpacity() { @@ -41,7 +53,11 @@ final class CircleAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["circle-opacity"] as? Double, annotation.circleOpacity) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(circleOpacity) = layerProperties["circle-opacity"] else { + return XCTFail() + } + XCTAssertEqual(circleOpacity, annotation.circleOpacity) } func testCircleRadius() { @@ -51,7 +67,11 @@ final class CircleAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["circle-radius"] as? Double, annotation.circleRadius) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(circleRadius) = layerProperties["circle-radius"] else { + return XCTFail() + } + XCTAssertEqual(circleRadius, annotation.circleRadius) } func testCircleStrokeColor() { @@ -61,7 +81,11 @@ final class CircleAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["circle-stroke-color"] as? String, annotation.circleStrokeColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(circleStrokeColor) = layerProperties["circle-stroke-color"] else { + return XCTFail() + } + XCTAssertEqual(circleStrokeColor, annotation.circleStrokeColor.flatMap { $0.rgbaString }) } func testCircleStrokeOpacity() { @@ -71,7 +95,11 @@ final class CircleAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["circle-stroke-opacity"] as? Double, annotation.circleStrokeOpacity) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(circleStrokeOpacity) = layerProperties["circle-stroke-opacity"] else { + return XCTFail() + } + XCTAssertEqual(circleStrokeOpacity, annotation.circleStrokeOpacity) } func testCircleStrokeWidth() { @@ -81,7 +109,11 @@ final class CircleAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["circle-stroke-width"] as? Double, annotation.circleStrokeWidth) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(circleStrokeWidth) = layerProperties["circle-stroke-width"] else { + return XCTFail() + } + XCTAssertEqual(circleStrokeWidth, annotation.circleStrokeWidth) } } diff --git a/Tests/MapboxMapsTests/Annotations/Generated/PointAnnotationTests.swift b/Tests/MapboxMapsTests/Annotations/Generated/PointAnnotationTests.swift index 386c037cb698..1af54a06df40 100644 --- a/Tests/MapboxMapsTests/Annotations/Generated/PointAnnotationTests.swift +++ b/Tests/MapboxMapsTests/Annotations/Generated/PointAnnotationTests.swift @@ -11,7 +11,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-anchor"] as? String, annotation.iconAnchor?.rawValue) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(iconAnchor) = layerProperties["icon-anchor"] else { + return XCTFail() + } + XCTAssertEqual(iconAnchor, annotation.iconAnchor?.rawValue) } func testIconImage() { @@ -21,7 +25,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-image"] as? String, annotation.iconImage) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(iconImage) = layerProperties["icon-image"] else { + return XCTFail() + } + XCTAssertEqual(iconImage, annotation.iconImage) } func testIconOffset() { @@ -31,7 +39,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-offset"] as? [Double], annotation.iconOffset) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .array(iconOffset) = layerProperties["icon-offset"] else { + return XCTFail() + } + XCTAssertEqual(iconOffset.compactMap { $0?.rawValue } as? [Double], annotation.iconOffset) } func testIconRotate() { @@ -41,7 +53,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-rotate"] as? Double, annotation.iconRotate) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(iconRotate) = layerProperties["icon-rotate"] else { + return XCTFail() + } + XCTAssertEqual(iconRotate, annotation.iconRotate) } func testIconSize() { @@ -51,7 +67,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-size"] as? Double, annotation.iconSize) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(iconSize) = layerProperties["icon-size"] else { + return XCTFail() + } + XCTAssertEqual(iconSize, annotation.iconSize) } func testSymbolSortKey() { @@ -61,7 +81,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["symbol-sort-key"] as? Double, annotation.symbolSortKey) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(symbolSortKey) = layerProperties["symbol-sort-key"] else { + return XCTFail() + } + XCTAssertEqual(symbolSortKey, annotation.symbolSortKey) } func testTextAnchor() { @@ -71,7 +95,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-anchor"] as? String, annotation.textAnchor?.rawValue) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(textAnchor) = layerProperties["text-anchor"] else { + return XCTFail() + } + XCTAssertEqual(textAnchor, annotation.textAnchor?.rawValue) } func testTextField() { @@ -81,7 +109,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-field"] as? String, annotation.textField) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(textField) = layerProperties["text-field"] else { + return XCTFail() + } + XCTAssertEqual(textField, annotation.textField) } func testTextJustify() { @@ -91,7 +123,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-justify"] as? String, annotation.textJustify?.rawValue) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(textJustify) = layerProperties["text-justify"] else { + return XCTFail() + } + XCTAssertEqual(textJustify, annotation.textJustify?.rawValue) } func testTextLetterSpacing() { @@ -101,7 +137,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-letter-spacing"] as? Double, annotation.textLetterSpacing) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(textLetterSpacing) = layerProperties["text-letter-spacing"] else { + return XCTFail() + } + XCTAssertEqual(textLetterSpacing, annotation.textLetterSpacing) } func testTextMaxWidth() { @@ -111,7 +151,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-max-width"] as? Double, annotation.textMaxWidth) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(textMaxWidth) = layerProperties["text-max-width"] else { + return XCTFail() + } + XCTAssertEqual(textMaxWidth, annotation.textMaxWidth) } func testTextOffset() { @@ -121,7 +165,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-offset"] as? [Double], annotation.textOffset) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .array(textOffset) = layerProperties["text-offset"] else { + return XCTFail() + } + XCTAssertEqual(textOffset.compactMap { $0?.rawValue } as? [Double], annotation.textOffset) } func testTextRadialOffset() { @@ -131,7 +179,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-radial-offset"] as? Double, annotation.textRadialOffset) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(textRadialOffset) = layerProperties["text-radial-offset"] else { + return XCTFail() + } + XCTAssertEqual(textRadialOffset, annotation.textRadialOffset) } func testTextRotate() { @@ -141,7 +193,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-rotate"] as? Double, annotation.textRotate) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(textRotate) = layerProperties["text-rotate"] else { + return XCTFail() + } + XCTAssertEqual(textRotate, annotation.textRotate) } func testTextSize() { @@ -151,7 +207,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-size"] as? Double, annotation.textSize) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(textSize) = layerProperties["text-size"] else { + return XCTFail() + } + XCTAssertEqual(textSize, annotation.textSize) } func testTextTransform() { @@ -161,7 +221,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-transform"] as? String, annotation.textTransform?.rawValue) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(textTransform) = layerProperties["text-transform"] else { + return XCTFail() + } + XCTAssertEqual(textTransform, annotation.textTransform?.rawValue) } func testIconColor() { @@ -171,7 +235,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-color"] as? String, annotation.iconColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(iconColor) = layerProperties["icon-color"] else { + return XCTFail() + } + XCTAssertEqual(iconColor, annotation.iconColor.flatMap { $0.rgbaString }) } func testIconHaloBlur() { @@ -181,7 +249,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-halo-blur"] as? Double, annotation.iconHaloBlur) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(iconHaloBlur) = layerProperties["icon-halo-blur"] else { + return XCTFail() + } + XCTAssertEqual(iconHaloBlur, annotation.iconHaloBlur) } func testIconHaloColor() { @@ -191,7 +263,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-halo-color"] as? String, annotation.iconHaloColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(iconHaloColor) = layerProperties["icon-halo-color"] else { + return XCTFail() + } + XCTAssertEqual(iconHaloColor, annotation.iconHaloColor.flatMap { $0.rgbaString }) } func testIconHaloWidth() { @@ -201,7 +277,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-halo-width"] as? Double, annotation.iconHaloWidth) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(iconHaloWidth) = layerProperties["icon-halo-width"] else { + return XCTFail() + } + XCTAssertEqual(iconHaloWidth, annotation.iconHaloWidth) } func testIconOpacity() { @@ -211,7 +291,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["icon-opacity"] as? Double, annotation.iconOpacity) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(iconOpacity) = layerProperties["icon-opacity"] else { + return XCTFail() + } + XCTAssertEqual(iconOpacity, annotation.iconOpacity) } func testTextColor() { @@ -221,7 +305,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-color"] as? String, annotation.textColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(textColor) = layerProperties["text-color"] else { + return XCTFail() + } + XCTAssertEqual(textColor, annotation.textColor.flatMap { $0.rgbaString }) } func testTextHaloBlur() { @@ -231,7 +319,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-halo-blur"] as? Double, annotation.textHaloBlur) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(textHaloBlur) = layerProperties["text-halo-blur"] else { + return XCTFail() + } + XCTAssertEqual(textHaloBlur, annotation.textHaloBlur) } func testTextHaloColor() { @@ -241,7 +333,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-halo-color"] as? String, annotation.textHaloColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(textHaloColor) = layerProperties["text-halo-color"] else { + return XCTFail() + } + XCTAssertEqual(textHaloColor, annotation.textHaloColor.flatMap { $0.rgbaString }) } func testTextHaloWidth() { @@ -251,7 +347,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-halo-width"] as? Double, annotation.textHaloWidth) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(textHaloWidth) = layerProperties["text-halo-width"] else { + return XCTFail() + } + XCTAssertEqual(textHaloWidth, annotation.textHaloWidth) } func testTextOpacity() { @@ -261,7 +361,11 @@ final class PointAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["text-opacity"] as? Double, annotation.textOpacity) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(textOpacity) = layerProperties["text-opacity"] else { + return XCTFail() + } + XCTAssertEqual(textOpacity, annotation.textOpacity) } } diff --git a/Tests/MapboxMapsTests/Annotations/Generated/PolygonAnnotationTests.swift b/Tests/MapboxMapsTests/Annotations/Generated/PolygonAnnotationTests.swift index 7a85f3119f5f..4f4d53b860c1 100644 --- a/Tests/MapboxMapsTests/Annotations/Generated/PolygonAnnotationTests.swift +++ b/Tests/MapboxMapsTests/Annotations/Generated/PolygonAnnotationTests.swift @@ -18,7 +18,11 @@ final class PolygonAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["fill-sort-key"] as? Double, annotation.fillSortKey) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(fillSortKey) = layerProperties["fill-sort-key"] else { + return XCTFail() + } + XCTAssertEqual(fillSortKey, annotation.fillSortKey) } func testFillColor() { @@ -35,7 +39,11 @@ final class PolygonAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["fill-color"] as? String, annotation.fillColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(fillColor) = layerProperties["fill-color"] else { + return XCTFail() + } + XCTAssertEqual(fillColor, annotation.fillColor.flatMap { $0.rgbaString }) } func testFillOpacity() { @@ -52,7 +60,11 @@ final class PolygonAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["fill-opacity"] as? Double, annotation.fillOpacity) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(fillOpacity) = layerProperties["fill-opacity"] else { + return XCTFail() + } + XCTAssertEqual(fillOpacity, annotation.fillOpacity) } func testFillOutlineColor() { @@ -69,7 +81,11 @@ final class PolygonAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["fill-outline-color"] as? String, annotation.fillOutlineColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(fillOutlineColor) = layerProperties["fill-outline-color"] else { + return XCTFail() + } + XCTAssertEqual(fillOutlineColor, annotation.fillOutlineColor.flatMap { $0.rgbaString }) } func testFillPattern() { @@ -86,7 +102,11 @@ final class PolygonAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["fill-pattern"] as? String, annotation.fillPattern) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(fillPattern) = layerProperties["fill-pattern"] else { + return XCTFail() + } + XCTAssertEqual(fillPattern, annotation.fillPattern) } } diff --git a/Tests/MapboxMapsTests/Annotations/Generated/PolylineAnnotationTests.swift b/Tests/MapboxMapsTests/Annotations/Generated/PolylineAnnotationTests.swift index 91402883d1ff..eeea3e2a2fff 100644 --- a/Tests/MapboxMapsTests/Annotations/Generated/PolylineAnnotationTests.swift +++ b/Tests/MapboxMapsTests/Annotations/Generated/PolylineAnnotationTests.swift @@ -12,7 +12,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-join"] as? String, annotation.lineJoin?.rawValue) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(lineJoin) = layerProperties["line-join"] else { + return XCTFail() + } + XCTAssertEqual(lineJoin, annotation.lineJoin?.rawValue) } func testLineSortKey() { @@ -23,7 +27,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-sort-key"] as? Double, annotation.lineSortKey) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(lineSortKey) = layerProperties["line-sort-key"] else { + return XCTFail() + } + XCTAssertEqual(lineSortKey, annotation.lineSortKey) } func testLineBlur() { @@ -34,7 +42,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-blur"] as? Double, annotation.lineBlur) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(lineBlur) = layerProperties["line-blur"] else { + return XCTFail() + } + XCTAssertEqual(lineBlur, annotation.lineBlur) } func testLineColor() { @@ -45,7 +57,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-color"] as? String, annotation.lineColor.flatMap { $0.rgbaString }) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(lineColor) = layerProperties["line-color"] else { + return XCTFail() + } + XCTAssertEqual(lineColor, annotation.lineColor.flatMap { $0.rgbaString }) } func testLineGapWidth() { @@ -56,7 +72,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-gap-width"] as? Double, annotation.lineGapWidth) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(lineGapWidth) = layerProperties["line-gap-width"] else { + return XCTFail() + } + XCTAssertEqual(lineGapWidth, annotation.lineGapWidth) } func testLineOffset() { @@ -67,7 +87,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-offset"] as? Double, annotation.lineOffset) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(lineOffset) = layerProperties["line-offset"] else { + return XCTFail() + } + XCTAssertEqual(lineOffset, annotation.lineOffset) } func testLineOpacity() { @@ -78,7 +102,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-opacity"] as? Double, annotation.lineOpacity) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(lineOpacity) = layerProperties["line-opacity"] else { + return XCTFail() + } + XCTAssertEqual(lineOpacity, annotation.lineOpacity) } func testLinePattern() { @@ -89,7 +117,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-pattern"] as? String, annotation.linePattern) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .string(linePattern) = layerProperties["line-pattern"] else { + return XCTFail() + } + XCTAssertEqual(linePattern, annotation.linePattern) } func testLineWidth() { @@ -100,7 +132,11 @@ final class PolylineAnnotationTests: XCTestCase { guard let featureProperties = try? XCTUnwrap(annotation.feature.properties) else { return } - XCTAssertEqual((featureProperties["layerProperties"] as! [String: Any])["line-width"] as? Double, annotation.lineWidth) + guard case let .object(layerProperties) = featureProperties["layerProperties"], + case let .number(lineWidth) = layerProperties["line-width"] else { + return XCTFail() + } + XCTAssertEqual(lineWidth, annotation.lineWidth) } } diff --git a/Tests/MapboxMapsTests/Foundation/Extensions/Core/FeatureExtensionValueTests.swift b/Tests/MapboxMapsTests/Foundation/Extensions/Core/FeatureExtensionValueTests.swift index 75e8d3cef8cf..2c54106b0d62 100644 --- a/Tests/MapboxMapsTests/Foundation/Extensions/Core/FeatureExtensionValueTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Extensions/Core/FeatureExtensionValueTests.swift @@ -16,7 +16,7 @@ final class FeatureExtensionValueTests: XCTestCase { let value = Int.random(in: 0..<100) let features = Array.random(withLength: .random(in: 0..<10)) { () -> Feature in var feature = Feature(geometry: .point(Point(.random()))) - feature.identifier = .number(.int(.random(in: (.min)...(.max)))) + feature.identifier = .number(Double(Int.random(in: (.min)...(.max)))) return feature } @@ -39,7 +39,7 @@ final class FeatureExtensionValueTests: XCTestCase { func testNonNilFeatures() { let features = Array.random(withLength: .random(in: 0..<10)) { () -> Feature in var feature = Feature(geometry: .point(Point(.random()))) - feature.identifier = .number(.int(.random(in: (.min)...(.max)))) + feature.identifier = .number(Double(Int.random(in: (.min)...(.max)))) return feature }.map(MapboxCommon.Feature.init(_:)) diff --git a/Tests/MapboxMapsTests/Foundation/Extensions/Turf/FeatureTests.swift b/Tests/MapboxMapsTests/Foundation/Extensions/Turf/FeatureTests.swift index f47a00275794..f5334d85b235 100644 --- a/Tests/MapboxMapsTests/Foundation/Extensions/Turf/FeatureTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Extensions/Turf/FeatureTests.swift @@ -24,7 +24,7 @@ final class FeatureTests: XCTestCase { let feature = try XCTUnwrap(Feature(commonFeature)) - guard case .number(.double(2.0)) = feature.identifier else { + guard feature.identifier == 2.0 else { XCTFail("feature.identifier did not match the expected value") return } @@ -55,7 +55,7 @@ final class FeatureTests: XCTestCase { func testInitializingCommonFeatureFromTurfFeatureNumberIdentifier() throws { var feature = Feature(geometry: geometry) - feature.identifier = .number(.double(2.0)) + feature.identifier = 2.0 let commonFeature = MapboxCommon.Feature(feature) diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/FeatureCollectionTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/FeatureCollectionTests.swift index c3debd6fc8a8..a6f74aa27397 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/FeatureCollectionTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/FeatureCollectionTests.swift @@ -8,12 +8,7 @@ class FeatureCollectionTests: XCTestCase { func testFeatureCollection() { let data = try! Fixture.geojsonData(from: "featurecollection")! - let geojson = try! GeoJSON.parse(FeatureCollection.self, from: data) - - XCTAssert(geojson.features[0].geometry.type == .LineString) - XCTAssert(geojson.features[1].geometry.type == .Polygon) - XCTAssert(geojson.features[2].geometry.type == .Polygon) - XCTAssert(geojson.features[3].geometry.type == .Point) + let geojson = try! JSONDecoder().decode(FeatureCollection.self, from: data) let lineStringFeature = geojson.features[0] guard case let .lineString(lineStringCoordinates) = lineStringFeature.geometry else { @@ -21,7 +16,7 @@ class FeatureCollectionTests: XCTestCase { return } XCTAssert(lineStringCoordinates.coordinates.count == 19) - XCTAssert(lineStringFeature.properties!["id"] as! Int == 1) + XCTAssertEqual(lineStringFeature.properties?["id"], 1) XCTAssert(lineStringCoordinates.coordinates.first!.latitude == -26.17500493262446) XCTAssert(lineStringCoordinates.coordinates.first!.longitude == 27.977542877197266) @@ -30,32 +25,31 @@ class FeatureCollectionTests: XCTestCase { XCTFail("Failed to create a Polygon.") return } - XCTAssert(polygonFeature.properties!["id"] as! Int == 2) + XCTAssertEqual(polygonFeature.properties?["id"], 2) XCTAssert(polygonCoordinates.coordinates[0].count == 21) XCTAssert(polygonCoordinates.coordinates[0].first!.latitude == -26.199035448897074) XCTAssert(polygonCoordinates.coordinates[0].first!.longitude == 27.972049713134762) + if case .polygon = geojson.features[2].geometry {} else { + XCTFail("Failed to create a Polygon.") + } + let pointFeature = geojson.features[3] guard case let .point(pointCoordinates) = pointFeature.geometry else { XCTFail("Failed to create a Point.") return } - XCTAssert(pointFeature.properties!["id"] as! Int == 4) + XCTAssertEqual(pointFeature.properties?["id"], 4) XCTAssert(pointCoordinates.coordinates.latitude == -26.152510345365126) XCTAssert(pointCoordinates.coordinates.longitude == 27.95642852783203) } func testDecodedFeatureCollection() { let data = try! Fixture.geojsonData(from: "featurecollection")! - let geojson = try! GeoJSON.parse(FeatureCollection.self, from: data) + let geojson = try! JSONDecoder().decode(FeatureCollection.self, from: data) let encodedData = try! JSONEncoder().encode(geojson) - let decoded = try! GeoJSON.parse(FeatureCollection.self, from: encodedData) - - XCTAssert(decoded.features[0].geometry.type == .LineString) - XCTAssert(decoded.features[1].geometry.type == .Polygon) - XCTAssert(decoded.features[2].geometry.type == .Polygon) - XCTAssert(decoded.features[3].geometry.type == .Point) + let decoded = try! JSONDecoder().decode(FeatureCollection.self, from: encodedData) let decodedLineStringFeature = decoded.features[0] guard case let .lineString(decodedLineStringCoordinates) = decodedLineStringFeature.geometry else { @@ -63,7 +57,7 @@ class FeatureCollectionTests: XCTestCase { return } XCTAssert(decodedLineStringCoordinates.coordinates.count == 19) - XCTAssert(decodedLineStringFeature.properties!["id"] as! Int == 1) + XCTAssertEqual(decodedLineStringFeature.properties?["id"], 1) XCTAssert(decodedLineStringCoordinates.coordinates.first!.latitude == -26.17500493262446) XCTAssert(decodedLineStringCoordinates.coordinates.first!.longitude == 27.977542877197266) @@ -72,31 +66,35 @@ class FeatureCollectionTests: XCTestCase { XCTFail("Failed to decode Polygon.") return } - XCTAssert(decodedPolygonFeature.properties!["id"] as! Int == 2) + XCTAssertEqual(decodedPolygonFeature.properties?["id"], 2) XCTAssert(decodedPolygonCoordinates.coordinates[0].count == 21) XCTAssert(decodedPolygonCoordinates.coordinates[0].first!.latitude == -26.199035448897074) XCTAssert(decodedPolygonCoordinates.coordinates[0].first!.longitude == 27.972049713134762) + if case .polygon = decoded.features[2].geometry {} else { + XCTFail("Failed to decode a Polygon.") + } + let decodedPointFeature = decoded.features[3] guard case let .point(decodedPointCoordinates) = decodedPointFeature.geometry else { XCTFail("Failed to decode Point.") return } - XCTAssert(decodedPointFeature.properties!["id"] as! Int == 4) + XCTAssertEqual(decodedPointFeature.properties?["id"], 4) XCTAssert(decodedPointCoordinates.coordinates.latitude == -26.152510345365126) XCTAssert(decodedPointCoordinates.coordinates.longitude == 27.95642852783203) } func testFeatureCollectionDecodeWithoutProperties() { let data = try! Fixture.geojsonData(from: "featurecollection-no-properties")! - let geojson = try! GeoJSON.parse(data) - XCTAssert(geojson.decoded is FeatureCollection) + let geojson = try! JSONDecoder().decode(GeoJSONObject.self, from: data) + if case .featureCollection = geojson {} else { XCTFail() } } func testUnkownFeatureCollection() { let data = try! Fixture.geojsonData(from: "featurecollection")! - let geojson = try! GeoJSON.parse(data) - XCTAssert(geojson.decoded is FeatureCollection) + let geojson = try! JSONDecoder().decode(GeoJSONObject.self, from: data) + if case .featureCollection = geojson {} else { XCTFail() } } func testPerformanceDecodeFeatureCollection() { @@ -104,14 +102,14 @@ class FeatureCollectionTests: XCTestCase { measure { for _ in 0...100 { - _ = try! GeoJSON.parse(FeatureCollection.self, from: data) + _ = try! JSONDecoder().decode(FeatureCollection.self, from: data) } } } func testPerformanceEncodeFeatureCollection() { let data = try! Fixture.geojsonData(from: "featurecollection")! - let decoded = try! GeoJSON.parse(FeatureCollection.self, from: data) + let decoded = try! JSONDecoder().decode(FeatureCollection.self, from: data) measure { for _ in 0...100 { @@ -125,7 +123,7 @@ class FeatureCollectionTests: XCTestCase { measure { for _ in 0...100 { - let decoded = try! GeoJSON.parse(FeatureCollection.self, from: data) + let decoded = try! JSONDecoder().decode(FeatureCollection.self, from: data) _ = try! JSONEncoder().encode(decoded) } } diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/Geometry+MBXGeometryTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/Geometry+MBXGeometryTests.swift index 6eafb0575175..3eb20057bc9a 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/Geometry+MBXGeometryTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/Geometry+MBXGeometryTests.swift @@ -14,7 +14,7 @@ internal class GeometryMBXGeometryTests: XCTestCase { let turfGeometry = Geometry(mbxGeometry) // Then - guard let expectedTurfPoint = turfGeometry?.value as? Point else { + guard case let .point(expectedTurfPoint) = turfGeometry else { XCTFail("Could not convert Geometry to Turf Point geometry") return } @@ -36,7 +36,7 @@ internal class GeometryMBXGeometryTests: XCTestCase { let turfGeometry = Geometry(mbxGeometry) // Then - guard let expectedTurfLineString = turfGeometry?.value as? LineString else { + guard case let .lineString(expectedTurfLineString) = turfGeometry else { XCTFail("Could not convert Geometry to Turf LineString geometry") return } @@ -59,7 +59,7 @@ internal class GeometryMBXGeometryTests: XCTestCase { let turfGeometry = Geometry(mbxGeometry) // Then - guard let expectedTurfPolygon = turfGeometry?.value as? Polygon else { + guard case let .polygon(expectedTurfPolygon) = turfGeometry else { XCTFail("Could not convert Geometry to Turf Polygon geometry.") return } @@ -78,7 +78,7 @@ internal class GeometryMBXGeometryTests: XCTestCase { let turfGeometry = Geometry(mbxGeometry) // Then - guard let expectedTurfMultiPoint = turfGeometry?.value as? MultiPoint else { + guard case let .multiPoint(expectedTurfMultiPoint) = turfGeometry else { XCTFail("Could not convert Geometry to Turf Multipoint geometry") return } @@ -104,7 +104,7 @@ internal class GeometryMBXGeometryTests: XCTestCase { let turfGeometry = Geometry(mbxGeometry) // Then - guard let expectedTurfMultiLineString = turfGeometry?.value as? MultiLineString else { + guard case let .multiLineString(expectedTurfMultiLineString) = turfGeometry else { XCTFail("Could not convert Geometry to Turf MultiLineString geometry") return } @@ -136,7 +136,7 @@ internal class GeometryMBXGeometryTests: XCTestCase { let turfGeometry = Geometry(mbxGeometry) // Then - guard let expectedTurfMultiPolygon = turfGeometry?.value as? MultiPolygon else { + guard case let .multiPolygon(expectedTurfMultiPolygon) = turfGeometry else { XCTFail("Could not convert Geometry to Turf MultiPolygon") return } diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/GeometryCollectionTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/GeometryCollectionTests.swift index d04f92ba0a21..be37dd50a866 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/GeometryCollectionTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/GeometryCollectionTests.swift @@ -12,25 +12,19 @@ class GeometryCollectionTests: XCTestCase { let multiPolygonCoordinate = CLLocationCoordinate2D(latitude: 8.5, longitude: 1) // Act - let geoJSON = try! GeoJSON.parse(data) + let geoJSON = try! JSONDecoder().decode(GeoJSONObject.self, from: data) // Assert - XCTAssert(geoJSON.decoded is Turf.Feature) - - guard let geometryCollectionFeature = geoJSON.decoded as? Turf.Feature else { + guard case let .feature(geometryCollectionFeature) = geoJSON else { XCTFail("Failed to create Feature.") return } - XCTAssert(geometryCollectionFeature.geometry.type == .GeometryCollection) - XCTAssert(geometryCollectionFeature.geometry.value is GeometryCollection) - guard case let .geometryCollection(geometries) = geometryCollectionFeature.geometry else { XCTFail("Failed to create GeometryCollection.") return } - XCTAssert(geometries.geometries[2].type == .MultiPolygon) guard case let .multiPolygon(decodedMultiPolygonCoordinate) = geometries.geometries[2] else { XCTFail("Failed to create MultiPolygon.") return @@ -42,29 +36,23 @@ class GeometryCollectionTests: XCTestCase { // Arrange let multiPolygonCoordinate = CLLocationCoordinate2D(latitude: 8.5, longitude: 1) let data = try! Fixture.geojsonData(from: "geometry-collection")! - let geoJSON = try! GeoJSON.parse(data) + let geoJSON = try! JSONDecoder().decode(GeoJSONObject.self, from: data) // Act let encodedData = try! JSONEncoder().encode(geoJSON) - let encodedJSON = try! GeoJSON.parse(encodedData) + let encodedJSON = try! JSONDecoder().decode(GeoJSONObject.self, from: encodedData) // Assert - XCTAssert(encodedJSON.decoded is Turf.Feature) - - guard let geometryCollectionFeature = encodedJSON.decoded as? Turf.Feature else { + guard case let .feature(geometryCollectionFeature) = encodedJSON else { XCTFail("Failed to create Feature.") return } - XCTAssert(geometryCollectionFeature.geometry.type == .GeometryCollection) - XCTAssert(geometryCollectionFeature.geometry.value is GeometryCollection) - guard case let .geometryCollection(geometries) = geometryCollectionFeature.geometry else { XCTFail("Failed to create GeometryCollection.") return } - XCTAssert(geometries.geometries[2].type == .MultiPolygon) guard case let .multiPolygon(decodedMultiPolygonCoordinate) = geometries.geometries[2] else { XCTFail("Failed to create MultiPolygon.") return diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/LineStringTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/LineStringTests.swift index b2a82315ee22..2c7f4cd55c55 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/LineStringTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/LineStringTests.swift @@ -9,9 +9,8 @@ class LineStringTests: XCTestCase { func testLineStringFeature() { let data = try! Fixture.geojsonData(from: "simple-line")! - let geojson = try! GeoJSON.parse(Feature.self, from: data) + let geojson = try! JSONDecoder().decode(Feature.self, from: data) - XCTAssert(geojson.geometry.type == .LineString) guard case let .lineString(lineStringCoordinates) = geojson.geometry else { XCTFail("Failed to create a LineString.") return @@ -22,17 +21,17 @@ class LineStringTests: XCTestCase { let last = CLLocationCoordinate2D(latitude: 10, longitude: 0) XCTAssert(lineStringCoordinates.coordinates.first == first) XCTAssert(lineStringCoordinates.coordinates.last == last) - XCTAssert(geojson.identifier!.value as! String == "1") + XCTAssertEqual(geojson.identifier, "1") let encodedData = try! JSONEncoder().encode(geojson) - let decoded = try! GeoJSON.parse(Feature.self, from: encodedData) + let decoded = try! JSONDecoder().decode(Feature.self, from: encodedData) guard case let .lineString(decodedLineStringCoordinates) = decoded.geometry else { XCTFail("Failed to create a LineString.") return } XCTAssertEqual(lineStringCoordinates, decodedLineStringCoordinates) - XCTAssertEqual(geojson.identifier!.value as! String, decoded.identifier!.value! as! String) + XCTAssertEqual(geojson.identifier, decoded.identifier) } } // diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiLineStringTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiLineStringTests.swift index 36fdf3be38e9..34fc89a4b8df 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiLineStringTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiLineStringTests.swift @@ -11,9 +11,8 @@ class MultiLineStringTests: XCTestCase { let firstCoordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0) let lastCoordinate = CLLocationCoordinate2D(latitude: 6, longitude: 6) - let geojson = try! GeoJSON.parse(Feature.self, from: data) + let geojson = try! JSONDecoder().decode(Feature.self, from: data) - XCTAssert(geojson.geometry.type == .MultiLineString) guard case let .multiLineString(multiLineStringCoordinates) = geojson.geometry else { XCTFail("Failed to create MultiLineString.") return @@ -22,7 +21,7 @@ class MultiLineStringTests: XCTestCase { XCTAssert(multiLineStringCoordinates.coordinates.last?.last == lastCoordinate) let encodedData = try! JSONEncoder().encode(geojson) - let decoded = try! GeoJSON.parse(Feature.self, from: encodedData) + let decoded = try! JSONDecoder().decode(Feature.self, from: encodedData) guard case let .multiLineString(decodedMultiLineStringCoordinates) = decoded.geometry else { XCTFail("Failed to create decoded MultiLineString.") return diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiPointTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiPointTests.swift index eadf9005e518..c50b73654ca5 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiPointTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiPointTests.swift @@ -11,9 +11,8 @@ class MultiPointTests: XCTestCase { let firstCoordinate = CLLocationCoordinate2D(latitude: 26.194876675795218, longitude: 14.765625) let lastCoordinate = CLLocationCoordinate2D(latitude: 24.926294766395593, longitude: 17.75390625) - let geojson = try! GeoJSON.parse(Feature.self, from: data) + let geojson = try! JSONDecoder().decode(Feature.self, from: data) - XCTAssert(geojson.geometry.type == .MultiPoint) guard case let .multiPoint(multipointCoordinates) = geojson.geometry else { XCTFail("Failed to create MultiPoint.") return @@ -22,7 +21,7 @@ class MultiPointTests: XCTestCase { XCTAssert(multipointCoordinates.coordinates.last == lastCoordinate) let encodedData = try! JSONEncoder().encode(geojson) - let decoded = try! GeoJSON.parse(Feature.self, from: encodedData) + let decoded = try! JSONDecoder().decode(Feature.self, from: encodedData) guard case let .multiPoint(decodedMultipointCoordinates) = decoded.geometry else { XCTFail("Failed to create MultiPoint.") return diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiPolygonTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiPolygonTests.swift index ba3069ee5b90..a7dd30f7746d 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiPolygonTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/MultiPolygonTests.swift @@ -11,9 +11,8 @@ class MultiPolygonTests: XCTestCase { let firstCoordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0) let lastCoordinate = CLLocationCoordinate2D(latitude: 11, longitude: 11) - let geojson = try! GeoJSON.parse(Feature.self, from: data) + let geojson = try! JSONDecoder().decode(Feature.self, from: data) - XCTAssert(geojson.geometry.type == .MultiPolygon) guard case let .multiPolygon(multipolygonCoordinates) = geojson.geometry else { XCTFail("Failed to create MultiPolygon.") return @@ -23,7 +22,7 @@ class MultiPolygonTests: XCTestCase { XCTAssert(multipolygonCoordinates.coordinates.last?.last?.last == lastCoordinate) let encodedData = try! JSONEncoder().encode(geojson) - let decoded = try! GeoJSON.parse(Feature.self, from: encodedData) + let decoded = try! JSONDecoder().decode(Feature.self, from: encodedData) guard case let .multiPolygon(decodedMultipolygonCoordinates) = decoded.geometry else { XCTFail("Failed to decode MultiPolygon.") return @@ -72,16 +71,15 @@ class MultiPolygonTests: XCTestCase { multiPolygonFeature.properties = ["some": "var"] let encodedData = try! JSONEncoder().encode(multiPolygonFeature) - let decodedCustomMultiPolygon = try! GeoJSON.parse(Feature.self, from: encodedData) + let decodedCustomMultiPolygon = try! JSONDecoder().decode(Feature.self, from: encodedData) let data = try! Fixture.geojsonData(from: "multipolygon")! - let bundledMultiPolygon = try! GeoJSON.parse(Feature.self, from: data) + let bundledMultiPolygon = try! JSONDecoder().decode(Feature.self, from: data) guard case let .multiPolygon(bundledMultipolygonCoordinates) = bundledMultiPolygon.geometry else { XCTFail("Failed to create MultiPolygon from bundled MultiPolygon.") return } - XCTAssert(decodedCustomMultiPolygon.geometry.type == .MultiPolygon) guard case let .multiPolygon(decodedMultipolygonCoordinates) = decodedCustomMultiPolygon.geometry else { XCTFail("Failed to create decoded MultiPolygon.") return diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/PointTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/PointTests.swift index a31bcb81f9e3..a55189c62daf 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/PointTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/PointTests.swift @@ -8,7 +8,7 @@ class PointTests: XCTestCase { func testPointFeature() { let data = try! Fixture.geojsonData(from: "point")! - let geojson = try! GeoJSON.parse(Feature.self, from: data) + let geojson = try! JSONDecoder().decode(Feature.self, from: data) let coordinate = CLLocationCoordinate2D(latitude: 26.194876675795218, longitude: 14.765625) guard case let .point(point) = geojson.geometry else { @@ -16,22 +16,19 @@ class PointTests: XCTestCase { return } XCTAssertEqual(point.coordinates, coordinate) - XCTAssert((geojson.identifier!.value as! Number).value! as! Int == 1) + XCTAssertEqual(geojson.identifier, 1) let encodedData = try! JSONEncoder().encode(geojson) - let decoded = try! GeoJSON.parse(Feature.self, from: encodedData) + let decoded = try! JSONDecoder().decode(Feature.self, from: encodedData) - XCTAssertEqual(geojson.geometry.value as! Point, - decoded.geometry.value as! Point) - XCTAssertEqual(geojson.identifier!.value as! Number, - decoded.identifier!.value as! Number) + XCTAssertEqual(geojson.geometry, decoded.geometry) } func testUnkownPointFeature() { let data = try! Fixture.geojsonData(from: "point")! - let geojson = try! GeoJSON.parse(data) + let geojson = try! JSONDecoder().decode(GeoJSONObject.self, from: data) - XCTAssert(geojson.decoded is Turf.Feature) - XCTAssert(geojson.decodedFeature?.geometry.type == .Point) + if case let .feature(feature) = geojson, + case .point = feature.geometry {} else { XCTFail() } } } diff --git a/Tests/MapboxMapsTests/Foundation/GeoJSON/PolygonTests.swift b/Tests/MapboxMapsTests/Foundation/GeoJSON/PolygonTests.swift index 54e4c998eef7..6dedfe92baf6 100644 --- a/Tests/MapboxMapsTests/Foundation/GeoJSON/PolygonTests.swift +++ b/Tests/MapboxMapsTests/Foundation/GeoJSON/PolygonTests.swift @@ -8,12 +8,12 @@ class PolygonTests: XCTestCase { func testPolygonFeature() { let data = try! Fixture.geojsonData(from: "polygon")! - let geojson = try! GeoJSON.parse(Feature.self, from: data) + let geojson = try! JSONDecoder().decode(Feature.self, from: data) let firstCoordinate = CLLocationCoordinate2D(latitude: 37.00255267215955, longitude: -109.05029296875) let lastCoordinate = CLLocationCoordinate2D(latitude: 40.6306300839918, longitude: -108.56689453125) - XCTAssert((geojson.identifier!.value as! Number).value! as! Double == 1.01) + XCTAssertEqual(geojson.identifier, 1.01) guard case let .polygon(polygon) = geojson.geometry else { XCTFail("Failed to create polygon.") @@ -25,14 +25,14 @@ class PolygonTests: XCTestCase { XCTAssert(polygon.innerRings.first?.coordinates.count == 5) let encodedData = try! JSONEncoder().encode(geojson) - let decoded = try! GeoJSON.parse(Feature.self, from: encodedData) + let decoded = try! JSONDecoder().decode(Feature.self, from: encodedData) guard case let .polygon(decodedPolygon) = decoded.geometry else { - XCTFail("Failed to create polygon") - return - } + XCTFail("Failed to create polygon") + return + } XCTAssertEqual(polygon, decodedPolygon) - XCTAssertEqual(geojson.identifier!.value as! Number, decoded.identifier!.value! as! Number) + XCTAssertEqual(geojson.identifier, decoded.identifier) XCTAssert(decodedPolygon.outerRing.coordinates.first == firstCoordinate) XCTAssert(decodedPolygon.innerRings.last?.coordinates.last == lastCoordinate) XCTAssert(decodedPolygon.outerRing.coordinates.count == 5) diff --git a/Tests/MapboxMapsTests/Foundation/Integration Tests/FeatureQueryingTest.swift b/Tests/MapboxMapsTests/Foundation/Integration Tests/FeatureQueryingTest.swift index 3a4dbd448e7c..a48ddde86192 100644 --- a/Tests/MapboxMapsTests/Foundation/Integration Tests/FeatureQueryingTest.swift +++ b/Tests/MapboxMapsTests/Foundation/Integration Tests/FeatureQueryingTest.swift @@ -79,8 +79,12 @@ internal class FeatureQueryingTest: MapViewIntegrationTestCase { case .success(let filteredFeatures) = filteredFeatures { let expectedFilteredFeatures = unfilteredFeatures.filter { queriedFeature in - // `GeometryType(1)` is equal to `GemoetryType`, `point` - return queriedFeature.feature?.geometry.type == .Point + // `GeometryType(1)` is equal to `GeometryType`, `point` + if case .point = queriedFeature.feature?.geometry { + return true + } else { + return false + } } // Then diff --git a/Tests/MapboxMapsTests/Offline/TileRegionLoadOptions+MapboxMaps.swift b/Tests/MapboxMapsTests/Offline/TileRegionLoadOptions+MapboxMaps.swift index 746926c690c3..bb238fcad60b 100644 --- a/Tests/MapboxMapsTests/Offline/TileRegionLoadOptions+MapboxMaps.swift +++ b/Tests/MapboxMapsTests/Offline/TileRegionLoadOptions+MapboxMaps.swift @@ -116,8 +116,7 @@ final class TileRegionLoadOptions_MapboxMapsTests: XCTestCase { averageBytesPerSecond: nil, extraOptions: nil) - XCTAssertEqual(tileRegionLoadOptions.geometry?.type, .Point) - XCTAssertEqual(tileRegionLoadOptions.geometry?.value as? Point, Point(coordinate)) + XCTAssertEqual(tileRegionLoadOptions.geometry, .point(.init(coordinate))) } func testNilGeometry() { diff --git a/Tests/MapboxMapsTests/Style/Fixtures/SourceProperties+Fixtures.swift b/Tests/MapboxMapsTests/Style/Fixtures/SourceProperties+Fixtures.swift index 29df9ec50642..12954311ee42 100644 --- a/Tests/MapboxMapsTests/Style/Fixtures/SourceProperties+Fixtures.swift +++ b/Tests/MapboxMapsTests/Style/Fixtures/SourceProperties+Fixtures.swift @@ -20,8 +20,7 @@ extension GeoJSONSourceData: Equatable { case (let .url(lhsURL), let .url(rhsURL)): return lhsURL == rhsURL case (let .feature(lhsFeature), let .feature(rhsFeature)): - // TODO: Fix temporary conformance to equatable for Turf features in tests - return lhsFeature.geometry.type == rhsFeature.geometry.type + return lhsFeature == rhsFeature default: return false } diff --git a/Tests/MapboxMapsTests/Style/GeoJSONSourceDataTests.swift b/Tests/MapboxMapsTests/Style/GeoJSONSourceDataTests.swift index a29742220eea..a5b448ed2234 100644 --- a/Tests/MapboxMapsTests/Style/GeoJSONSourceDataTests.swift +++ b/Tests/MapboxMapsTests/Style/GeoJSONSourceDataTests.swift @@ -44,7 +44,7 @@ class GeoJSONSourceDataTests: XCTestCase { if let validData = decodedSource?.data, case let GeoJSONSourceData.feature(feature) = validData { XCTAssert(feature.identifier != nil) - XCTAssert(feature.geometry.type == .Point) + if case .point = feature.geometry {} else { XCTFail() } } else { XCTFail("Failed to read decoded geojson fixture.") }