Skip to content

Commit 2e38231

Browse files
committed
add missing tests for HttpMethod core type
1 parent 43f6eeb commit 2e38231

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
//
2+
// HttpTypeTests.swift
3+
//
4+
5+
import OpenAPIKitCore
6+
import XCTest
7+
8+
final class HttpMethodTests: XCTestCase {
9+
func test_builtinInits() {
10+
let methods: [Shared.HttpMethod] = [
11+
.get,
12+
.post,
13+
.patch,
14+
.put,
15+
.delete,
16+
.head,
17+
.options,
18+
.trace,
19+
.query
20+
]
21+
22+
XCTAssertEqual(methods, [
23+
.builtin(.get),
24+
.builtin(.post),
25+
.builtin(.patch),
26+
.builtin(.put),
27+
.builtin(.delete),
28+
.builtin(.head),
29+
.builtin(.options),
30+
.builtin(.trace),
31+
.builtin(.query)
32+
])
33+
34+
XCTAssertEqual(methods.map(\.rawValue), [
35+
"GET",
36+
"POST",
37+
"PATCH",
38+
"PUT",
39+
"DELETE",
40+
"HEAD",
41+
"OPTIONS",
42+
"TRACE",
43+
"QUERY"
44+
])
45+
46+
XCTAssertEqual(methods, [
47+
"GET",
48+
"POST",
49+
"PATCH",
50+
"PUT",
51+
"DELETE",
52+
"HEAD",
53+
"OPTIONS",
54+
"TRACE",
55+
"QUERY"
56+
])
57+
58+
XCTAssertEqual(methods.map(Optional.some), [
59+
.init(rawValue: "GET"),
60+
.init(rawValue: "POST"),
61+
.init(rawValue: "PATCH"),
62+
.init(rawValue: "PUT"),
63+
.init(rawValue: "DELETE"),
64+
.init(rawValue: "HEAD"),
65+
.init(rawValue: "OPTIONS"),
66+
.init(rawValue: "TRACE"),
67+
.init(rawValue: "QUERY")
68+
])
69+
}
70+
71+
func test_otherInit() {
72+
let otherMethod = Shared.HttpMethod.other("LINK")
73+
XCTAssertEqual(otherMethod, Shared.HttpMethod(rawValue: "LINK"))
74+
XCTAssertEqual(otherMethod, "LINK")
75+
XCTAssertEqual(otherMethod.rawValue, "LINK")
76+
}
77+
78+
func test_knownBadCasing() {
79+
XCTAssertNil(Shared.HttpMethod(rawValue: "link"))
80+
XCTAssertEqual(Shared.HttpMethod.other("link"), "link")
81+
XCTAssertEqual(Shared.HttpMethod.problem(with: "link"), "'link' must be uppercased")
82+
}
83+
84+
func test_encoding() throws {
85+
let methods: [Shared.HttpMethod] = [
86+
.get,
87+
.post,
88+
.patch,
89+
.put,
90+
.delete,
91+
.head,
92+
.options,
93+
.trace,
94+
.query,
95+
"LINK"
96+
]
97+
98+
for method in methods {
99+
let encoded = try orderUnstableTestStringFromEncoding(of: method)
100+
101+
XCTAssertEqual(encoded, "\"\(method.rawValue)\"")
102+
}
103+
}
104+
105+
func test_decoding() throws {
106+
let methods: [String] = [
107+
"GET",
108+
"POST",
109+
"PATCH",
110+
"PUT",
111+
"DELETE",
112+
"HEAD",
113+
"OPTIONS",
114+
"TRACE",
115+
"QUERY",
116+
"LINK"
117+
]
118+
119+
for method in methods {
120+
let decoded = try orderUnstableDecode(Shared.HttpMethod.self, from: "\"\(method)\"".data(using: .utf8)!)
121+
122+
XCTAssertEqual(decoded, Shared.HttpMethod(rawValue: method))
123+
}
124+
}
125+
}

0 commit comments

Comments
 (0)