Files
museion/MuseionTests/PolishSeamTests.swift
AlexKucera d7fd11cf0d
CI / ci (push) Canceled after 0s
chore(lint): repo-wide green becomes the contract
Close the lint arc #194-#197: deliberate-style rule disables with
rationales (#194), filter-safe test renames + --test-case-name-format
preserve (#195), every surviving warning fixed through the sanctioned
lint-stable shapes (#196), and the docs now state the true contract
(#197): bare swiftlint . reports zero violations and swiftformat .
reformats nothing, while push gates stay scoped to the push's own
files (settled #190 design) — the pre-push hook's stale 'pre-existing
violations' rationale blocks refreshed, gate logic untouched.

Also in the sweep: quiesce the FSEvent-burst watcher race in
LibrarySearchTests (two rescans double-count one shared PostScanCache
miss; benign revision over-bump), pin the learnings scan's symlink-skip
contract (flip-verified — defended in depth by the lstat guard AND
contentsOfDirectory's own symlink refusal), reorder that scan's guard
so cheap rejections precede the directory listing, and park the roster
chmod window with a ceiling comment.

Finish-audit: 3 reviewers, 0 blocking; the one code finding was
disproved by probe (&& out-binds ?? — the guard was correct). Suite
693/693 via scripts/full-test.sh; swiftlint 0 violations; swiftformat
0/141; hook rig 23/23.

Closes #197
2026-11-17 16:29:46 +01:00

48 lines
2.0 KiB
Swift

//
// PolishSeamTests.swift
// MuseionTests
//
// Finish-audit pins for the ui-polish loop's pure seams that shipped
// "so a test can pin" them but no pin landed: the editor's
// first-content walker (title detection + the caret hop ride it) and
// the settings path elision ladder.
//
import Foundation
@testable import Museion
import Testing
@Suite("PolishSeamTests")
struct PolishSeamTests {
/// Leading blank lines are skipped to the first CONTENT line; a
/// whitespace-only buffer has none (nil); a buffer with no leading
/// blanks returns 0. The same walker styles the title line and hops
/// programmatic carets past the invisible blank fragment.
@Test func firstContentLocationSkipsLeadingBlanks() {
let plain = "Title\n\nbody" as NSString
#expect(ProsePresenter.firstContentLocation(plain) == 0)
let blankLead = "\n\n \nTitle\nbody" as NSString
let loc = ProsePresenter.firstContentLocation(blankLead)
#expect(loc == 5) // three leading blank lines (5 UTF-16 units incl. newline) before "Title"
#expect(ProsePresenter.firstContentLocation("" as NSString) == nil)
#expect(ProsePresenter.firstContentLocation("\n \n\t\n" as NSString) == nil)
}
/// The ladder keeps the full path, then each shorter variant with one
/// more leading component kept whole; ≤2 components has nothing to
/// elide. `elide` picks the longest candidate that fits.
@Test func elidedPathTextCandidateLadderAndElision() {
let path = "/Users/alex/Library/Mobile Documents/com~apple~CloudDocs/Museion"
let ladder = ElidedPathText.candidates(path)
#expect(ladder.first == path)
#expect(ladder.last == "/Users/…/Museion")
#expect(ladder.count == path.split(separator: "/").count - 1)
// Short paths never elide.
#expect(ElidedPathText.candidates("/a/b") == ["/a/b"])
// A wide-enough field keeps the full path; a narrow one falls to
// the shortest rung.
#expect(ElidedPathText.elide(path, into: 5000) == path)
#expect(ElidedPathText.elide(path, into: 10) == "/Users/…/Museion")
}
}