Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor throwing tests #61

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions Tests/ScreamURITemplateTests/TestFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ class TestFileTests: XCTestCase {
XCTFail("Test File Parse Failed")
}

func testSuccessfulProcess() {
do {
let template = try URITemplate(string: templateString)
let result = try template.process(variables: variables)
XCTAssertTrue(acceptableExpansions.contains(result))
} catch {
XCTFail("Unexpected Throw")
}
func testSuccessfulProcess() throws {
let template = try URITemplate(string: templateString)
let result = try template.process(variables: variables)
XCTAssertTrue(acceptableExpansions.contains(result))
}

func testFailedProcess() {
Expand Down
41 changes: 15 additions & 26 deletions Tests/ScreamURITemplateTests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ class Tests: XCTestCase {
XCTAssertEqual(template.description, "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
}

func testExpressibleByStringLiteral() {
func testExpressibleByStringLiteral() throws {
let templateA: URITemplate = "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}"
guard let templateB = try? URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}") else {
XCTFail("invalid template")
return
}
let templateB = try URITemplate(string: "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}")
XCTAssertEqual(templateA, templateB)
}

Expand Down Expand Up @@ -71,29 +68,21 @@ class Tests: XCTestCase {
XCTAssertEqual(variableNames, expected)
}

func testEncoding() {
do {
let templateString = "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}"
let template = try URITemplate(string: templateString)
let jsonData = try JSONEncoder().encode(["a": template])
let expectedData = try JSONEncoder().encode(["a": templateString])
XCTAssertEqual(jsonData, expectedData)
} catch {
XCTFail("unexpected throw")
}
func testEncoding() throws {
let templateString = "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}"
let template = try URITemplate(string: templateString)
let jsonData = try JSONEncoder().encode(["a": template])
let expectedData = try JSONEncoder().encode(["a": templateString])
XCTAssertEqual(jsonData, expectedData)
}

func testDecoding() {
do {
let templateString = "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}"
let jsonString = "{\"a\":\"\(templateString)\"}"
let jsonData = jsonString.data(using: .utf8)!
let object = try JSONDecoder().decode([String: URITemplate].self, from: jsonData)
let expectedTemplate = try URITemplate(string: templateString)
XCTAssertEqual(object["a"], expectedTemplate)
} catch {
XCTFail("unexpected throw")
}
func testDecoding() throws {
let templateString = "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}"
let jsonString = "{\"a\":\"\(templateString)\"}"
let jsonData = jsonString.data(using: .utf8)!
let object = try JSONDecoder().decode([String: URITemplate].self, from: jsonData)
let expectedTemplate = try URITemplate(string: templateString)
XCTAssertEqual(object["a"], expectedTemplate)
}

func testInitPerformance() {
Expand Down