Cotton code
46 lines · 2.8 KB · SwiftRaw
import Foundationimport XCTest@testable import CottonUI/// The look is data (lane lookdata, 13 Oct 2026): what a card is and how an/// act is coloured come from definitions and the theme, never a list in Swift./// (Sizes are Swift's own beside their reader since 14 Oct; a type size, a/// colour and a stock stay the theme's — `LookLiteralGuardTests`.)final class LookIsDataTests: XCTestCase {    /// RULE: no table id is spelled in Cards/ — what a card shows for a link (a cap, a person's picture) is read from the linked tool's definition, never from a list of tables in Swift, so an imported tool draws the way a built-in one does.    func testNoTableIsNamedInACard() throws {        let tables = Set(FixtureDefinitions.load().definitions.map(\.id))        XCTAssertFalse(tables.isEmpty, "the built-in definitions are bundled")        let quoted = try NSRegularExpression(pattern: #""([a-z_]+)""#)        var found: [String] = []        for source in try SourceSweep.swiftSources() where source.name.hasPrefix("CottonUI/Cards/") {            let code = SourceSweep.withoutComments(source.text) as NSString            for match in quoted.matches(in: code as String, range: NSRange(location: 0, length: code.length)) {                let word = code.substring(with: match.range(at: 1))                // A word the card vocabulary names an object by ("note" is a                // pencil, whatever table shares the word) is an object, not a table.                let object = CardEnamel.named(word) != nil                if tables.contains(word), !object { found.append("\(source.name): \"\(word)\"") }            }        }        XCTAssertEqual(found, [], "a card reads what a link is from the linked definition, not a table list")    }    /// RULE: a definition's menu line names the object its card stands, and the tray draws that object — a line carries no symbol, so without one every line fell back to the link, and "Import a file" wore Disconnect's chain (walker294 row 41).    func testADefinitionsMenuLineStandsItsOwnObject() {        var lines: [String] = []        for table in FixtureDefinitions.load().definitions {            for line in table.menu {                lines.append(table.id)                guard let named = CardEnamel.named(line.object) else {                    XCTFail("\(table.id)'s menu line \(line.path) names no object this build draws")                    continue                }                let item = PopoverMenuItem(id: line.path, object: line.object, label: line.label) {}                XCTAssertEqual(ActCardReading.item(item).object, .enamel(named), "\(table.id): \(line.path)")                XCTAssertNotEqual(named, .link, "\(table.id): \(line.path) is not a connection")            }        }        XCTAssertFalse(lines.isEmpty, "some shipped list keeps a menu")    }}