-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
101d583
commit 719cf6d
Showing
2 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
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,150 @@ | ||
import XCTest | ||
import Nimble | ||
import ApolloAPI | ||
|
||
class ObjectDataTransformerTests: XCTestCase { | ||
|
||
fileprivate struct DataTransformer: _ObjectData_Transformer { | ||
func transform(_ value: AnyHashable) -> (any ScalarType)? { | ||
switch value { | ||
case let scalar as any ScalarType: | ||
return scalar | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
// Empty until needed in tests | ||
func transform(_ value: AnyHashable) -> ObjectData? { return nil } | ||
func transform(_ value: AnyHashable) -> ListData? { return nil } | ||
} | ||
|
||
// MARK: ObjectData Tests | ||
|
||
func test__ObjectData_subscript_ScalarType__givenData_asInt_equalToBoolFalse_shouldReturnIntType() { | ||
// given | ||
let dataTransformer = ObjectData( | ||
_transformer: DataTransformer(), | ||
_rawData: ["intKey": 0] | ||
) | ||
|
||
// when | ||
let actual = dataTransformer["intKey"] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Int.self)) | ||
} | ||
|
||
func test__ObjectData_subscript_ScalarType__givenData_asInt_equalToBoolTrue_shouldReturnIntType() { | ||
// given | ||
let dataTransformer = ObjectData( | ||
_transformer: DataTransformer(), | ||
_rawData: ["intKey": 1] | ||
) | ||
|
||
// when | ||
let actual = dataTransformer["intKey"] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Int.self)) | ||
} | ||
|
||
func test__ObjectData_subscript_ScalarType__givenData_asInt_outsideBoolRange_shouldReturnIntType() { | ||
// given | ||
let dataTransformer = ObjectData( | ||
_transformer: DataTransformer(), | ||
_rawData: ["intKey": 2] | ||
) | ||
|
||
// when | ||
let actual = dataTransformer["intKey"] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Int.self)) | ||
} | ||
|
||
func test__ObjectData_subscript_ScalarType__givenData_asBool_true_shouldReturnBoolType() { | ||
// given | ||
let dataTransformer = ObjectData( | ||
_transformer: DataTransformer(), | ||
_rawData: ["boolKey": true] | ||
) | ||
|
||
// when | ||
let actual = dataTransformer["boolKey"] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Bool.self)) | ||
} | ||
|
||
func test__ObjectData_subscript_ScalarType__givenData_asBool_false_shouldReturnBoolType() { | ||
// given | ||
let dataTransformer = ObjectData( | ||
_transformer: DataTransformer(), | ||
_rawData: ["boolKey": false] | ||
) | ||
|
||
// when | ||
let actual = dataTransformer["boolKey"] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Bool.self)) | ||
} | ||
|
||
// MARK: ListData Tests | ||
|
||
func test__ListData_subscript_ScalarType__givenData_asInt_equalToBoolFalse_shouldReturnIntType() { | ||
// given | ||
let dataTransformer = ListData(_transformer: DataTransformer(), _rawData: [0]) | ||
|
||
// when | ||
let actual = dataTransformer[0] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Int.self)) | ||
} | ||
|
||
func test__ListData_subscript_ScalarType__givenData_asInt_equalToBoolTrue_shouldReturnIntType() { | ||
// given | ||
let dataTransformer = ListData(_transformer: DataTransformer(), _rawData: [1]) | ||
|
||
// when | ||
let actual = dataTransformer[0] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Int.self)) | ||
} | ||
|
||
func test__ListData_subscript_ScalarType__givenData_asInt_outsideBoolRange_shouldReturnIntType() { | ||
// given | ||
let dataTransformer = ListData(_transformer: DataTransformer(), _rawData: [2]) | ||
|
||
// when | ||
let actual = dataTransformer[0] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Int.self)) | ||
} | ||
|
||
func test__ListData_subscript_ScalarType__givenData_asBool_true_shouldReturnBoolType() { | ||
// given | ||
let dataTransformer = ListData(_transformer: DataTransformer(), _rawData: [true]) | ||
|
||
// when | ||
let actual = dataTransformer[0] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Bool.self)) | ||
} | ||
|
||
func test__ListData_subscript_ScalarType__givenData_asBool_false_shouldReturnBoolType() { | ||
// given | ||
let dataTransformer = ListData(_transformer: DataTransformer(), _rawData: [false]) | ||
|
||
// when | ||
let actual = dataTransformer[0] | ||
|
||
// then | ||
expect(actual).to(beAnInstanceOf(Bool.self)) | ||
} | ||
} |
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