import XCTest @testable import CottonUI final class NoTableInGenericSurfacesTests: XCTestCase { /// RULE: The app never decides behaviour by whether a table shipped: `builtin` is decoded and read nowhere — whether a record's commands run comes from its engine commands or typed package acts, so an imported tool's records behave as a built-in's (architect, 13 Oct 2026). func testNothingReadsBuiltin() throws { let root = SourceSweep.iosSources.appendingPathComponent("CottonUI") let files = try FileManager.default.subpathsOfDirectory(atPath: root.path).filter { $0.hasSuffix(".swift") } let read = try NSRegularExpression(pattern: #"(?)] = [ (try NSRegularExpression(pattern: #"(?:\btable|\.id|\blinkTo|\bto)\s*[!=]=\s*"# + word), tables), (try NSRegularExpression(pattern: #"\bengine\s*[!=]=\s*"# + word), engines), (try NSRegularExpression(pattern: #"definitions\[\s*"# + word + #"\s*\]"#), tables), (try NSRegularExpression(pattern: #"\btable:\s*"# + word), tables), (try NSRegularExpression(pattern: #"^\s*"# + word + #":\s*(?:\.[a-z]|[A-Z])"#, options: .anchorsMatchLines), tables), ] let list = try NSRegularExpression(pattern: #"\[\s*"[a-z_]+"(?:\s*,\s*"[a-z_]+")+\s*\]"#) let quoted = try NSRegularExpression(pattern: word) // A multi-line string is data a sampler or a preview decodes, not code. let block = try NSRegularExpression(pattern: #"""(?s).*?""""#) let folders = ["CottonUI/Surfaces/", "CottonUI/Faces/", "CottonUI/Definitions/", "CottonUI/Editors/"] var found: [String] = [] for source in try SourceSweep.swiftSources() where folders.contains(where: source.name.hasPrefix) { let stripped = SourceSweep.withoutComments(source.text) let code = block.stringByReplacingMatches( in: stripped, range: NSRange(stripped.startIndex..., in: stripped), withTemplate: "\"\"") as NSString let all = NSRange(location: 0, length: code.length) for (pattern, words) in named { for match in pattern.matches(in: code as String, range: all) where words.contains(code.substring(with: match.range(at: 1))) { found.append("\(source.name): \(code.substring(with: match.range))") } } for match in list.matches(in: code as String, range: all) { let inside = code.substring(with: match.range) as NSString let ids = quoted.matches(in: inside as String, range: NSRange(location: 0, length: inside.length)) .map { inside.substring(with: $0.range(at: 1)) }.filter(tables.contains) if ids.count >= 2 { found.append("\(source.name): \(inside)") } } } XCTAssertEqual(found, [], "a generic surface reads what a table does from its definition, never from its name") } }