Skip to content

Commit 1782a8e

Browse files
committed
Implement custom equatable for Triple
It seems like equality for triples should depend on the parsed version and exclude the initial string representation. Eventually, we should probably get rid of storing the original string and compute that from the parsed version, but I am just trying to address equality for now.
1 parent 82a554a commit 1782a8e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Sources/TSCUtility/Triple.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ public struct Triple: Encodable, Equatable {
197197
fatalError("Failed to parse triple string (\(error)).\nTriple string: \(tripleString)")
198198
}
199199
}
200+
201+
public static func ==(lhs: Triple, rhs: Triple) -> Bool {
202+
return lhs.arch == rhs.arch && lhs.vendor == rhs.vendor && lhs.os == rhs.os && lhs.abi == rhs.abi && lhs.osVersion == rhs.osVersion && lhs.abiVersion == rhs.abiVersion
203+
}
200204
}
201205

202206
extension Triple {

Tests/TSCUtilityTests/TripleTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,13 @@ class TripleTests : XCTestCase {
3434
XCTAssertEqual(android!.os, .linux)
3535
XCTAssertEqual(android!.abiVersion, "24")
3636
}
37+
38+
func testEquality() throws {
39+
let macOSTriple = try Triple("arm64-apple-macos")
40+
let macOSXTriple = try Triple("arm64-apple-macosx")
41+
XCTAssertEqual(macOSTriple, macOSXTriple)
42+
43+
let intelMacOSTriple = try Triple("x86_64-apple-macos")
44+
XCTAssertNotEqual(macOSTriple, intelMacOSTriple)
45+
}
3746
}

0 commit comments

Comments
 (0)