Skip to content

Commit 0cc1e70

Browse files
committed
Add GestureTraitCompatibilityTests
1 parent 1916948 commit 0cc1e70

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

Tests/OpenGesturesCompatibilityTests/GestureTrait/GestureTraitCompatibilityTests.swift

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,95 @@
44

55
import Testing
66

7+
// MARK: - GestureTraitCompatibilityTests
8+
9+
@Suite
10+
struct GestureTraitCompatibilityTests {
11+
@Test
12+
func initializer() {
13+
let trait = GestureTrait(id: .longPress, attributes: [:])
14+
_ = trait
15+
}
16+
17+
@Test
18+
func identifiable() {
19+
let box: any Identifiable = GestureTrait.tap()
20+
_ = box.id
21+
}
22+
23+
// MARK: - GestureTrait Factory Methods
24+
25+
@Test
26+
func pan() {
27+
let trait = GestureTrait.pan()
28+
#expect(trait.id == .pan)
29+
#expect(trait.attributes.isEmpty)
30+
}
31+
32+
@Test
33+
func tapDefaults() {
34+
let trait = GestureTrait.tap()
35+
#expect(trait.id == .tap)
36+
#expect(trait.attributes.isEmpty)
37+
}
38+
39+
@Test
40+
func tapWithParameters() {
41+
let trait = GestureTrait.tap(tapCount: 2, pointCount: 1)
42+
#expect(trait.id == .tap)
43+
#expect(trait.attributes[.tapCount] == .int(2))
44+
#expect(trait.attributes[.pointCount] == .int(1))
45+
}
46+
47+
@Test
48+
func longPressDefaults() {
49+
let trait = GestureTrait.longPress()
50+
#expect(trait.id == .longPress)
51+
#expect(trait.attributes.isEmpty)
52+
}
53+
54+
@Test
55+
func longPressWithParameters() {
56+
let trait = GestureTrait.longPress(
57+
pointCount: 1,
58+
minimumDuration: .seconds(0.5),
59+
maximumMovement: 10.0
60+
)
61+
#expect(trait.id == .longPress)
62+
#expect(trait.attributes[.pointCount] == .int(1))
63+
#expect(trait.attributes[.minimumDuration] == .double(0.5))
64+
#expect(trait.attributes[.maximumMovement] == .double(10.0))
65+
}
66+
67+
@Suite
68+
struct AttributeKeyCompatibilityTests {
69+
@Test(arguments: [
70+
(.pointCount, "pointCount"),
71+
(.tapCount, "tapCount"),
72+
(.minimumDuration, "minimumDuration"),
73+
(.maximumMovement, "maximumMovement"),
74+
] as [(GestureTrait.AttributeKey, String)])
75+
func description(_ key: GestureTrait.AttributeKey, _ expected: String) {
76+
#expect(key.description == expected)
77+
}
78+
}
79+
80+
// MARK: - AttributeValueCompatibilityTests
81+
82+
@Suite
83+
struct AttributeValueCompatibilityTests {
84+
@Test(arguments: [
85+
(.bool(true), "true"),
86+
(.bool(false), "false"),
87+
(.int(42), "42"),
88+
(.double(1.5), "1.5"),
89+
] as [(GestureTrait.AttributeValue, String)])
90+
func description(_ value: GestureTrait.AttributeValue, _ expected: String) {
91+
#expect(value.description == expected)
92+
}
93+
}
94+
}
95+
796
// MARK: - GestureTraitIDCompatibilityTests
897

998
@Suite

0 commit comments

Comments
 (0)