From b5da8980271f2c19ed1fff2022faf475e873aaba Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 6 Apr 2026 23:31:25 +0800 Subject: [PATCH 1/2] Fix GestureTag --- Sources/OpenGestures/Core/GestureTag.swift | 3 +- .../Core/GestureTagCompatibilityTests.swift | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Tests/OpenGesturesCompatibilityTests/Core/GestureTagCompatibilityTests.swift diff --git a/Sources/OpenGestures/Core/GestureTag.swift b/Sources/OpenGestures/Core/GestureTag.swift index 07729c3..3a56abe 100644 --- a/Sources/OpenGestures/Core/GestureTag.swift +++ b/Sources/OpenGestures/Core/GestureTag.swift @@ -7,6 +7,7 @@ // MARK: - GestureTag +@frozen public struct GestureTag: Hashable, Sendable, ExpressibleByStringLiteral, CustomStringConvertible { public let rawValue: String @@ -19,6 +20,6 @@ public struct GestureTag: Hashable, Sendable, ExpressibleByStringLiteral, Custom } public var description: String { - rawValue + "\"\(rawValue)\"" } } diff --git a/Tests/OpenGesturesCompatibilityTests/Core/GestureTagCompatibilityTests.swift b/Tests/OpenGesturesCompatibilityTests/Core/GestureTagCompatibilityTests.swift new file mode 100644 index 0000000..1d917e7 --- /dev/null +++ b/Tests/OpenGesturesCompatibilityTests/Core/GestureTagCompatibilityTests.swift @@ -0,0 +1,45 @@ +// +// GestureTagCompatibilityTests.swift +// OpenGesturesCompatibilityTests + +import Testing + +struct GestureTagCompatibilityTests { + @Test + func initWithRawValue() { + let tag = GestureTag(rawValue: "tap") + #expect(tag.rawValue == "tap") + } + + @Test + func stringLiteral() { + let tag: GestureTag = "pan" + #expect(tag.rawValue == "pan") + } + + @Test + func equality() { + let a: GestureTag = "tap" + let b = GestureTag(rawValue: "tap") + let c: GestureTag = "pan" + #expect(a == b) + #expect(a != c) + } + + @Test + func hashable() { + var set: Set = [] + set.insert("tap") + set.insert("tap") + set.insert("pan") + #expect(set.count == 2) + } + + @Test(arguments: [ + (GestureTag(rawValue: "tap"), "\"tap\""), + (GestureTag(rawValue: "longPress"), "\"longPress\""), + ]) + func description(_ tag: GestureTag, _ expected: String) { + #expect(tag.description == expected) + } +} From fe245d28ce66cb17ca5b6cbcfc579848444bf869 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 6 Apr 2026 23:31:37 +0800 Subject: [PATCH 2/2] Add GestureNodeID --- .../GestureNode/GestureNodeID.swift | 14 ++++-- .../GestureNodeIDCompatibilityTests.swift | 49 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 Tests/OpenGesturesCompatibilityTests/GestureNode/GestureNodeIDCompatibilityTests.swift diff --git a/Sources/OpenGestures/GestureNode/GestureNodeID.swift b/Sources/OpenGestures/GestureNode/GestureNodeID.swift index 302f058..b91c6dc 100644 --- a/Sources/OpenGestures/GestureNode/GestureNodeID.swift +++ b/Sources/OpenGestures/GestureNode/GestureNodeID.swift @@ -1,10 +1,18 @@ +// +// GestureNodeID.swift +// OpenGestures +// +// Audited for 9126.1.5 +// Status: Complete + // MARK: - GestureNodeID /// A unique identifier for a gesture node. +@frozen public struct GestureNodeID: Hashable, Comparable, Sendable, CustomStringConvertible { - public var rawValue: UInt32 + package let rawValue: UInt32 - public init(rawValue: UInt32) { + package init(rawValue: UInt32) { self.rawValue = rawValue } @@ -13,6 +21,6 @@ public struct GestureNodeID: Hashable, Comparable, Sendable, CustomStringConvert } public var description: String { - "GestureNodeID(\(rawValue))" + rawValue.description } } diff --git a/Tests/OpenGesturesCompatibilityTests/GestureNode/GestureNodeIDCompatibilityTests.swift b/Tests/OpenGesturesCompatibilityTests/GestureNode/GestureNodeIDCompatibilityTests.swift new file mode 100644 index 0000000..e7feb5d --- /dev/null +++ b/Tests/OpenGesturesCompatibilityTests/GestureNode/GestureNodeIDCompatibilityTests.swift @@ -0,0 +1,49 @@ +// +// GestureNodeIDCompatibilityTests.swift +// OpenGesturesCompatibilityTests + +import Testing + +#if !OPENGESTURES +extension GestureNodeID { + init(rawValue: UInt32) { + self = unsafeBitCast(rawValue, to: GestureNodeID.self) + } +} +#endif + +struct GestureNodeIDCompatibilityTests { + @Test + func equality() { + let a = GestureNodeID(rawValue: 1) + let b = GestureNodeID(rawValue: 1) + let c = GestureNodeID(rawValue: 2) + #expect(a == b) + #expect(a != c) + } + + @Test + func comparable() { + let a = GestureNodeID(rawValue: 1) + let b = GestureNodeID(rawValue: 2) + #expect(a < b) + #expect(!(b < a)) + } + + @Test + func hashable() { + var set: Set = [] + set.insert(GestureNodeID(rawValue: 1)) + set.insert(GestureNodeID(rawValue: 1)) + set.insert(GestureNodeID(rawValue: 2)) + #expect(set.count == 2) + } + + @Test(arguments: [ + (GestureNodeID(rawValue: 0), "0"), + (GestureNodeID(rawValue: 42), "42"), + ]) + func description(_ id: GestureNodeID, _ expected: String) { + #expect(id.description == expected) + } +}