Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,34 @@ permissions:

jobs:
macos-tests:
name: macOS Tests (Swift ${{ matrix.swift }})
name: macOS Tests (${{ matrix.name }})
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
swift: ["6.0"]
include:
- name: "Xcode 16.0"
swift: "6.0"
xcode: "16.0"
- name: "Xcode 16.1"
swift: "6.0"
xcode: "16.1"

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Select Xcode for Swift ${{ matrix.swift }}
run: |
sudo xcode-select -s /Applications/Xcode_16.1.app
swift --version

- name: Select Xcode ${{ matrix.xcode }}
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode }}

- name: Show Swift version
run: swift --version

- name: Build
run: swift build

- name: Run tests
run: swift test
run: swift test
6 changes: 3 additions & 3 deletions Sources/DIGIPIN/DIGIPIN.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

/// Errors that can occur during DIGIPIN encoding or decoding.
public enum DIGIPINError: Error, Equatable, CustomStringConvertible {
public enum DIGIPINError: Error, Equatable, CustomStringConvertible, Sendable {
/// The provided coordinates are outside the supported bounds for India.
case outOfBounds
/// The provided DIGIPIN code is invalid or malformed.
Expand All @@ -22,7 +22,7 @@ public enum DIGIPINError: Error, Equatable, CustomStringConvertible {
}

/// Represents a geographic coordinate (latitude and longitude).
public struct Coordinate: Equatable, CustomStringConvertible {
public struct Coordinate: Equatable, CustomStringConvertible, Sendable {
/// Latitude in decimal degrees (WGS84).
public let latitude: Double
/// Longitude in decimal degrees (WGS84).
Expand All @@ -43,7 +43,7 @@ public struct Coordinate: Equatable, CustomStringConvertible {
}

/// DIGIPIN encoder/decoder for India Post's Digital Postal Index Number system.
public struct DIGIPIN {
public struct DIGIPIN: Sendable {
// MARK: - Constants

/// The official 4x4 DIGIPIN grid used at all levels.
Expand Down
17 changes: 17 additions & 0 deletions Tests/DIGIPINTests/DIGIPINTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,21 @@ final class DIGIPINTests: XCTestCase {
XCTFail("Third code should fail with invalidDIGIPIN")
}
}

func testDIGIPINCanBeStoredInSendableType() throws {
struct LocationService: Sendable {
let maxDistanceKm: Double
let digipin = DIGIPIN()

func code(for coordinate: Coordinate) throws -> String {
try digipin.generateDIGIPIN(for: coordinate)
}
}

let service = LocationService(maxDistanceKm: 5)
let coordinate = Coordinate(latitude: 28.622788, longitude: 77.213033)

XCTAssertEqual(service.maxDistanceKm, 5)
XCTAssertEqual(try service.code(for: coordinate), "39J-49L-L8T4")
}
}
Loading