Skip to content

Commit

Permalink
Merge pull request #7 from jeanetienne/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
jeanetienne authored Jun 7, 2017
2 parents 7f02898 + 0410e3f commit f0178f8
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 57 deletions.
2 changes: 1 addition & 1 deletion AssetResizer/AppIconSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct AppIconSet {
/// - Returns: An array of paths in which the last component is a folder
/// with the `*.appiconset` extension, in the order they are traversed.
/// Can be empty.
public static func findAppIconSets(inFolder folder: URL) -> [URL] {
public static func find(in folder: URL) -> [URL] {
return self.findItems(withExtension: self.pathExtension, inFolder: folder)
}

Expand Down
2 changes: 1 addition & 1 deletion AssetResizer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>0.0.2</string>
<key>CFBundleVersion</key>
<string>6</string>
<string>8</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 Jean-Étienne. All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
28 changes: 26 additions & 2 deletions AssetResizer/ResizedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public struct SizeDescription {
private let pointSize: NSSize

public var canonicalName: String {
return "\(name)-\(Int(pointSize.width))x\(Int(pointSize.height))@\(pixelDensity)x"
return "\(name)-\(pointSize.description)@\(pixelDensity)x"
}

public init(name aName: String, pointSize aSize: NSSize, pixelDensity aPixelDensity: Int) {
Expand Down Expand Up @@ -116,7 +116,31 @@ extension SizeDescription: CustomDebugStringConvertible {

}

extension NSBitmapImageFileType {
private extension NSSize {

var description: String {
if width == height {
return width.description
} else {
return "\(width.description)x\(height.description)"
}
}

}

private extension CGFloat {

var description: String {
if ceil(self) == self {
return "\(Int(self))"
} else {
return String(format: "%.1f", self)
}
}

}

private extension NSBitmapImageFileType {

var fileExtension: String {
switch self {
Expand Down
96 changes: 48 additions & 48 deletions AssetResizerTests/AppIconSetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class AppIconSetTests: XCTestCase {
}

func testFindAppIconSet() {
let paths = AppIconSet.findAppIconSets(inFolder: URL.cacheFolder)
let paths = AppIconSet.find(in: URL.cacheFolder)

XCTAssertEqual(paths.count, 1, "AppIconSet didn't find exactly one .appiconset")
}

func testNotFindAppIconSetInsideAppIconSet() {
let paths = AppIconSet.findAppIconSets(inFolder: URL.cacheFolder.appendingPathComponent("SampleAppIcon.appiconset"))
let paths = AppIconSet.find(in: URL.cacheFolder.appendingPathComponent("SampleAppIcon.appiconset"))

XCTAssertEqual(paths.count, 0, "AppIconSet found an .appiconset")
}
Expand All @@ -41,7 +41,7 @@ class AppIconSetTests: XCTestCase {
}

func testGettingSizes() {
let paths = AppIconSet.findAppIconSets(inFolder: URL.cacheFolder)
let paths = AppIconSet.find(in: URL.cacheFolder)
let appIconSetPath = paths[0]
if let appIconSet = AppIconSet(atPath: appIconSetPath) {
let sizes = appIconSet.sizes
Expand All @@ -54,7 +54,7 @@ class AppIconSetTests: XCTestCase {

func testUpdate() {
let originalImage = TestData.image(named: "sample-red-app-icon")!
let paths = AppIconSet.findAppIconSets(inFolder: URL.cacheFolder)
let paths = AppIconSet.find(in: URL.cacheFolder)
let appIconSetPath = paths[0]
guard var appIconSet = AppIconSet(atPath: appIconSetPath) else {
return XCTAssertTrue(false, "AppIconSet could not be initialized")
Expand All @@ -76,50 +76,50 @@ class AppIconSetTests: XCTestCase {
if let updatedSizes = AppIconSet(atPath: appIconSetPath)?.jsonRepresentation["images"] as? [[String: String]] {
let updatedFilenames = updatedSizes.map { $0["filename"] }.flatMap { $0 }.sorted()
let expectedFilenames = [
"car-60x60@2x.png",
"car-60x60@3x.png",
"ipad-20x20@1x.png",
"ipad-20x20@2x.png",
"ipad-29x29@1x.png",
"ipad-29x29@2x.png",
"ipad-40x40@1x.png",
"ipad-40x40@2x.png",
"ipad-50x50@1x.png",
"ipad-50x50@2x.png",
"ipad-72x72@1x.png",
"ipad-72x72@2x.png",
"ipad-76x76@1x.png",
"ipad-76x76@2x.png",
"ipad-83x83@2x.png",
"iphone-20x20@2x.png",
"iphone-20x20@3x.png",
"iphone-29x29@1x.png",
"iphone-29x29@2x.png",
"iphone-29x29@3x.png",
"iphone-40x40@2x.png",
"iphone-40x40@3x.png",
"iphone-57x57@1x.png",
"iphone-57x57@2x.png",
"iphone-60x60@2x.png",
"iphone-60x60@3x.png",
"mac-16x16@1x.png",
"mac-16x16@2x.png",
"mac-32x32@1x.png",
"mac-32x32@2x.png",
"mac-128x128@1x.png",
"mac-128x128@2x.png",
"mac-256x256@1x.png",
"mac-256x256@2x.png",
"mac-512x512@1x.png",
"mac-512x512@2x.png",
"watch-24x24@2x.png",
"watch-27x27@2x.png",
"watch-29x29@2x.png",
"watch-29x29@3x.png",
"watch-40x40@2x.png",
"watch-44x44@2x.png",
"watch-86x86@2x.png",
"watch-98x98@2x.png"
"car-60@2x.png",
"car-60@3x.png",
"ipad-20@1x.png",
"ipad-20@2x.png",
"ipad-29@1x.png",
"ipad-29@2x.png",
"ipad-40@1x.png",
"ipad-40@2x.png",
"ipad-50@1x.png",
"ipad-50@2x.png",
"ipad-72@1x.png",
"ipad-72@2x.png",
"ipad-76@1x.png",
"ipad-76@2x.png",
"ipad-83.5@2x.png",
"iphone-20@2x.png",
"iphone-20@3x.png",
"iphone-29@1x.png",
"iphone-29@2x.png",
"iphone-29@3x.png",
"iphone-40@2x.png",
"iphone-40@3x.png",
"iphone-57@1x.png",
"iphone-57@2x.png",
"iphone-60@2x.png",
"iphone-60@3x.png",
"mac-16@1x.png",
"mac-16@2x.png",
"mac-32@1x.png",
"mac-32@2x.png",
"mac-128@1x.png",
"mac-128@2x.png",
"mac-256@1x.png",
"mac-256@2x.png",
"mac-512@1x.png",
"mac-512@2x.png",
"watch-24@2x.png",
"watch-27.5@2x.png",
"watch-29@2x.png",
"watch-29@3x.png",
"watch-40@2x.png",
"watch-44@2x.png",
"watch-86@2x.png",
"watch-98@2x.png"
].sorted()

XCTAssertEqual(updatedFilenames, expectedFilenames, "AppIconSet didn't find the expected updated contents")
Expand Down
2 changes: 1 addition & 1 deletion AssetResizerTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<key>CFBundleShortVersionString</key>
<string>0.0.2</string>
<key>CFBundleVersion</key>
<string>6</string>
<string>8</string>
</dict>
</plist>
6 changes: 2 additions & 4 deletions AssetResizerTests/ResizedImageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ class ResizedImageTests: XCTestCase {

override func setUp() {
super.setUp()
try? FileManager.default.createDirectory(at: URL.cacheFolder,
withIntermediateDirectories: true,
attributes: nil)
TestData.createCacheFolder()
}

override func tearDown() {
super.tearDown()
try? FileManager.default.removeItem(at: URL.cacheFolder)
TestData.removeCacheFolder()
}

func testFailingInitialization() {
Expand Down

0 comments on commit f0178f8

Please sign in to comment.