Skip to content
This repository was archived by the owner on Feb 2, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion Codemine.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@
291272CF1C75F32200FB1BBD /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291272CE1C75F32200FB1BBD /* Operators.swift */; };
293490EE1C6CAFD500E8305E /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293490ED1C6CAFD500E8305E /* Application.swift */; };
293490F01C6CAFF200E8305E /* Then.swift in Sources */ = {isa = PBXBuildFile; fileRef = 293490EF1C6CAFF200E8305E /* Then.swift */; };
83A5BEBC1D981F3500C74312 /* UIImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A5BEBB1D981F3500C74312 /* UIImageTests.swift */; };
83A5BEBD1D98215F00C74312 /* UIImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A5BEBB1D981F3500C74312 /* UIImageTests.swift */; };
83A5BEBE1D98216000C74312 /* UIImageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A5BEBB1D981F3500C74312 /* UIImageTests.swift */; };
83A5BEC01D98226800C74312 /* add.png in Resources */ = {isa = PBXBuildFile; fileRef = 83A5BEBF1D98226800C74312 /* add.png */; };
83A5BEC11D98226800C74312 /* add.png in Resources */ = {isa = PBXBuildFile; fileRef = 83A5BEBF1D98226800C74312 /* add.png */; };
83A5BEC21D98226800C74312 /* add.png in Resources */ = {isa = PBXBuildFile; fileRef = 83A5BEBF1D98226800C74312 /* add.png */; };
83A5BEC41D98228300C74312 /* alert.png in Resources */ = {isa = PBXBuildFile; fileRef = 83A5BEC31D98228300C74312 /* alert.png */; };
83A5BEC51D98228300C74312 /* alert.png in Resources */ = {isa = PBXBuildFile; fileRef = 83A5BEC31D98228300C74312 /* alert.png */; };
83A5BEC61D98228300C74312 /* alert.png in Resources */ = {isa = PBXBuildFile; fileRef = 83A5BEC31D98228300C74312 /* alert.png */; };
83A5BEC91D98249500C74312 /* URLImageAssetSizeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A5BEC81D98249500C74312 /* URLImageAssetSizeTests.swift */; };
83A5BECA1D98249500C74312 /* URLImageAssetSizeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A5BEC81D98249500C74312 /* URLImageAssetSizeTests.swift */; };
83A5BECB1D98249500C74312 /* URLImageAssetSizeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83A5BEC81D98249500C74312 /* URLImageAssetSizeTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -112,6 +124,10 @@
291272CE1C75F32200FB1BBD /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = "<group>"; };
293490ED1C6CAFD500E8305E /* Application.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = "<group>"; };
293490EF1C6CAFF200E8305E /* Then.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Then.swift; sourceTree = "<group>"; };
83A5BEBB1D981F3500C74312 /* UIImageTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIImageTests.swift; sourceTree = "<group>"; };
83A5BEBF1D98226800C74312 /* add.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = add.png; sourceTree = "<group>"; };
83A5BEC31D98228300C74312 /* alert.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = alert.png; sourceTree = "<group>"; };
83A5BEC81D98249500C74312 /* URLImageAssetSizeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLImageAssetSizeTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -208,8 +224,11 @@
275BCAAD1C57D1B500FF3647 /* CodemineTests */ = {
isa = PBXGroup;
children = (
275BCAAE1C57D1B500FF3647 /* CodemineTests.swift */,
83A5BEC71D98228F00C74312 /* Resources */,
275BCAB01C57D1B500FF3647 /* Info.plist */,
275BCAAE1C57D1B500FF3647 /* CodemineTests.swift */,
83A5BEBB1D981F3500C74312 /* UIImageTests.swift */,
83A5BEC81D98249500C74312 /* URLImageAssetSizeTests.swift */,
);
path = CodemineTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -240,6 +259,15 @@
path = "Supporting Files";
sourceTree = "<group>";
};
83A5BEC71D98228F00C74312 /* Resources */ = {
isa = PBXGroup;
children = (
83A5BEBF1D98226800C74312 /* add.png */,
83A5BEC31D98228300C74312 /* alert.png */,
);
name = Resources;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -474,6 +502,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
83A5BEC51D98228300C74312 /* alert.png in Resources */,
83A5BEC11D98226800C74312 /* add.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -488,6 +518,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
83A5BEC61D98228300C74312 /* alert.png in Resources */,
83A5BEC21D98226800C74312 /* add.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -509,6 +541,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
83A5BEC41D98228300C74312 /* alert.png in Resources */,
83A5BEC01D98226800C74312 /* add.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -535,6 +569,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
83A5BEBD1D98215F00C74312 /* UIImageTests.swift in Sources */,
83A5BECA1D98249500C74312 /* URLImageAssetSizeTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -562,6 +598,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
83A5BEBE1D98216000C74312 /* UIImageTests.swift in Sources */,
83A5BECB1D98249500C74312 /* URLImageAssetSizeTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -607,7 +645,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
83A5BEC91D98249500C74312 /* URLImageAssetSizeTests.swift in Sources */,
275BCAAF1C57D1B500FF3647 /* CodemineTests.swift in Sources */,
83A5BEBC1D981F3500C74312 /* UIImageTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion Codemine/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Foundation

public struct Application {

private static func getString(_ key: String) -> String {
fileprivate static func getString(_ key: String) -> String {
guard let infoDictionary = Bundle.main.infoDictionary,
let value = infoDictionary[key] as? String
else { return "" }
Expand Down
6 changes: 3 additions & 3 deletions Codemine/Extensions/NSURL+AssetSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public extension URL {
- widthParameterName: the name of the width paramter. Default is 'h'
- Returns: `URL` as a `NSURL`.
*/
public func urlByAppendingAssetSize(_ size: CGSize, mode: ImageUrlMode = .Default, heightParameterName : String = "h", widthParameterName : String = "w") -> URL {
guard var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: false) else { return self }
public func urlByAppendingAssetSize(_ size: CGSize, mode: ImageUrlMode = .Default, heightParameterName : String = "h", widthParameterName : String = "w") -> URL? {
guard var urlComponents = URLComponents(url: self, resolvingAgainstBaseURL: false) else { return nil }

var queryItems:[URLQueryItem] = urlComponents.queryItems ?? []
queryItems.append(URLQueryItem(name: widthParameterName, value: "\(Int(size.width * UIScreen.main.scale ))"))
Expand All @@ -51,6 +51,6 @@ public extension URL {
queryItems.append(URLQueryItem(name: "mode", value: mode.rawValue))
}
urlComponents.queryItems = queryItems
return urlComponents.url ?? self
return urlComponents.url
}
}
2 changes: 1 addition & 1 deletion Codemine/Then.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Foundation
public protocol Then {}
extension Then {

public func then( _ block: @noescape (Self) -> Void) -> Self {
public func then( _ block: (Self) -> Void) -> Self {
block(self)
return self
}
Expand Down
18 changes: 0 additions & 18 deletions CodemineTests/CodemineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,7 @@ class CodemineTests: XCTestCase {
XCTAssertEqual(magenta, UIColor.magenta)
XCTAssertNotEqual(red, UIColor.yellow)
}

// MARK: - NSURL extension test
func testURLWithSize() {
guard let url = URL(string: "https://example.com/image.png") else { XCTAssertTrue(false, "Failed to create NSURL"); return }
let size = CGSize(width: 512, height: 256)
let heightParameterName = "height"
let widthParameterName = "width"

let url2 = url.urlByAppendingAssetSize(size, mode: .Default, heightParameterName: heightParameterName, widthParameterName: widthParameterName)
XCTAssertEqual(url2.absoluteString, url.absoluteString + "?\(widthParameterName)=\(Int(size.width * UIScreen.main.scale ))&\(heightParameterName)=\(Int(size.height * UIScreen.main.scale))")

let url3 = url.urlByAppendingAssetSize(size)
XCTAssertEqual(url3.absoluteString, url.absoluteString + "?w=\(Int(size.width * UIScreen.main.scale ))&h=\(Int(size.height * UIScreen.main.scale))")

let url4 = url.urlByAppendingAssetSize(size, mode: .Crop)
XCTAssertEqual(url4.absoluteString, url.absoluteString + "?w=\(Int(size.width * UIScreen.main.scale ))&h=\(Int(size.height * UIScreen.main.scale))&mode=crop")

}

func testError() {
let domain = "Domain"
let code = 123
Expand Down
37 changes: 37 additions & 0 deletions CodemineTests/UIImageTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// UIImageTests.swift
// Codemine
//
// Created by Chris on 25/09/2016.
// Copyright © 2016 Nodes. All rights reserved.
//

import XCTest
@testable import Codemine

class UIImageTests: XCTestCase {

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

func testImageNamed(name: String) -> UIImage {
let bundle = Bundle(for: type(of: self))
let path = bundle.path(forResource: name, ofType: "png")!
return UIImage(contentsOfFile: path)!
}

func testUIImageFromColor() {
XCTAssertNotNil(UIImage.imageFromColor(.red, size: CGSize(width: 20, height: 20), cornerRadius: 1.0), "Failed to convert color to image")
}

func testImageImbed() {
XCTAssertNotNil(UIImage.imageByEmbeddingIconIn(testImageNamed(name: "add"), icon: testImageNamed(name: "alert")), "Failed to embed image")
}

func testImageRotation() {
XCTAssertNotNil(testImageNamed(name: "add").rotationCorrectedImage(), "Failed to rotate image")
}

}
48 changes: 48 additions & 0 deletions CodemineTests/URLImageAssetSizeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// URLImageAssetSizeTests.swift
// Codemine
//
// Created by Chris on 25/09/2016.
// Copyright © 2016 Nodes. All rights reserved.
//

import XCTest
@testable import Codemine

class URLImageAssetSizeTests: XCTestCase {

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}


func testURLWithSize() {
guard let url = URL(string: "https://example.com/image.png") else { XCTAssertTrue(false, "Failed to create NSURL"); return }
let size = CGSize(width: 512, height: 256)
let heightParameterName = "height"
let widthParameterName = "width"

let url2 = url.urlByAppendingAssetSize(size, mode: .Default, heightParameterName: heightParameterName, widthParameterName: widthParameterName)
XCTAssertEqual(url2?.absoluteString, url.absoluteString + "?\(widthParameterName)=\(Int(size.width * UIScreen.main.scale ))&\(heightParameterName)=\(Int(size.height * UIScreen.main.scale))")

let url3 = url.urlByAppendingAssetSize(size)
XCTAssertEqual(url3?.absoluteString, url.absoluteString + "?w=\(Int(size.width * UIScreen.main.scale ))&h=\(Int(size.height * UIScreen.main.scale))")

let url4 = url.urlByAppendingAssetSize(size, mode: .Crop)
XCTAssertEqual(url4?.absoluteString, url.absoluteString + "?w=\(Int(size.width * UIScreen.main.scale ))&h=\(Int(size.height * UIScreen.main.scale))&mode=crop")

}

func testBadUrl() {
let url = URL(string: "http://example.com:-80/")!

print(URLComponents(url: url, resolvingAgainstBaseURL: false))

let newUrl = url.urlByAppendingAssetSize(CGSize(width: 10, height: 10))
XCTAssertNil(newUrl?.absoluteString, "Bad URL did not return nil")
}



}
Binary file added CodemineTests/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CodemineTests/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.