diff --git a/Package.resolved b/Package.resolved index 228d9c6..a0484d0 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,6 +1,15 @@ { "object": { "pins": [ + { + "package": "RBBJSON", + "repositoryURL": "https://github.com/robb/RBBJSON", + "state": { + "branch": "main", + "revision": "102c970283e105d7c5be2e29630db29c808c20eb", + "version": null + } + }, { "package": "swift-argument-parser", "repositoryURL": "https://github.com/apple/swift-argument-parser", diff --git a/Package.swift b/Package.swift index 47180f3..d0b3184 100644 --- a/Package.swift +++ b/Package.swift @@ -10,6 +10,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.3.1")), + .package(url: "https://github.com/robb/RBBJSON", .branch("main")), ], targets: [ .target( @@ -26,7 +27,10 @@ let package = Package( ), .testTarget( name: "MakeColorsTests", - dependencies: ["LibMakeColors"] + dependencies: [ + "LibMakeColors", + .product(name: "RBBJSON", package: "RBBJSON"), + ] ), ] ) diff --git a/Sources/LibMakeColors/Generators/AssetCatalogGenerator.swift b/Sources/LibMakeColors/Generators/AssetCatalogGenerator.swift index 9cc8698..f21d153 100644 --- a/Sources/LibMakeColors/Generators/AssetCatalogGenerator.swift +++ b/Sources/LibMakeColors/Generators/AssetCatalogGenerator.swift @@ -58,7 +58,7 @@ private let infoTag = """ } """ -private extension Color { +extension Color { func json() -> String { """ { diff --git a/Tests/MakeColorsTests/AssetCatalogFormattingTest.swift b/Tests/MakeColorsTests/AssetCatalogFormattingTest.swift new file mode 100644 index 0000000..4c0e8e5 --- /dev/null +++ b/Tests/MakeColorsTests/AssetCatalogFormattingTest.swift @@ -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")) + } +}