Cotton code
25 lines · 1.3 KB · SwiftRaw
import Foundationimport XCTest@testable import CottonPaper@testable import CottonUIfinal class ThemeScaleKeyTests: XCTestCase {    private func shippedRow(_ family: String) throws -> [String: Any] {        // The shell's theme row, read by path: the core compiles it in and        // the app's catalogue snapshot carries it.        let url = SourceSweep.kits.appendingPathComponent("shell/themes/\(family).json")        return try XCTUnwrap(JSONSerialization.jsonObject(with: Data(contentsOf: url)) as? [String: Any])    }    /// RULE: the theme the app draws when nothing else is read is its shipped row, whole — every scale knob read from the row, the acts and the cards the row's — never a base of Swift values.    func testTheShippedThemeIsItsRow() throws {        for (family, theme) in [("paper", Theme.paper), ("plain", Theme.plain)] {            let scale = try XCTUnwrap((try shippedRow(family)["scale"] as? [String: Any])?["tokens"] as? [String: Double])            for key in ThemeScale.Key.allCases {                XCTAssertEqual(Double(theme.scale[key]), scale[key.rawValue], "\(family): \(key.rawValue)")            }            XCTAssertNotEqual(theme.acts, ThemeActs.unread)            XCTAssertNotEqual(theme.cards, ThemeCards.unread)        }    }}