Files
ghostty/macos/Tests/CommandPaletteTests.swift
2026-08-06 15:11:48 +02:00

50 lines
1.5 KiB
Swift

//
// CommandPaletteTests.swift
// GhosttyTests
//
// Tests for command palette query filtering and match ranking.
//
import Testing
import SwiftUI
@testable import Ghostty
struct CommandPaletteFilterTests {
private func option(
title: String,
subtitle: String? = nil,
description: String? = nil,
leadingColor: Color? = nil
) -> CommandOption {
CommandOption(
title: title,
subtitle: subtitle,
description: description,
leadingColor: leadingColor
) {}
}
/// Title matches outrank subtitle matches, which outrank description
/// matches. Options that don't match at all are dropped.
@Test func textMatchTiers() {
let byDescription = option(title: "Alpha", description: "make it fast")
let bySubtitle = option(title: "Beta", subtitle: "fast scrolling")
let byTitle = option(title: "Fast Redraw")
let noMatch = option(title: "Quit")
let results = [noMatch, byDescription, bySubtitle, byTitle]
.filteredAndSorted(query: "fast")
#expect(results == [byTitle, bySubtitle, byDescription])
}
/// Options with equal scores keep their original relative order.
@Test func tiesPreserveOriginalOrder() {
let first = option(title: "New Window")
let second = option(title: "New Tab")
#expect([first, second].filteredAndSorted(query: "new") == [first, second])
#expect([second, first].filteredAndSorted(query: "new") == [second, first])
}
}