blob: 6f8162e07a5eea1db24d231693287dfa6dc79b09 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import Foundation
import Testing
@testable import aria
@Test func addUriParamsEncodesPositionalArray() throws {
let params = Aria2.AddUriParams(
secret: "s3cret",
uris: ["https://example.com/file.zip"],
options: ["dir": "/tmp"]
)
let data = try JSONEncoder().encode(params)
let value = try JSONSerialization.jsonObject(with: data) as! [Any]
#expect(value.count == 3)
#expect(value[0] as? String == "token:s3cret")
#expect(value[1] as? [String] == ["https://example.com/file.zip"])
#expect(value[2] as? [String: String] == ["dir": "/tmp"])
}
@Test func addUriParamsOmitsSecretAndOptions() throws {
let params = Aria2.AddUriParams(secret: nil, uris: ["magnet:?xt=1"], options: [:])
let data = try JSONEncoder().encode(params)
let value = try JSONSerialization.jsonObject(with: data) as! [Any]
#expect(value.count == 1)
#expect(value[0] as? [String] == ["magnet:?xt=1"])
}
|