Skip to content

Commit

Permalink
Fix failing tests for different color space
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Dec 27, 2017
1 parent 0fb7b4d commit 2e7e958
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion Demo/Kingfisher-Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,3 @@ extension ViewController: UICollectionViewDataSourcePrefetching {
ImagePrefetcher(urls: urls).start()
}
}

4 changes: 2 additions & 2 deletions Sources/ImageProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,15 @@ public func >>(left: ImageProcessor, right: ImageProcessor) -> ImageProcessor {
return left.append(another: right)
}

fileprivate extension Color {
extension Color {
var hex: String {
var r: CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0

#if os(macOS)
(usingColorSpace(.genericRGB) ?? self).getRed(&r, green: &g, blue: &b, alpha: &a)
(usingColorSpace(.sRGB) ?? self).getRed(&r, green: &g, blue: &b, alpha: &a)
#else
getRed(&r, green: &g, blue: &b, alpha: &a)
#endif
Expand Down
10 changes: 5 additions & 5 deletions Tests/KingfisherTests/ImageProcessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// THE SOFTWARE.

import XCTest
import Kingfisher
@testable import Kingfisher

#if os(macOS)
import AppKit
Expand Down Expand Up @@ -70,7 +70,7 @@ class ImageProcessorTests: XCTestCase {
#if os(macOS)
func testCompositingProcessor() {
let p = CompositingImageProcessor(compositingOperation: .darken, alpha: 1.0, backgroundColor: .lightGray)
XCTAssertEqual(p.identifier, "com.onevcat.Kingfisher.CompositingImageProcessor(\(NSCompositingOperation.darken.rawValue),\(p.alpha))_#aaaaaaff")
XCTAssertEqual(p.identifier, "com.onevcat.Kingfisher.CompositingImageProcessor(\(NSCompositingOperation.darken.rawValue),\(p.alpha))_\(Color.lightGray.hex)")
checkProcessor(p, with: "compositing-\(NSCompositingOperation.darken.rawValue)")
}
#endif
Expand Down Expand Up @@ -127,18 +127,18 @@ class ImageProcessorTests: XCTestCase {

func testOverlayProcessor() {
let p1 = OverlayImageProcessor(overlay: .red)
XCTAssertEqual(p1.identifier, "com.onevcat.Kingfisher.OverlayImageProcessor(#ff0000ff_0.5)")
XCTAssertEqual(p1.identifier, "com.onevcat.Kingfisher.OverlayImageProcessor(\(Color.red.hex)_0.5)")
checkProcessor(p1, with: "overlay-red")

let p2 = OverlayImageProcessor(overlay: .red, fraction: 0.7)
XCTAssertEqual(p2.identifier, "com.onevcat.Kingfisher.OverlayImageProcessor(#ff0000ff_0.7)")
XCTAssertEqual(p2.identifier, "com.onevcat.Kingfisher.OverlayImageProcessor(\(Color.red.hex)_0.7)")
checkProcessor(p2, with: "overlay-red-07")
}

func testTintProcessor() {
let color = Color.yellow.withAlphaComponent(0.2)
let p = TintImageProcessor(tint: color)
XCTAssertEqual(p.identifier, "com.onevcat.Kingfisher.TintImageProcessor(#ffff0033)")
XCTAssertEqual(p.identifier, "com.onevcat.Kingfisher.TintImageProcessor(\(color.hex))")
checkProcessor(p, with: "tint-yellow-02")
}

Expand Down

0 comments on commit 2e7e958

Please sign in to comment.