tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 497HTML 254C 19JavaScript 81329 Definiciones

⎇ bce89b1006f36ce35abfaf1f1c2b3dd95f3dffd3 bindings/swift/Example/Tests/NodeSpec.swift 90 líneas · 3.2 KB Historia crudo

Implement new rust API for bindings and release v0.3 bce89b100 · Emil Sjölander ·

1import Quick
2import Nimble
3import StretchKit
4
5class NodeSpec: QuickSpec {
6    override func spec() {
7        it("will create node") {
8            let child = Node(style: Style(), children: [])
9            let node = Node(style: Style(), children: [child])
10            expect(node.children.count) == 1
11        }
12        
13        it("will create leaf") {
14            let node = Node(style: Style()) { constraint in
15                return Size(width: 100.0, height: 100.0)
16            }
17
18            let layout = node.computeLayout(thatFits: Size(width: nil, height: nil))
19            expect(layout.width) == 100.0
20            expect(layout.height) == 100.0
21        }
22
23        it("will set measure") {
24            let node = Node(style: Style(), children: [])
25            node.measure = { constraint in
26                return Size(width: 100.0, height: 100.0)
27            }
28
29            let layout = node.computeLayout(thatFits: Size(width: nil, height: nil))
30            expect(layout.width) == 100.0
31            expect(layout.height) == 100.0
32        }
33
34        it("will add child") {
35            let node = Node(style: Style(), children: [])
36            let child = Node(style: Style(), children: [])
37            node.addChild(child)
38            expect(node.children.count) == 1
39        }
40
41        it("will remove child") {
42            let child = Node(style: Style(), children: [])
43            let node = Node(style: Style(), children: [child])
44            node.removeChild(child)
45            expect(node.children.count) == 0
46        }
47
48        it("will remove child at index") {
49            let child = Node(style: Style(), children: [])
50            let node = Node(style: Style(), children: [child])
51            node.removeChild(at: 0)
52            expect(node.children.count) == 0
53        }
54
55        it("will replace child at index") {
56            let child1 = Node(style: Style(size: Size(width: .points(100.0), height: .points(100.0))), children: [])
57            let child2 = Node(style: Style(size: Size(width: .points(200.0), height: .points(200.0))), children: [])
58            let node = Node(style: Style(), children: [child1])
59            node.replaceChild(child2, at: 0)
60
61            let layout = node.computeLayout(thatFits: Size(width: nil, height: nil))
62            expect(layout.width) == 200.0
63            expect(layout.height) == 200.0
64        }
65
66        it("will set style") {
67            let node = Node(style: Style(size: Size(width: .points(100.0), height: .points(100.0))), children: [])
68            node.style = Style(size: Size(width: .points(200.0), height: .points(200.0)))
69
70            let layout = node.computeLayout(thatFits: Size(width: nil, height: nil))
71            expect(layout.width) == 200.0
72            expect(layout.height) == 200.0
73        }
74
75        it("will set children") {
76            let node = Node(style: Style(), children: [])
77            let child = Node(style: Style(), children: [])
78            node.children = [child]
79            expect(node.children.count) == 1
80        }
81
82        it("will mark node dirty") {
83            let node = Node(style: Style(), children: [])
84            let _ = node.computeLayout(thatFits: Size(width: nil, height: nil))
85            expect(node.dirty) == false
86            node.markDirty()
87            expect(node.dirty) == true
88        }
89    }
90}