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
3 changes: 2 additions & 1 deletion Sources/OpenGestures/Core/GestureTag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// MARK: - GestureTag

@frozen
public struct GestureTag: Hashable, Sendable, ExpressibleByStringLiteral, CustomStringConvertible {
public let rawValue: String

Expand All @@ -19,6 +20,6 @@ public struct GestureTag: Hashable, Sendable, ExpressibleByStringLiteral, Custom
}

public var description: String {
rawValue
"\"\(rawValue)\""
}
}
14 changes: 11 additions & 3 deletions Sources/OpenGestures/GestureNode/GestureNodeID.swift
Original file line number Diff line number Diff line change
@@ -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
}

Expand All @@ -13,6 +21,6 @@ public struct GestureNodeID: Hashable, Comparable, Sendable, CustomStringConvert
}

public var description: String {
"GestureNodeID(\(rawValue))"
rawValue.description
}
}
Original file line number Diff line number Diff line change
@@ -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<GestureTag> = []
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)
}
}
Original file line number Diff line number Diff line change
@@ -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<GestureNodeID> = []
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)
}
}
Loading