From 97fcb79722a8ea4e0a68e7df84402a6abc8df577 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Mon, 24 Jun 2024 07:46:35 -0700 Subject: [PATCH] Add geoURL format to string coordinate extension --- .../LocationFormatter/Extensions/String.swift | 3 ++- .../LocationCoordinateFormatterTests.swift | 12 ++++++++++++ .../UTMCoordinateFormatterTests.swift | 1 - .../LocationFormatterTests/StringTests.swift | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Tests/LocationFormatterTests/StringTests.swift diff --git a/Sources/LocationFormatter/Extensions/String.swift b/Sources/LocationFormatter/Extensions/String.swift index a167fa5..4564e35 100644 --- a/Sources/LocationFormatter/Extensions/String.swift +++ b/Sources/LocationFormatter/Extensions/String.swift @@ -15,7 +15,8 @@ public extension String { LocationCoordinateFormatter(format: .decimalDegrees), LocationCoordinateFormatter(format: .degreesDecimalMinutes), LocationCoordinateFormatter(format: .degreesMinutesSeconds), - LocationCoordinateFormatter(format: .utm) + LocationCoordinateFormatter(format: .utm), + LocationCoordinateFormatter(format: .geoURI), ] for formatter in formatters { diff --git a/Tests/LocationFormatterTests/Formatters/LocationCoordinateFormatterTests.swift b/Tests/LocationFormatterTests/Formatters/LocationCoordinateFormatterTests.swift index 9820069..1ece08d 100644 --- a/Tests/LocationFormatterTests/Formatters/LocationCoordinateFormatterTests.swift +++ b/Tests/LocationFormatterTests/Formatters/LocationCoordinateFormatterTests.swift @@ -51,6 +51,18 @@ struct LocationCoordinateFormatterTests { #expect(formatter.string(from: CLLocationCoordinate2D.nullIsland) == "31N 166021m E 000000m N") } + @Test func geoURI() { + let formatter = LocationCoordinateFormatter(format: .geoURI) + + #expect(formatter.string(from: CLLocationCoordinate2D.portTownsend) == "geo:48.11638,-122.77527") + #expect(formatter.string(from: CLLocationCoordinate2D.capeHorn) == "geo:-55.97917,-67.275") + #expect(formatter.string(from: CLLocationCoordinate2D.seychelles) == "geo:-4.67785,55.46718") + #expect(formatter.string(from: CLLocationCoordinate2D.capeHorn) == "geo:-55.97917,-67.275") + #expect(formatter.string(from: CLLocationCoordinate2D.faroeIslands) == "geo:62.06323,-6.87355") + #expect(formatter.string(from: CLLocationCoordinate2D.pointNemo) == "geo:-48.876667,-123.393333") + + } + @Suite struct SymbolStyle { @Test func none() { diff --git a/Tests/LocationFormatterTests/Formatters/UTMCoordinateFormatterTests.swift b/Tests/LocationFormatterTests/Formatters/UTMCoordinateFormatterTests.swift index 5bd24e1..353dff0 100644 --- a/Tests/LocationFormatterTests/Formatters/UTMCoordinateFormatterTests.swift +++ b/Tests/LocationFormatterTests/Formatters/UTMCoordinateFormatterTests.swift @@ -142,7 +142,6 @@ struct UTMCoordinateFormatterTests { #expect(coordinate.latitude.isApproximatelyEqual(to: 48.116380622937946, absoluteTolerance: 0.00001)) #expect(coordinate.longitude.isApproximatelyEqual(to: -122.77527139988439, absoluteTolerance: 0.00001)) } - } } } diff --git a/Tests/LocationFormatterTests/StringTests.swift b/Tests/LocationFormatterTests/StringTests.swift new file mode 100644 index 0000000..d5a0f05 --- /dev/null +++ b/Tests/LocationFormatterTests/StringTests.swift @@ -0,0 +1,19 @@ +import Testing +import CoreLocation +import Numerics +@testable import LocationFormatter + +struct StringTests { + + @Test(arguments: [ + "48.11638° N, 122.77527° W", // decimalDegrees + "48° 06.983′ N, 122° 46.516′ W", // degreesDecimalMinutes + "48° 6′ 59″ N, 122° 46′ 31″ W", // degreesMinutesSeconds + "10U 516726m E 5329260m N", // UTM + "geo:48.11638,-122.77527" // GeoURI + ]) func coordinate(string: String) throws { + let coordinate = try #require(string.coordinate()) + #expect(coordinate.isApproximatelyEqual(to: .portTownsend, absoluteTolerance: 0.0001)) + } + +}