From 4c2b9fe9ef5eac59eee8b5e7f1b9b0b35a21f748 Mon Sep 17 00:00:00 2001 From: Alex Deem Date: Sun, 2 Jun 2024 14:16:10 +1000 Subject: [PATCH] Refactor throwing tests --- .../TestFileTests.swift | 12 ++---- Tests/ScreamURITemplateTests/Tests.swift | 41 +++++++------------ 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/Tests/ScreamURITemplateTests/TestFileTests.swift b/Tests/ScreamURITemplateTests/TestFileTests.swift index a38ac7e..781456c 100644 --- a/Tests/ScreamURITemplateTests/TestFileTests.swift +++ b/Tests/ScreamURITemplateTests/TestFileTests.swift @@ -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() { diff --git a/Tests/ScreamURITemplateTests/Tests.swift b/Tests/ScreamURITemplateTests/Tests.swift index 51a7098..e6de45d 100644 --- a/Tests/ScreamURITemplateTests/Tests.swift +++ b/Tests/ScreamURITemplateTests/Tests.swift @@ -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) } @@ -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() {