Skip to content

Commit

Permalink
add url-encodedform array tests, #2338
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed May 6, 2020
1 parent c70d45f commit 6d4a71b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Tests/VaporTests/URLEncodedFormTests.swift
Expand Up @@ -101,6 +101,32 @@ final class URLEncodedFormTests: XCTestCase {
XCTAssertEqual(user.isCool, false)
}

func testDecodeIndexedArray() throws {
struct Test: Decodable {
let array: [String]
}

let data = """
array[0]=a&array[1]=b
"""
let test = try URLEncodedFormDecoder().decode(Test.self, from: data)
XCTAssertEqual(test.array[0], "a")
XCTAssertEqual(test.array[1], "b")
}

func testDecodeIndexedArray_dictionary() throws {
struct Test: Decodable {
let array: [Int: String]
}

let data = """
array[0]=a&array[1]=b
"""
let test = try URLEncodedFormDecoder().decode(Test.self, from: data)
XCTAssertEqual(test.array[0], "a")
XCTAssertEqual(test.array[1], "b")
}

func testEncode() throws {
let user = User(name: "Tanner", age: 23, pets: ["Zizek", "Foo"], dict: ["a": 1, "b": 2], foos: [.baz], nums: [3.14], isCool: true)
let result = try URLEncodedFormEncoder().encode(user)
Expand Down

0 comments on commit 6d4a71b

Please sign in to comment.