Skip to content

Commit

Permalink
Renaming to and spelling fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrandelli committed Nov 14, 2016
1 parent b50c206 commit ea906f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions MarshalTests/MarshalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,33 +398,33 @@ class MarshalTests: XCTestCase {
let optionalArrayOfOptionalCars: [Car?]? = try? json.value(for: "cars")
XCTAssertNotNil(optionalArrayOfOptionalCars, "optionalArrayOfOptionalCars should not be nil")
XCTAssert(optionalArrayOfOptionalCars?.count == 8, "optionalArrayOfOptionalCars should have 8 objects. Actual count = \(optionalArrayOfOptionalCars?.count)")
XCTAssert(optionalArrayOfOptionalCars?.contains(where: { $0?.make == "Lexus" }) == false, "optionalArrayOfOptionalCars should not contain a Lexus becasue the Lexus was malformed")
XCTAssert(optionalArrayOfOptionalCars?.contains(where: { $0?.make == "Lexus" }) == false, "optionalArrayOfOptionalCars should not contain a Lexus because the Lexus was malformed")
XCTAssert(optionalArrayOfOptionalCars?[1] == nil, "optionalArrayOfOptionalCars[1] should be nil")

do {
let arrayOfOptionalCars: [Car?] = try json.value(for: "cars")

XCTAssertNotNil(arrayOfOptionalCars, "arrayOfOptionalCars should not be nil")
XCTAssert(arrayOfOptionalCars.count == 8, "arrayOfOptionalCars should have 8 objects. Actual count = \(optionalArrayOfOptionalCars?.count)")
XCTAssert(arrayOfOptionalCars.contains(where: { $0?.make == "Lexus" }) == false, "arrayOfOptionalCars should not contain a Lexus becasue the Lexus was malformed")
XCTAssert(arrayOfOptionalCars.contains(where: { $0?.make == "Lexus" }) == false, "arrayOfOptionalCars should not contain a Lexus because the Lexus was malformed")
XCTAssert(arrayOfOptionalCars[1] == nil, "arrayOfOptionalCars[1] should be nil")
}
catch {
XCTFail("error marshaling arrayOfOptionalCars: \(error)")
}
}

func testDiscardingInvalidObjects() {
func testDiscardingErrors() {
guard let path = Bundle(for: type(of: self)).path(forResource: "TestMissingData", ofType: "json"),
let data = try? Data(contentsOf: URL(fileURLWithPath: path)),
let json = try? JSONParser.JSONObjectWithData(data) else {
XCTFail("Error parsing TestMissingData.json")
return
}

let arrayOfCarsWithoutInvalidObjects: [Car]? = try? json.value(for: "cars", discardInvalidObjects: true)
let arrayOfCarsWithoutInvalidObjects: [Car]? = try? json.value(for: "cars", discardingErrors: true)
XCTAssert(arrayOfCarsWithoutInvalidObjects?.count == 5, "arrayOfCarsWithoutInvalidObjects should have 5 objects. Actual count = \(arrayOfCarsWithoutInvalidObjects?.count)")
XCTAssert(arrayOfCarsWithoutInvalidObjects?.contains(where: { $0.make == "Lexus" }) == false, "arrayOfCarsWithoutInvalidObjects should not contain a Lexus becasue the Lexus was malformed")
XCTAssert(arrayOfCarsWithoutInvalidObjects?.contains(where: { $0.make == "Lexus" }) == false, "arrayOfCarsWithoutInvalidObjects should not contain a Lexus because the Lexus was malformed")
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/MarshaledObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public extension MarshaledObject {
}
}

public func value<A: ValueType>(for key: KeyType, discardInvalidObjects: Bool = false) throws -> [A] {
public func value<A: ValueType>(for key: KeyType, discardingErrors: Bool = false) throws -> [A] {
let any = try self.any(for: key)
do {
return try Array<A>.value(from: any, discardInvalidObjects: discardInvalidObjects)
return try Array<A>.value(from: any, discardingErrors: discardingErrors)
}
catch let MarshalError.typeMismatch(expected: expected, actual: actual) {
throw MarshalError.typeMismatchWithKey(key: key.stringValue, expected: expected, actual: actual)
Expand All @@ -84,9 +84,9 @@ public extension MarshaledObject {
}
}

public func value<A: ValueType>(for key: KeyType, discardInvalidObjects: Bool = false) throws -> [A]? {
public func value<A: ValueType>(for key: KeyType, discardingErrors: Bool = false) throws -> [A]? {
do {
return try self.value(for: key, discardInvalidObjects: discardInvalidObjects) as [A]
return try self.value(for: key, discardingErrors: discardingErrors) as [A]
}
catch MarshalError.keyNotFound {
return nil
Expand Down
4 changes: 2 additions & 2 deletions Sources/ValueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ extension Int64: ValueType {
}

extension Array where Element: ValueType {
public static func value(from object: Any, discardInvalidObjects: Bool = false) throws -> [Element] {
public static func value(from object: Any, discardingErrors: Bool = false) throws -> [Element] {
guard let anyArray = object as? [AnyObject] else {
throw MarshalError.typeMismatch(expected: self, actual: type(of: object))
}

if discardInvalidObjects {
if discardingErrors {
return anyArray.flatMap {
let value = try? Element.value(from: $0)
guard let element = value as? Element else {
Expand Down

0 comments on commit ea906f7

Please sign in to comment.