-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Oni-zerone/feature/beer-parsing
Feature/beer parsing
- Loading branch information
Showing
19 changed files
with
433 additions
and
250 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Example/PunkAPI.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict/> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// BeerParsingTests.swift | ||
// PunkAPI_Tests | ||
// | ||
// Created by Andrea Altea on 17/02/2019. | ||
// Copyright © 2019 CocoaPods. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import PunkAPI | ||
|
||
class BeerParsingTests: XCTestCase { | ||
|
||
var parser: JSONDecoder! | ||
|
||
override func setUp() { | ||
|
||
let parser = JSONDecoder() | ||
parser.keyDecodingStrategy = .convertFromSnakeCase | ||
self.parser = parser | ||
} | ||
|
||
override func tearDown() { | ||
self.parser = nil | ||
} | ||
|
||
func testFirst() { | ||
self.decodeBeers(BeerStub.first) | ||
} | ||
|
||
func testSecond() { | ||
self.decodeBeers(BeerStub.second) | ||
} | ||
|
||
func testThird() { | ||
self.decodeBeers(BeerStub.third) | ||
} | ||
|
||
func testFourth() { | ||
self.decodeBeers(BeerStub.fourth) | ||
} | ||
|
||
func testFifth() { | ||
self.decodeBeers(BeerStub.fifth) | ||
} | ||
|
||
func testSixth() { | ||
self.decodeBeers(BeerStub.sixth) | ||
} | ||
|
||
func testMultipleFirst() { | ||
self.decodeBeers(BeerStub.multipleFirst) | ||
} | ||
|
||
func testMultipleSecond() { | ||
self.decodeBeers(BeerStub.multipleSecond) | ||
} | ||
|
||
@discardableResult | ||
func decodeBeers(_ json: String) -> [Beer]? { | ||
|
||
do { | ||
guard let data = json.data(using: .utf8) else { | ||
XCTFail("invalid stub") | ||
return nil | ||
} | ||
return try self.parser.decode([Beer].self, from: data) | ||
} catch let error { | ||
XCTFail(error.localizedDescription) | ||
return nil | ||
} | ||
} | ||
} |
Oops, something went wrong.