Tests/OrgAppTests/PaneLayoutTests.swift
42 lines · 2740 bytes
5 symbols in this file
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, ofSplitBetween: b, and: c)
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, ofSplitBetween: a, and: b) == .split(axis: .horizontal, first: .pane(a), second: .split(axis: .vertical, first: .pane(b), second: .pane(c), fraction: 0.5), fraction: 0.9))
28 // A nested split on the first side shares its first pane with the outer split.
29 let nestedFirst = PaneLayout.pane(a).splitting(a, axis: .horizontal, new: b).splitting(a, axis: .vertical, new: c)
30 #expect(nestedFirst.settingFraction(0.3, ofSplitBetween: a, and: c) == .split(axis: .horizontal, first: .split(axis: .vertical, first: .pane(a), second: .pane(c), fraction: 0.3), second: .pane(b), fraction: 0.5))
31 #expect(nestedFirst.settingFraction(0.3, ofSplitBetween: c, and: b) == .split(axis: .horizontal, first: .split(axis: .vertical, first: .pane(a), second: .pane(c), fraction: 0.5), second: .pane(b), fraction: 0.3))
32 }
33
34 @Test func onlyAndNext() {
35 let a = PaneID(), b = PaneID(), c = PaneID()
36 let layout = PaneLayout.pane(a).splitting(a, axis: .horizontal, new: b).splitting(b, axis: .vertical, new: c)
37 #expect(layout.only(b) == .pane(b))
38 #expect(layout.next(after: a) == b)
39 #expect(layout.next(after: c) == a)
40 #expect(layout.next(after: PaneID()) == a)
41 }
42}