Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172import Foundationimport ParcelConfigimport Testing
@Suitestruct DocumentationExamplesTests { @Test(arguments: ["README.md", "Sources/ParcelConfig/ParcelConfig.docc/ParcelConfig.md"]) func documentedTOMLLoadsWithoutDiagnostics(path: String) async throws { let root = URL(fileURLWithPath: #filePath) .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() let markdown = try String(contentsOf: root.appendingPathComponent(path), encoding: .utf8) let examples = markdown.components(separatedBy: "```toml\n").dropFirst() try #require(!examples.isEmpty) for example in examples { let source = try #require(example.components(separatedBy: "```").first) #expect(source.hasPrefix("#:schema \(ConfigJSONSchema.publishedURL)\n")) let snapshot = await ConfigStore().load(source: source) #expect(snapshot.loadState == .loaded) #expect(snapshot.diagnostics.isEmpty) } }
@Test(arguments: ["README.md", "docs/configuration.md"]) func shortcutTablesMatchDefaults(path: String) throws { let root = URL(fileURLWithPath: #filePath) .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() let markdown = try String(contentsOf: root.appendingPathComponent(path), encoding: .utf8) let heading = path == "README.md" ? "## Shortcuts\n" : "## Shortcuts and motion\n" let section = try #require(markdown.components(separatedBy: heading).dropFirst().first) .components(separatedBy: "\n## ").first ?? "" let rows = section.components(separatedBy: "\n").filter { $0.hasPrefix("| ") } #expect(rows.count > 2) #expect(rows.first == "| Action | Shortcut |") let bindings = ParcelConfiguration.defaults.keybindings #expect(bindings == DefaultKeybindings.bindings()) var documented: Set<ConfigCommand> = [] for row in rows.dropFirst(2) { let cells = row.split(separator: "|", omittingEmptySubsequences: false) try #require(cells.count == 4) let label = cells[1].trimmingCharacters(in: .whitespaces) let commands = try #require(shortcutRows[label], "Unknown shortcut row: \(label)") let shortcuts = try commands.map { command in shortcutText(try #require(bindings[command], "Missing default: \(command)")) } #expect(cells[2].trimmingCharacters(in: .whitespaces) == shortcuts.joined(separator: " / ")) for command in commands { #expect(documented.insert(command).inserted, "Duplicate shortcut: \(command)") } } if path == "docs/configuration.md" { #expect(documented == Set(bindings.keys)) } else { #expect( documented.isSuperset(of: [ .swapLeft, .focusLeft, .floatToggle, .alwaysFloat, .toggleFocus, .toggleNoPeek, .toggleCleanSpace, .toggleAutomaticTiling, .ratioIncrease, .ratioDecrease, .tabView, ])) } }
@Test func shiftedPrefixAlternatesMatchConfigurationGuide() throws { let root = URL(fileURLWithPath: #filePath) .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() let markdown = try String(contentsOf: root.appendingPathComponent("docs/configuration.md"), encoding: .utf8) let normal = DefaultKeybindings.bindings() let shifted = DefaultKeybindings.bindings(prefix: [.ctrl, .alt, .shift]) let alternatives: [ConfigCommand] = [ .focusLeft, .focusRight, .focusUp, .focusDown, .moveRight, .stackPrevious, .alwaysFloat, .layoutTree, .windowControls, ] let changed = Set(normal.keys.filter { normal[$0]?.key != shifted[$0]?.key }) #expect(changed == Set(alternatives)) let keys = try alternatives.map { command in let chord = try #require(shifted[command]) #expect(chord.modifiers == [.ctrl, .alt, .shift]) return chord.key == .backslash ? "backslash" : chord.key.rawValue.uppercased() } let paragraph = "If the prefix includes Shift, focus uses \(keys[0...3].joined(separator: "/")), move right uses \(keys[4]),\n" + "previous stack member uses \(keys[5]), always float uses \(keys[6]), and Tree uses \(keys[7]).\n" + "Window controls uses \(keys[8]).\n" + "Other keys remain the same." #expect(markdown.contains(paragraph)) }
@Test func cliShortcutGuideLinksToCheckedDefaults() throws { let root = URL(fileURLWithPath: #filePath) .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() let markdown = try String(contentsOf: root.appendingPathComponent("docs/command-line.md"), encoding: .utf8) let section = try #require(markdown.components(separatedBy: "## Default command shortcuts\n").dropFirst().first) .components(separatedBy: "\n## ").first ?? "" #expect(section.contains("configuration.md#shortcuts-and-motion")) #expect(!section.contains("\n|")) }
@Test func configDocumentationListsNewCommandsAndModeAPI() throws { let root = URL(fileURLWithPath: #filePath) .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent() let markdown = try String( contentsOf: root.appendingPathComponent("Sources/ParcelConfig/ParcelConfig.docc/ParcelConfig.md"), encoding: .utf8) let commands: [ConfigCommand] = [ .layoutTree, .layoutBSP, .layoutAccordion, .splitHorizontal, .splitVertical, .joinLeft, .joinRight, .joinUp, .joinDown, .balance, .rotate, .mirrorHorizontal, .mirrorVertical, .ratioHalf, .ratioThreeFifths, .ratioTwoThirds, ] + ConfigCommand.allCases.filter(\.isSpaceCommand) for command in commands { let name = try #require(command.rawValue.split(separator: " ").first) #expect(markdown.contains(name)) } for name in ["BindingAction", "defaultModeEntries", "validateBindingModes()", "enter-mode", "exit-mode"] { #expect(markdown.contains(name)) } }}
private let shortcutRows: [String: [ConfigCommand]] = [ "Swap left / right / up / down": [.swapLeft, .swapRight, .swapUp, .swapDown], "Focus left / right / up / down": [.focusLeft, .focusRight, .focusUp, .focusDown], "Move left / right / up / down": [.moveLeft, .moveRight, .moveUp, .moveDown], "Make primary": [.makePrimary], "Window controls": [.windowControls], "Next / previous window": [.windowNext, .windowPrevious], "Stack / unstack": [.stack, .unstack], "Next / previous stack member": [.stackNext, .stackPrevious], "Grow / shrink / reset sizes": [.ratioIncrease, .ratioDecrease, .resetSizes], "Float / tile; always float": [.floatToggle, .alwaysFloat], "Focus / No Peek / Clean Space": [.toggleFocus, .toggleNoPeek, .toggleCleanSpace], "Automatic tiling": [.toggleAutomaticTiling], "Retile": [.retile], "Grid / Columns / Rows / Side / Tree / BSP / Accordion": [ .layoutGrid, .layoutColumns, .layoutRows, .layoutSide, .layoutTree, .layoutBSP, .layoutAccordion, ], "Horizontal / vertical split": [.splitHorizontal, .splitVertical], "Join left / right / up / down": [.joinLeft, .joinRight, .joinUp, .joinDown], "Balance / rotate / mirror horizontally / vertically": [.balance, .rotate, .mirrorHorizontal, .mirrorVertical], "Window cap 1 / 2 / 3 / 4 / 5": [ .setWindowCap(1), .setWindowCap(2), .setWindowCap(3), .setWindowCap(4), .setWindowCap(5), ], "Snap left / right / top / bottom half": [.snapLeftHalf, .snapRightHalf, .snapTopHalf, .snapBottomHalf], "Undo / undo last rule": [.undo, .undoLastRule], "Close / fullscreen / hover focus": [.close, .toggleFullscreen, .toggleHoverFocus], "Move to display left / right / up / down": [ .displayMoveLeft, .displayMoveRight, .displayMoveUp, .displayMoveDown, ], "Tab View": [.tabView], "Settings / Quit": [.openSettings, .quit],]
private func shortcutText(_ chord: KeyChord) -> String { let modifiers: [(KeyModifiers, String)] = [(.ctrl, "⌃"), (.alt, "⌥"), (.cmd, "⌘"), (.shift, "⇧"), (.fn, "fn")] let prefix = modifiers.filter { chord.modifiers.contains($0.0) }.map(\.1).joined() let key: String = switch chord.key { case .left: "←" case .right: "→" case .up: "↑" case .down: "↓" case .minus: "−" case .grave: "<kbd>`</kbd>" case .return: "Return" case .space: "Space" case .tab: "Tab" case .delete: "Delete" default: chord.key.rawValue.uppercased() } return prefix + key}