-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
51 additions
and
0 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,51 @@ | ||
import CustomDump | ||
import XCTest | ||
|
||
@testable import GraphQLPagination | ||
|
||
final class CursorTests: XCTestCase { | ||
|
||
func test_string() throws { | ||
let id = Cursor(rawValue: "testing123") | ||
|
||
XCTAssertEqual(id.rawValue, "testing123") | ||
XCTAssertEqual(id.description, "dGVzdGluZzEyMw==") | ||
|
||
XCTAssertEqual( | ||
String(data: try JSONEncoder().encode(id), encoding: .utf8), | ||
""" | ||
"dGVzdGluZzEyMw==" | ||
""" | ||
) | ||
} | ||
|
||
func test_intValue() throws { | ||
let id = Cursor(intValue: 3) | ||
|
||
XCTAssertEqual(id.rawValue, "3") | ||
XCTAssertEqual(id.description, "Mw==") | ||
|
||
XCTAssertEqual( | ||
String(data: try JSONEncoder().encode(id), encoding: .utf8), | ||
""" | ||
"Mw==" | ||
""" | ||
) | ||
} | ||
|
||
func test_coding_roundtrip() throws { | ||
let id = Cursor(rawValue: "testing123") | ||
let encoded = try JSONEncoder().encode(id) | ||
let decoded = try JSONDecoder().decode(Cursor.self, from: encoded) | ||
XCTAssertNoDifference(id, decoded) | ||
} | ||
|
||
func test_intValue_valid() { | ||
let id = Cursor(intValue: 3) | ||
XCTAssertEqual(id.intValue(), 3) | ||
} | ||
func test_intValue_invalid() { | ||
let id = Cursor(rawValue: "foo") | ||
XCTAssertEqual(id.intValue(), nil) | ||
} | ||
} |