Tests/OrgAppTests/PaneLayoutTests.swift

d6defe0dc0a9a2097c50011a25c810644b5ffaef
orgstar/Tests/OrgAppTests/PaneLayoutTests.swift

38 lines · 2081 bytes

 1import Testing
 2@testable import OrgApp
 3
 4struct PaneLayoutTests {
 5    @Test func splitsNestAndReadInOrder() {
 6        let a = PaneID(), b = PaneID(), c = PaneID()
 7        var layout = PaneLayout.pane(a)
 8        layout = layout.splitting(a, axis: .horizontal, new: b)
 9        layout = layout.splitting(b, axis: .vertical, new: c)
10        #expect(layout.panes == [a, b, c])
11        #expect(layout == .split(axis: .horizontal, first: .pane(a), second: .split(axis: .vertical, first: .pane(b), second: .pane(c), fraction: 0.5), fraction: 0.5))
12    }
13
14    @Test func removingAPaneCollapsesItsSplit() {
15        let a = PaneID(), b = PaneID(), c = PaneID()
16        let layout = PaneLayout.pane(a).splitting(a, axis: .horizontal, new: b).splitting(b, axis: .vertical, new: c)
17        #expect(layout.removing(b) == .split(axis: .horizontal, first: .pane(a), second: .pane(c), fraction: 0.5))
18        #expect(layout.removing(a)?.panes == [b, c])
19        #expect(PaneLayout.pane(a).removing(a) == nil)
20    }
21
22    @Test func settingAFractionFindsTheSplitByItsFirstPane() {
23        let a = PaneID(), b = PaneID(), c = PaneID()
24        let layout = PaneLayout.pane(a).splitting(a, axis: .horizontal, new: b).splitting(b, axis: .vertical, new: c)
25        let inner = layout.settingFraction(0.3, ofSplitStartingWith: b)
26        #expect(inner == .split(axis: .horizontal, first: .pane(a), second: .split(axis: .vertical, first: .pane(b), second: .pane(c), fraction: 0.3), fraction: 0.5))
27        #expect(layout.settingFraction(2, ofSplitStartingWith: a) == .split(axis: .horizontal, first: .pane(a), second: .split(axis: .vertical, first: .pane(b), second: .pane(c), fraction: 0.5), fraction: 0.9))
28    }
29
30    @Test func onlyAndNext() {
31        let a = PaneID(), b = PaneID(), c = PaneID()
32        let layout = PaneLayout.pane(a).splitting(a, axis: .horizontal, new: b).splitting(b, axis: .vertical, new: c)
33        #expect(layout.only(b) == .pane(b))
34        #expect(layout.next(after: a) == b)
35        #expect(layout.next(after: c) == a)
36        #expect(layout.next(after: PaneID()) == a)
37    }
38}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form