Skip to content

Commit 9839901

Browse files
committed
Add compatibility tests for initializing Attribute with Rule/StatefuleRule and initial value
1 parent a8028a7 commit 9839901

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Tests/OpenAttributeGraphCompatibilityTests/Attribute/Attribute/AttributeCompatibilityTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@ struct AttributeCompatibilityTests {
1414
#expect(intAttribute.value == 0)
1515
}
1616

17+
@Test
18+
func initWithRule() {
19+
struct TestRule: Rule {
20+
var value: Int {
21+
return 0
22+
}
23+
}
24+
let attribute1 = Attribute(TestRule())
25+
#expect(attribute1.value == 0)
26+
27+
let attribute2 = Attribute(TestRule(), initialValue: 1)
28+
#expect(attribute2.value == 1)
29+
}
30+
31+
@Test
32+
func initWithStatefulRule() {
33+
struct TestStatefuleRule: StatefulRule {
34+
typealias Value = Int
35+
func updateValue() {
36+
withUnsafePointer(to: 0) { ptr in
37+
Graph.setOutputValue(ptr)
38+
}
39+
}
40+
}
41+
let attribute1 = Attribute(TestStatefuleRule())
42+
#expect(attribute1.value == 0)
43+
44+
let attribute2 = Attribute(TestStatefuleRule(), initialValue: 1)
45+
#expect(attribute2.value == 1)
46+
}
47+
1748
@Test
1849
func hashableAndEquatable() {
1950
let a = Attribute<Int>(identifier: .nil)

0 commit comments

Comments
 (0)