From 4fba7cae5867f4457b66dec6ba38e8e7d9231f0b Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Tue, 27 Oct 2026 16:45:21 +0100 Subject: make highlight parsing more reliable --- Tests/barTests/CellTests.swift | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Tests/barTests/CellTests.swift (limited to 'Tests/barTests') diff --git a/Tests/barTests/CellTests.swift b/Tests/barTests/CellTests.swift new file mode 100644 index 0000000..c7aae13 --- /dev/null +++ b/Tests/barTests/CellTests.swift @@ -0,0 +1,38 @@ +import SwiftUI +import Testing +@testable import bar + +@Test(arguments: [ + "", "ordinary text", "text &!1 more", " &!1 text", + "&!", "&!1", "&!12", "&!0", "&!999999999999999999999999999999", + "&! text", "&!-1 text", "&!+1 text", "&!1 text", "&!١ text", +]) func literalCellText(_ input: String) { + let cell = Cell(rawValue: input) + #expect(cell.rawValue == input) + #expect(cell.background == .clear) + #expect(cell.id == "\(input):0") +} + +@Test(arguments: ["0", "12", "999999999999999999999999999999"]) func invalidCellLevels(_ level: String) { + let cell = Cell(rawValue: "&!\(level) text") + #expect(cell.rawValue == " text") + #expect(cell.background == .clear) + #expect(cell.id == " text:0") +} + +@Test func configuredCellHighlights() { + for level in 1...Config.highlights.count { + for body in ["hello", " hello", " ", "\t", "\n", "&!2 nested"] { + let cell = Cell(rawValue: "&!\(level)\(body)") + #expect(cell.rawValue == body) + #expect(cell.background == Config.highlights[level - 1]) + #expect(cell.id == "\(body):\(level)") + } + } + let cell = Cell(rawValue: "&!01 hello") + #expect(cell.background == Config.highlights[0]) + #expect(cell.rawValue == " hello") + let outOfRange = Cell(rawValue: "&!\(Config.highlights.count + 1) text") + #expect(outOfRange.rawValue == " text") + #expect(outOfRange.background == .clear) +} -- cgit v1.2.3