Skip to content

Commit

Permalink
Sort variables provided as a dictionary for stability
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdeem committed Jun 8, 2024
1 parent 529e109 commit a1de3b0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sources/ScreamURITemplate/VariableValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension KeyValuePairs<String, StringVariableValue>: VariableValue {

extension [String: StringVariableValue]: VariableValue {
public func asTypedVariableValue() -> TypedVariableValue? {
.associativeArray(map { ($0, $1.asStringVariableValue()) })
.associativeArray(map { ($0, $1.asStringVariableValue()) }.sorted { $0.0 < $1.0 })
}
}

Expand Down
13 changes: 1 addition & 12 deletions Tests/ScreamURITemplateTests/TestModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,7 @@ extension TestCase {
let expansionsData = data[1]
switch expansionsData {
case let .string(string):
// HACK: ensure the tests support alternate ordering for dictionary explode tests
// A PR has been raised to add support for the alternate ordering https://github.com/uri-templates/uritemplate-test/pull/58
switch string {
case "key1,val1%2F,key2,val2%2F":
acceptableExpansions = [string, "key2,val2%2F,key1,val1%2F"]
case "#key1,val1%2F,key2,val2%2F":
acceptableExpansions = [string, "#key2,val2%2F,key1,val1%2F"]
case "key1,val1%252F,key2,val2%252F":
acceptableExpansions = [string, "key2,val2%252F,key1,val1%252F"]
default:
acceptableExpansions = [string]
}
acceptableExpansions = [string]
shouldFail = false
case let .array(array):
acceptableExpansions = array.compactMap { value in
Expand Down
2 changes: 1 addition & 1 deletion Tests/ScreamURITemplateTests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Tests: XCTestCase {
] as KeyValuePairs,
]
let urlString = try template.process(variables: variables)
XCTAssertTrue(["https://api.example.com/a,42/SwiftScream?a=A&b=42&b2=42&a2=A", "https://api.example.com/a,42/SwiftScream?b=42&a=A&b2=42&a2=A"].contains(urlString))
XCTAssertEqual("https://api.example.com/a,42/SwiftScream?a=A&b=42&b2=42&a2=A", urlString)
}

func testSendable() {
Expand Down

0 comments on commit a1de3b0

Please sign in to comment.