import CottonValues import Foundation import XCTest @testable import CottonUI final class ChoiceObjectTests: XCTestCase { /// RULE: A choice changes its object only through its own declared map; /// the same named object on an act uses the same worn theme. func testChoiceObjectsAreDeclaredAndReadThroughTheTheme() throws { let json = #"{"key":"system","type":"choice","choices":["handheld","desktop","server"],"objects":{"handheld":"phone","desktop":"mac","server":"linux"}}"# let column = try JSONDecoder().decode(ColumnDefinition.self, from: Data(json.utf8)) let roundTrip = try JSONDecoder().decode(ColumnDefinition.self, from: JSONEncoder().encode(column)) XCTAssertEqual(roundTrip.objects, column.objects) var cards = Theme.paper.cards cards.objects["mac"] = "linux" XCTAssertEqual(CardObject.named("mac", cards: cards), .enamel(.linux)) XCTAssertNotEqual(CardObject.named("phone", cards: cards), .enamel(.phone), "a device is not Call's handset") // An older theme row, saved before the shipped one named `phone`: the // loader lays it over the shipped theme, so it inherits the device. let older = Theme.decode(Data(#"{"family":"paper","objects":{"bell":"flame"}}"#.utf8)) XCTAssertEqual(CardObject.named("phone", cards: older.cards), .enamel(.devicePhone), "an older theme inherits the shipped device object") } }