import CottonKit import Foundation import XCTest @testable import CottonUI /// Walker 298 read "schema 139" twice at the foot of the Databases sheet: /// the build line wrote this build's schema and the serving Mac's. final class DatabasesSheetNamesNoSchemaTests: XCTestCase { /// RULE: no line of the Databases sheet carries "schema" followed by a number, because a person reads that sheet and no schema number stands anywhere a person reads (the opening card's rule); only a diagnostics page a developer opens on purpose may say it. func testNoDatabasesSheetLineNamesASchemaNumber() throws { let schemaNumber = try NSRegularExpression(pattern: "schema\\W*\\d", options: .caseInsensitive) func check(_ text: String, _ why: String) { let range = NSRange(text.startIndex..., in: text) XCTAssertNil(schemaNumber.firstMatch(in: text, range: range), "\(why): \(text)") } let peers: [BuildLine.Peer?] = [ nil, BuildLine.Peer(name: "mac-c"), BuildLine.Peer(name: "mac-c", version: "0.29.57", schema: 139), BuildLine.Peer(name: "mac-c", version: "0.29.57", schema: 138), BuildLine.Peer(schema: 139), ] for schema in [nil, 139] as [Int?] { for peer in peers { let line = BuildLine(version: "1.0.0", build: "298", commit: "7bc2557", schema: schema, peer: peer) check(line.text, "the build line at the sheet's foot") } } // A differing schema still turns the line red, without writing the number. let differing = BuildLine(build: "298", commit: "7bc2557", schema: 139, peer: BuildLine.Peer(name: "mac-c", schema: 138)) XCTAssertTrue(differing.mismatched) // The sheet's own code never writes a schema into a string it draws. let sheet = try SourceSweep.withoutComments( SourceSweep.mustRead("apps/cotton/Sources/CottonUI/Surfaces/Databases/DatabasesScreen.swift", ownedBy: "phonefixes")) XCTAssertFalse(sheet.range(of: "schema", options: .caseInsensitive) != nil, "DatabasesScreen.swift draws a schema; the sheet is person-facing") } }