Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #22 from num42/feature/improvements
Browse files Browse the repository at this point in the history
Feature/improvements
  • Loading branch information
Lutzifer authored Apr 2, 2019
2 parents 92c4fea + 5813539 commit 28c9b74
Show file tree
Hide file tree
Showing 8 changed files with 1,362 additions and 1,220 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.build
/Packages
/AppIconResizer.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate
/AppIconResizer.xcodeproj/xcuserdata
2,353 changes: 1,217 additions & 1,136 deletions AppIconResizer.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AppIconResizer::AppIconResizerCore"
BuildableName = "AppIconResizerCore.framework"
BlueprintName = "AppIconResizerCore"
BlueprintIdentifier = "AppIconResizer::AppIconResizer"
BuildableName = "AppIconResizer"
BlueprintName = "AppIconResizer"
ReferencedContainer = "container:AppIconResizer.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand All @@ -28,9 +28,9 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AppIconResizer::AppIconResizer"
BuildableName = "AppIconResizer"
BlueprintName = "AppIconResizer"
BlueprintIdentifier = "AppIconResizer::AppIconResizerCore"
BuildableName = "AppIconResizerCore.framework"
BlueprintName = "AppIconResizerCore"
ReferencedContainer = "container:AppIconResizer.xcodeproj">
</BuildableReference>
</BuildActionEntry>
Expand Down Expand Up @@ -69,9 +69,9 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AppIconResizer::AppIconResizerCore"
BuildableName = "AppIconResizerCore.framework"
BlueprintName = "AppIconResizerCore"
BlueprintIdentifier = "AppIconResizer::AppIconResizer"
BuildableName = "AppIconResizer"
BlueprintName = "AppIconResizer"
ReferencedContainer = "container:AppIconResizer.xcodeproj">
</BuildableReference>
</MacroExpansion>
Expand Down
9 changes: 0 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
"version": "0.8.0"
}
},
{
"package": "Files",
"repositoryURL": "https://github.com/JohnSundell/Files.git",
"state": {
"branch": null,
"revision": "06f95bd1bf4f8d5f50bc6bb30b808c253acd4c88",
"version": "2.2.1"
}
},
{
"package": "Spectre",
"repositoryURL": "https://github.com/kylef/Spectre.git",
Expand Down
14 changes: 13 additions & 1 deletion Sources/AppIconResizerCore/AppIconEntry.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import CoreImage

struct AppIconEntry: Encodable, Hashable {
struct AppIconEntry: Encodable, Hashable, Comparable {
static func < (lhs: AppIconEntry, rhs: AppIconEntry) -> Bool {
if lhs.idiom != rhs.idiom {
return lhs.idiom < rhs.idiom
}

if lhs.scale != rhs.scale {
return lhs.scale < rhs.scale
}

return lhs.size < rhs.size
}

let size: CGFloat
let idiom: String
let scale: Int
Expand Down
2 changes: 1 addition & 1 deletion Sources/AppIconResizerCore/AppIconResizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public final class AppIconResizer {
// Write app icon entries to contents json
let info = Info(version: 1, author: "AppIconResizer")
let outerContents = AppIconSetContents(iconEntries: nil, info: info)
let contents = AppIconSetContents(iconEntries: appIconEntries, info: info)
let contents = AppIconSetContents(iconEntries: appIconEntries.sorted(), info: info)
do {
let jsonData = try JSONEncoder().encode(contents)
let jsonInfoData = try JSONEncoder().encode(outerContents)
Expand Down
3 changes: 1 addition & 2 deletions Sources/AppIconResizerCore/Idiom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public enum Idiom: String, CaseIterable {
}

var appIconEntries: [AppIconEntry] {
return Array(virtualDevices.map { $0.appIconEntries }.joined())

return Array(virtualDevices.map { $0.appIconEntries }.joined()).sorted()
}

}
182 changes: 120 additions & 62 deletions Tests/AppIconResizerTests/AppIconResizerTests.swift
Original file line number Diff line number Diff line change
@@ -1,75 +1,133 @@
import XCTest
import Files
import AppIconResizerCore
@testable import AppIconResizerCore
import class Foundation.Bundle

final class AppIconResizerTests: XCTestCase {
func testCreatingFile() throws {

// Setup a temporarz test folder that can be used as a sandbox
let fileSystem = FileSystem()
let tempFolder = fileSystem.temporaryFolder
let testFolder = try tempFolder.createSubfolderIfNeeded(withName:"AppIconResizerTests")

// Empty the test folder to ensure a clean state
try testFolder.empty()

// Make the temp folder the current working folder
let fileManager = FileManager.default
fileManager.changeCurrentDirectoryPath(testFolder.path)

// Create an instance of the command line tool
let arguments = [testFolder.path, "Hello.swift"]
let tool = AppIconResizer(arguments:arguments)

// Try to run tool and look if there is
try tool.run()
XCTAssertNotNil(try? testFolder.file(named: "Hello.swift"))
}

func testReadingCommand() throws {

let devices = ["iphone", "ipad", "watch", "marketing", "all"]
try devices.forEach{ device in
let arguments = [device, "testFilePath"]
let tool = AppIconResizer(arguments:arguments)
try tool.run()
}
//NoIdea
}

func testDeviceSizes() {
XCTAssert( Idiom.all.appIconEntries == Idiom.all.appIconEntries )

XCTAssert(
Idiom.iphone.sizes.map { $0.width } == [40, 58, 60, 80, 87, 120, 180]
Idiom.iphone.appIconEntries == [
AppIconEntry(
size : 20.0,
idiom : "iphone",
scale : 2),
AppIconEntry(
size : 20.0,
idiom : "iphone",
scale : 3),
AppIconEntry(
size : 29.0,
idiom : "iphone",
scale : 2),
AppIconEntry(
size : 29.0,
idiom : "iphone",
scale : 3),
AppIconEntry(
size : 40.0,
idiom : "iphone",
scale : 2),
AppIconEntry(
size : 40.0,
idiom : "iphone",
scale : 3),
AppIconEntry(
size : 60.0,
idiom : "iphone",
scale : 2),
AppIconEntry(
size : 60.0,
idiom : "iphone",
scale : 3)
]
)

XCTAssert(
Idiom.ipad.sizes.map { $0.width } == [20, 29, 40, 58, 76, 80, 152, 167]
Idiom.ipad.appIconEntries == [
AppIconEntry(
size : 20.0,
idiom : "ipad",
scale : 1),
AppIconEntry(
size : 20.0,
idiom : "ipad",
scale : 2),
AppIconEntry(
size : 29.0,
idiom : "ipad",
scale : 1),
AppIconEntry(
size : 29.0,
idiom : "ipad",
scale : 2),
AppIconEntry(
size : 40.0,
idiom : "ipad",
scale : 1),
AppIconEntry(
size : 40.0,
idiom : "ipad",
scale : 2),
AppIconEntry(
size : 76.0,
idiom : "ipad",
scale : 1),
AppIconEntry(
size : 76.0,
idiom : "ipad",
scale : 2),
AppIconEntry(
size : 83.5,
idiom : "ipad",
scale : 2)
]
)

XCTAssert(
Idiom.watch.sizes.map { $0.width } == [48, 55, 58, 80, 87, 88, 100, 172, 196, 216]
Idiom.watch.appIconEntries == [
AppIconEntry(
size : 24.0,
idiom : "watch",
scale : 2),
AppIconEntry(
size : 27.5,
idiom : "watch",
scale : 2),
AppIconEntry(
size : 29.0,
idiom : "watch",
scale : 2),
AppIconEntry(
size : 29.0,
idiom : "watch",
scale : 3),
AppIconEntry(
size : 40.0,
idiom : "watch",
scale : 2),
AppIconEntry(
size : 44.0,
idiom : "watch",
scale : 2),
AppIconEntry(
size : 50.0,
idiom : "watch",
scale : 2),
AppIconEntry(
size : 86.0,
idiom : "watch",
scale : 2),
AppIconEntry(
size : 98.0,
idiom : "watch",
scale : 2),
AppIconEntry(
size : 108.0,
idiom : "watch",
scale : 2)
]
)
}

func testCreatedPngs() throws {
let testFolder = try Folder(path: FileManager.default.currentDirectoryPath)
//AppIconResizer.render(device:iphone, )
XCTAssertNotNil(try? testFolder.file(named: "20.png"))
}


/// Returns path to the built products directory.
var productsDirectory: URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()
}
fatalError("couldn't find the products directory")
#else
return Bundle.main.bundleURL
#endif
}

static var allTests = [
("test", testCreatingFile),
]
}

0 comments on commit 28c9b74

Please sign in to comment.