|
| 1 | +@testable import AppBundle |
| 2 | +import Common |
| 3 | +import XCTest |
| 4 | + |
| 5 | +@MainActor |
| 6 | +final class SwapCommandTest: XCTestCase { |
| 7 | + override func setUp() async throws { setUpWorkspacesForTests() } |
| 8 | + |
| 9 | + func testSwap_swapWindows_Directional() { |
| 10 | + let root = Workspace.get(byName: name).rootTilingContainer.apply { |
| 11 | + TilingContainer.newVTiles(parent: $0, adaptiveWeight: 1).apply { |
| 12 | + assertEquals(TestWindow.new(id: 1, parent: $0).focusWindow(), true) |
| 13 | + TestWindow.new(id: 2, parent: $0) |
| 14 | + } |
| 15 | + TestWindow.new(id: 3, parent: $0) |
| 16 | + } |
| 17 | + |
| 18 | + SwapCommand(args: SwapCmdArgs(rawArgs: [], target: .direction(.right))).run(.defaultEnv, .emptyStdin) |
| 19 | + assertEquals(root.layoutDescription, |
| 20 | + .h_tiles([.v_tiles([.window(3), .window(2)]), |
| 21 | + .window(1)])) |
| 22 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 23 | + |
| 24 | + SwapCommand(args: SwapCmdArgs(rawArgs: [], target: .direction(.left))).run(.defaultEnv, .emptyStdin) |
| 25 | + assertEquals(root.layoutDescription, |
| 26 | + .h_tiles([.v_tiles([.window(1), .window(2)]), |
| 27 | + .window(3)])) |
| 28 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 29 | + |
| 30 | + SwapCommand(args: SwapCmdArgs(rawArgs: [], target: .direction(.down))).run(.defaultEnv, .emptyStdin) |
| 31 | + assertEquals(root.layoutDescription, |
| 32 | + .h_tiles([.v_tiles([.window(2), .window(1)]), |
| 33 | + .window(3)])) |
| 34 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 35 | + |
| 36 | + SwapCommand(args: SwapCmdArgs(rawArgs: [], target: .direction(.up))).run(.defaultEnv, .emptyStdin) |
| 37 | + assertEquals(root.layoutDescription, |
| 38 | + .h_tiles([.v_tiles([.window(1), .window(2)]), |
| 39 | + .window(3)])) |
| 40 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 41 | + } |
| 42 | + |
| 43 | + func testSwap_swapWindows_DfsRelative() { |
| 44 | + let root = Workspace.get(byName: name).rootTilingContainer.apply { |
| 45 | + TilingContainer.newVTiles(parent: $0, adaptiveWeight: 1).apply { |
| 46 | + assertEquals(TestWindow.new(id: 1, parent: $0).focusWindow(), true) |
| 47 | + TestWindow.new(id: 2, parent: $0) |
| 48 | + } |
| 49 | + TestWindow.new(id: 3, parent: $0) |
| 50 | + } |
| 51 | + |
| 52 | + SwapCommand(args: SwapCmdArgs(rawArgs: [], target: .dfsRelative(.dfsNext))).run(.defaultEnv, .emptyStdin) |
| 53 | + assertEquals(root.layoutDescription, |
| 54 | + .h_tiles([.v_tiles([.window(2), .window(1)]), |
| 55 | + .window(3)])) |
| 56 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 57 | + |
| 58 | + SwapCommand(args: SwapCmdArgs(rawArgs: [], target: .dfsRelative(.dfsNext))).run(.defaultEnv, .emptyStdin) |
| 59 | + assertEquals(root.layoutDescription, |
| 60 | + .h_tiles([.v_tiles([.window(2), .window(3)]), |
| 61 | + .window(1)])) |
| 62 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 63 | + |
| 64 | + SwapCommand(args: SwapCmdArgs(rawArgs: [], target: .dfsRelative(.dfsPrev))).run(.defaultEnv, .emptyStdin) |
| 65 | + assertEquals(root.layoutDescription, |
| 66 | + .h_tiles([.v_tiles([.window(2), .window(1)]), |
| 67 | + .window(3)])) |
| 68 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 69 | + |
| 70 | + SwapCommand(args: SwapCmdArgs(rawArgs: [], target: .dfsRelative(.dfsPrev))).run(.defaultEnv, .emptyStdin) |
| 71 | + assertEquals(root.layoutDescription, |
| 72 | + .h_tiles([.v_tiles([.window(1), .window(2)]), |
| 73 | + .window(3)])) |
| 74 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 75 | + } |
| 76 | + |
| 77 | + func testSwap_DirectionalWrapping() { |
| 78 | + let root = Workspace.get(byName: name).rootTilingContainer.apply { |
| 79 | + assertEquals(TestWindow.new(id: 1, parent: $0).focusWindow(), true) |
| 80 | + TestWindow.new(id: 2, parent: $0) |
| 81 | + TestWindow.new(id: 3, parent: $0) |
| 82 | + } |
| 83 | + |
| 84 | + var args = SwapCmdArgs(rawArgs: [], target: .direction(.left)) |
| 85 | + args.wrapAround = true |
| 86 | + SwapCommand(args: args).run(.defaultEnv, .emptyStdin) |
| 87 | + assertEquals(root.layoutDescription, .h_tiles([.window(3), .window(2), .window(1)])) |
| 88 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 89 | + |
| 90 | + args.target = .initialized(.direction(.right)) |
| 91 | + SwapCommand(args: args).run(.defaultEnv, .emptyStdin) |
| 92 | + assertEquals(root.layoutDescription, .h_tiles([.window(1), .window(2), .window(3)])) |
| 93 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 94 | + } |
| 95 | + |
| 96 | + func testSwap_DfsRelativeWrapping() { |
| 97 | + let root = Workspace.get(byName: name).rootTilingContainer.apply { |
| 98 | + assertEquals(TestWindow.new(id: 1, parent: $0).focusWindow(), true) |
| 99 | + TestWindow.new(id: 2, parent: $0) |
| 100 | + TestWindow.new(id: 3, parent: $0) |
| 101 | + } |
| 102 | + |
| 103 | + var args = SwapCmdArgs(rawArgs: [], target: .dfsRelative(.dfsPrev)) |
| 104 | + args.wrapAround = true |
| 105 | + SwapCommand(args: args).run(.defaultEnv, .emptyStdin) |
| 106 | + assertEquals(root.layoutDescription, .h_tiles([.window(3), .window(2), .window(1)])) |
| 107 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 108 | + |
| 109 | + args.target = .initialized(.dfsRelative(.dfsNext)) |
| 110 | + SwapCommand(args: args).run(.defaultEnv, .emptyStdin) |
| 111 | + assertEquals(root.layoutDescription, .h_tiles([.window(1), .window(2), .window(3)])) |
| 112 | + assertEquals(focus.windowOrNil?.windowId, 1) |
| 113 | + } |
| 114 | + |
| 115 | + func testSwap_SwapFocus() { |
| 116 | + let root = Workspace.get(byName: name).rootTilingContainer.apply { |
| 117 | + TestWindow.new(id: 1, parent: $0) |
| 118 | + assertEquals(TestWindow.new(id: 2, parent: $0).focusWindow(), true) |
| 119 | + TestWindow.new(id: 3, parent: $0) |
| 120 | + } |
| 121 | + |
| 122 | + var args = SwapCmdArgs(rawArgs: [], target: .direction(.right)) |
| 123 | + args.swapFocus = true |
| 124 | + SwapCommand(args: args).run(.defaultEnv, .emptyStdin) |
| 125 | + assertEquals(root.layoutDescription, .h_tiles([.window(1), .window(3), .window(2)])) |
| 126 | + assertEquals(focus.windowOrNil?.windowId, 3) |
| 127 | + } |
| 128 | +} |
0 commit comments