Create unit test for color JSON
This commit is contained in:
parent
be2a655c40
commit
1c31c11f49
4 changed files with 41 additions and 2 deletions
|
@ -1,6 +1,15 @@
|
||||||
{
|
{
|
||||||
"object": {
|
"object": {
|
||||||
"pins": [
|
"pins": [
|
||||||
|
{
|
||||||
|
"package": "RBBJSON",
|
||||||
|
"repositoryURL": "https://github.com/robb/RBBJSON",
|
||||||
|
"state": {
|
||||||
|
"branch": "main",
|
||||||
|
"revision": "102c970283e105d7c5be2e29630db29c808c20eb",
|
||||||
|
"version": null
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"package": "swift-argument-parser",
|
"package": "swift-argument-parser",
|
||||||
"repositoryURL": "https://github.com/apple/swift-argument-parser",
|
"repositoryURL": "https://github.com/apple/swift-argument-parser",
|
||||||
|
|
|
@ -10,6 +10,7 @@ let package = Package(
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.3.1")),
|
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.3.1")),
|
||||||
|
.package(url: "https://github.com/robb/RBBJSON", .branch("main")),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
|
@ -26,7 +27,10 @@ let package = Package(
|
||||||
),
|
),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "MakeColorsTests",
|
name: "MakeColorsTests",
|
||||||
dependencies: ["LibMakeColors"]
|
dependencies: [
|
||||||
|
"LibMakeColors",
|
||||||
|
.product(name: "RBBJSON", package: "RBBJSON"),
|
||||||
|
]
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -58,7 +58,7 @@ private let infoTag = """
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
private extension Color {
|
extension Color {
|
||||||
func json() -> String {
|
func json() -> String {
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
|
|
26
Tests/MakeColorsTests/AssetCatalogFormattingTest.swift
Normal file
26
Tests/MakeColorsTests/AssetCatalogFormattingTest.swift
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
@testable import LibMakeColors
|
||||||
|
import RBBJSON
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
class AssetCatalogFormattingTest: XCTestCase {
|
||||||
|
func testColorProducedValidJSON() throws {
|
||||||
|
let color = Color(red: 0xFF, green: 0xF0, blue: 0x0F)
|
||||||
|
let data = Data(color.json().utf8)
|
||||||
|
|
||||||
|
let json = try JSONDecoder().decode(RBBJSON.self, from: data)
|
||||||
|
|
||||||
|
XCTAssertEqual(json.info.author, .string("de.5sw.MakeColors"))
|
||||||
|
XCTAssertEqual(json.info.version, .number(1))
|
||||||
|
|
||||||
|
XCTAssertEqual(Array(json.colors[any: .child]).count, 1)
|
||||||
|
|
||||||
|
XCTAssertEqual(json.colors[0].idiom, .string("universal"))
|
||||||
|
|
||||||
|
let jsonColor = json.colors[0].color
|
||||||
|
XCTAssertEqual(jsonColor["color-space"], .string("srgb"))
|
||||||
|
XCTAssertEqual(jsonColor.components.alpha, .string("1.0"))
|
||||||
|
XCTAssertEqual(jsonColor.components.red, .string("0xFF"))
|
||||||
|
XCTAssertEqual(jsonColor.components.green, .string("0xF0"))
|
||||||
|
XCTAssertEqual(jsonColor.components.blue, .string("0x0F"))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue