Skip to content

Commit

Permalink
Test refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszj committed Apr 28, 2019
1 parent 82b633e commit df3b018
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 394 deletions.
2 changes: 1 addition & 1 deletion acextract/AssetsCatalog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct AssetsCatalog {

extension AssetsCatalog {
func performOperation(operation: Operation) throws {
try operation.read(catalg: self)
try operation.read(catalog: self)
}

func performOperations(operations: [Operation]) throws {
Expand Down
2 changes: 1 addition & 1 deletion acextract/CoreUI_Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ extension CUINamedImage {
// image size
let width = self.size.width
let height = self.size.height
let size = width>0 ? "\(Int(width))x\(Int(height))" : ""
let size = width > 0 ? "\(Int(width))x\(Int(height))" : ""

// Graphical class
let graphics = self.graphicsClass().name
Expand Down
10 changes: 5 additions & 5 deletions acextract/Operation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import Foundation

// MARK: - Protocols
protocol Operation {
func read(catalg: AssetsCatalog) throws
func read(catalog: AssetsCatalog) throws
}

struct CompoundOperation: Operation {
let operations: [Operation]

func read(catalg: AssetsCatalog) throws {
func read(catalog: AssetsCatalog) throws {
for operation in operations {
try operation.read(catalg: catalg)
try operation.read(catalog: catalog)
}
}
}
Expand Down Expand Up @@ -65,11 +65,11 @@ struct ExtractOperation: Operation {
}

// MARK: Methods
func read(catalg: AssetsCatalog) throws {
func read(catalog: AssetsCatalog) throws {
// Create output folder if needed
try checkAndCreateFolder()
// For every image set and every named image.
for imageSet in catalg.imageSets {
for imageSet in catalog.imageSets {
for namedImage in imageSet.namedImages {
// Save image to file.
extractNamedImage(namedImage: namedImage)
Expand Down
6 changes: 3 additions & 3 deletions acextract/PrintInformationOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ struct PrintInformationOperation: Operation {
case veryVeryVerbose
}

func read(catalg: AssetsCatalog) {
print("Assets catalog: \(catalg.filePath)")
for imageSet in catalg.imageSets {
func read(catalog: AssetsCatalog) {
print("Assets catalog: \(catalog.filePath)")
for imageSet in catalog.imageSets {
printImageSetData(imageSet: imageSet)
}
}
Expand Down
8 changes: 4 additions & 4 deletions acextractTests/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ enum Asset: String {

// MARK: Static
static let bundleIdentifer = "com.bjanda.acextractTests"
static let bundle = NSBundle(identifier: bundleIdentifer)!
static func path(name name: String) -> String? {
return bundle.pathForResource(name, ofType: "car")
static let bundle = Bundle(identifier: bundleIdentifer)!
static func path(name: String) -> String? {
return bundle.path(forResource: name, ofType: "car")
}
static func path(catalog catalog: Asset) -> String? {
static func path(catalog: Asset) -> String? {
return path(name: catalog.rawValue)
}
}
Expand Down
10 changes: 5 additions & 5 deletions acextractTests/AssetsCatalogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AssetsCatalogTests: XCTestCase {
do {
_ = try AssetsCatalog(path: "Fake path")
XCTFail("AssetsCatalog should not be created")
} catch AssetsCatalogError.FileDoesntExists {
} catch AssetsCatalogError.fileDoesntExists {

} catch {
XCTFail("Unknown exception \(error)")
Expand All @@ -48,15 +48,15 @@ class AssetsCatalogTests: XCTestCase {
Incorrect file.
*/
func testCreateAssetsCatalog03() {
guard let path = Asset.bundle.pathForResource("data/fake_assets", ofType: nil) else {
guard let path = Asset.bundle.path(forResource: "data/fake_assets", ofType: nil) else {
XCTFail("Cannot find fake asset")
return
}

do {
_ = try AssetsCatalog(path: path)
XCTFail("AssetsCatalog should not be created")
} catch AssetsCatalogError.CannotOpenAssetsCatalog {
} catch AssetsCatalogError.cannotOpenAssetsCatalog {

} catch {
XCTFail("Unknown exception \(error)")
Expand All @@ -69,7 +69,7 @@ class AssetsCatalogTests: XCTestCase {
func testOperation01() {
do {
let operation = FakeOperation()
try assetsContainer.iOS.performOperation(operation)
try assetsContainer.iOS.performOperation(operation: operation)
XCTAssertTrue(operation.executed)
} catch {
XCTFail("Unknown exception \(error)")
Expand All @@ -83,7 +83,7 @@ class AssetsCatalogTests: XCTestCase {
do {
let operation1 = FakeOperation()
let operation2 = FakeOperation()
try assetsContainer.iOS.performOperations([operation1, operation2])
try assetsContainer.iOS.performOperations(operations: [operation1, operation2])
XCTAssertTrue(operation1.executed)
XCTAssertTrue(operation2.executed)
} catch {
Expand Down
20 changes: 10 additions & 10 deletions acextractTests/CorrectnessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@ import XCTest
// Check correctness by printing verbose information
class CorrectnessTests: XCTestCase {
// MARK: Properties
let printOperation = PrintInformationOperation(verbose: .VeryVeryVerbose)
let printOperation = PrintInformationOperation(verbose: .veryVeryVerbose)

// MARK: Test correctness
func testIOSCorrectness() {
printOperation.read(assetsContainer.iOS)
printOperation.read(catalog: assetsContainer.iOS)
}

func testIPadCorrectness() {
printOperation.read(assetsContainer.iPad)
printOperation.read(catalog: assetsContainer.iPad)
}

func testIPhoneCorrectness() {
printOperation.read(assetsContainer.iPhone)
printOperation.read(catalog: assetsContainer.iPhone)
}

func testMacCorrectness() {
printOperation.read(assetsContainer.macOS)
printOperation.read(catalog: assetsContainer.macOS)
}

func testTVCorrectness() {
printOperation.read(assetsContainer.tvOS)
printOperation.read(catalog: assetsContainer.tvOS)
}

func testWatchCorrectness() {
printOperation.read(assetsContainer.watchOS)
printOperation.read(catalog: assetsContainer.watchOS)
}

func testPrintInformationName() {
PrintInformationOperation(verbose: .Name).read(assetsContainer.iOS)
PrintInformationOperation(verbose: .name).read(catalog: assetsContainer.iOS)
}

func testPrintInformationVerbose() {
PrintInformationOperation(verbose: .Verbose).read(assetsContainer.iOS)
PrintInformationOperation(verbose: .verbose).read(catalog: assetsContainer.iOS)
}

func testPrintInformationVeryVerbose() {
PrintInformationOperation(verbose: .VeryVerbose).read(assetsContainer.iOS)
PrintInformationOperation(verbose: .veryVerbose).read(catalog: assetsContainer.iOS)
}
}
74 changes: 37 additions & 37 deletions acextractTests/DeviceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class DeviceTests: XCTestCase {
let images = imageSet.namedImages
XCTAssertEqual(images.count, 2)
if let image = images.filter({ return $0.scale == 1.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.IPad)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.iPad)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_ipad~ipad.png")
Expand All @@ -93,8 +93,8 @@ class DeviceTests: XCTestCase {
}

if let image = images.filter({ return $0.scale == 2.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.IPad)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.iPad)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_ipad@2x~ipad.png")
Expand All @@ -109,8 +109,8 @@ class DeviceTests: XCTestCase {
let images = imageSet.namedImages
XCTAssertEqual(images.count, 3)
if let image = images.filter({ return $0.scale == 1.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.IPhone)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.iPhone)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_iphone~iphone.png")
Expand All @@ -120,8 +120,8 @@ class DeviceTests: XCTestCase {
}

if let image = images.filter({ return $0.scale == 2.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.IPhone)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.iPhone)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_iphone@2x~iphone.png")
Expand All @@ -131,8 +131,8 @@ class DeviceTests: XCTestCase {
}

if let image = images.filter({ return $0.scale == 3.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.IPhone)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.iPhone)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "@3x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_iphone@3x~iphone.png")
Expand All @@ -146,9 +146,9 @@ class DeviceTests: XCTestCase {
let imageSet = assetsContainer.iPhone.imageSet(withName: "d_iphone4")
let images = imageSet.namedImages
XCTAssertEqual(images.count, 2)
if let image = images.filter({ return $0.subtype() == .Normal }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.IPhone)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
if let image = images.filter({ return $0.subtype() == .normal }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.iPhone)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_iphone4@2x~iphone.png")
Expand All @@ -157,9 +157,9 @@ class DeviceTests: XCTestCase {
XCTFail("Cannot find image")
}

if let image = images.filter({ return $0.subtype() == .IPhone4Inch }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.IPhone)
XCTAssertEqual(image.subtype(), CUISubtype.IPhone4Inch)
if let image = images.filter({ return $0.subtype() == .iPhone4Inch }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.iPhone)
XCTAssertEqual(image.subtype(), CUISubtype.iPhone4Inch)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_iphone4-568h@2x~iphone.png")
Expand All @@ -174,8 +174,8 @@ class DeviceTests: XCTestCase {
let images = imageSet.namedImages
XCTAssertEqual(images.count, 2)
if let image = images.filter({ return $0.scale == 1.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.Universal)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.universal)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_mac.png")
Expand All @@ -185,8 +185,8 @@ class DeviceTests: XCTestCase {
}

if let image = images.filter({ return $0.scale == 2.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.Universal)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.universal)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "[email protected]")
Expand All @@ -201,8 +201,8 @@ class DeviceTests: XCTestCase {
let images = imageSet.namedImages
XCTAssertEqual(images.count, 1)
if let image = images.filter({ return $0.scale == 1.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.AppleTV)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.appleTV)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_tv~tv.png")
Expand All @@ -217,8 +217,8 @@ class DeviceTests: XCTestCase {
let images = imageSet.namedImages
XCTAssertEqual(images.count, 3)
if let image = images.filter({ return $0.scale == 1.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.Universal)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.universal)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_universal.png")
Expand All @@ -228,8 +228,8 @@ class DeviceTests: XCTestCase {
}

if let image = images.filter({ return $0.scale == 2.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.Universal)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.universal)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "[email protected]")
Expand All @@ -239,8 +239,8 @@ class DeviceTests: XCTestCase {
}

if let image = images.filter({ return $0.scale == 3.0 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.Universal)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.universal)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "@3x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "[email protected]")
Expand All @@ -254,9 +254,9 @@ class DeviceTests: XCTestCase {
let imageSet = assetsContainer.watchOS.imageSet(withName: "d_watch")
let images = imageSet.namedImages
XCTAssertEqual(images.count, 3)
if let image = images.filter({ return $0.subtype() == .Normal }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.AppleWatch)
XCTAssertEqual(image.subtype(), CUISubtype.Normal)
if let image = images.filter({ return $0.subtype() == .normal }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.appleWatch)
XCTAssertEqual(image.subtype(), CUISubtype.normal)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_watch@2x~watch.png")
Expand All @@ -265,9 +265,9 @@ class DeviceTests: XCTestCase {
XCTFail("Cannot find image")
}

if let image = images.filter({ return $0.subtype() == .AppleWatch38 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.AppleWatch)
XCTAssertEqual(image.subtype(), CUISubtype.AppleWatch38)
if let image = images.filter({ return $0.subtype() == .appleWatch38 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.appleWatch)
XCTAssertEqual(image.subtype(), CUISubtype.appleWatch38)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_watch-38@2x~watch.png")
Expand All @@ -276,9 +276,9 @@ class DeviceTests: XCTestCase {
XCTFail("Cannot find image")
}

if let image = images.filter({ return $0.subtype() == .AppleWatch42 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.AppleWatch)
XCTAssertEqual(image.subtype(), CUISubtype.AppleWatch42)
if let image = images.filter({ return $0.subtype() == .appleWatch42 }).first {
XCTAssertEqual(image.idiom(), CUIDeviceIdiom.appleWatch)
XCTAssertEqual(image.subtype(), CUISubtype.appleWatch42)
XCTAssertEqual(image.acScale.name, "@2x")
XCTAssertEqual(image.acIsPDF, false)
XCTAssertEqual(image.acImageName, "d_watch-42@2x~watch.png")
Expand Down
Loading

0 comments on commit df3b018

Please sign in to comment.