Skip to content

Commit e89aec1

Browse files
committed
add unit test for change to parser
1 parent 28b56f0 commit e89aec1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

XCode/Tests/SwifterTestsHttpParser.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,17 @@ class SwifterTestsHttpParser: XCTestCase {
165165
resp = try? parser.readHttpRequest(TestSocket("GET / HTTP/1.0\nHeader1: 1\nHeader2: 2\nContent-Length: 0\n\n"))
166166
XCTAssertEqual(resp?.headers["header1"], "1", "Parser should extract multiple headers from the request.")
167167
XCTAssertEqual(resp?.headers["header2"], "2", "Parser should extract multiple headers from the request.")
168+
169+
resp = try? parser.readHttpRequest(TestSocket("GET https://www.example.com/some/path?subscript_query[]=1&subscript_query[]=2 HTTP/1.0\nContent-Length: 10\n\n1234567890"))
170+
let queryPairs = resp?.queryParams ?? []
171+
XCTAssertEqual(queryPairs.count, 2)
172+
XCTAssertEqual(queryPairs.first?.0, "subscript_query[]")
173+
XCTAssertEqual(queryPairs.first?.1, "1")
174+
XCTAssertEqual(queryPairs.last?.0, "subscript_query[]")
175+
XCTAssertEqual(queryPairs.last?.1, "2")
176+
XCTAssertEqual(resp?.method, "GET", "Parser should extract HTTP method name from the status line.")
177+
XCTAssertEqual(resp?.path, "/some/path", "Parser should extract HTTP path value from the status line.")
178+
XCTAssertEqual(resp?.headers["content-length"], "10", "Parser should extract Content-Length header value.")
179+
168180
}
169181
}

0 commit comments

Comments
 (0)