Cotton code
33 lines · 1.9 KB · SwiftRaw
import CottonValuesimport XCTest@testable import CottonUI/// A slip whose tap is a copy (`slip.tap`, Clips, 14 Oct 2026): a clip is/// tapped to put it on this device's clipboard.final class SlipTapTests: XCTestCase {    private func definition(copies: String, secret: Bool = false) throws -> TableDefinition {        let json = """        {"id":"clip_example","name":"Clip","plural":"Clips","builtin":false,         "columns":[{"key":"text","name":"Copied","type":"text"\(secret ? ",\"secret\":true" : "")}],         "title":"text","date":null,"project":null,"order":null,         "slip":{"title":"text","tap":"copy"},"tile":{"face":"slip-list"},"page":[],         "commands":[{"id":"copy","label":"Copy","kind":"copy","copies":"\(copies)"}],         "tables":[]}        """        return try JSONDecoder().decode(TableDefinition.self, from: Data(json.utf8))    }    /// RULE: A slip's tap copies only a column's own value — never a sealed vault value, which opens behind its own flow on the page — and a secret column's copy carries the secret expiry.    func testATapCopiesAColumnAndNeverASealedValue() throws {        let record = TableRecord(id: "a", values: ["text": .text("Invented words")])        let plain = try definition(copies: "text")        XCTAssertEqual(plain.slip.tap, "copy")        XCTAssertEqual(plain.tapCopy(record)?.value, "Invented words")        XCTAssertEqual(plain.tapCopy(record)?.secret, false)        XCTAssertEqual(try definition(copies: "text", secret: true).tapCopy(record)?.secret, true)        XCTAssertNil(try definition(copies: RecordCommand.copySealed).tapCopy(record), "a sealed value is never a tap")        XCTAssertNil(plain.tapCopy(TableRecord(id: "b", values: [:])), "nothing to copy opens the page instead")        let encoded = try JSONEncoder().encode(plain)        XCTAssertEqual(try JSONDecoder().decode(TableDefinition.self, from: encoded).slip.tap, "copy", "the key round-trips")    }}