Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,42 @@ module ToQueryParamsTests =
let result = toQueryParams "id" (box [| g1; g2 |]) stubClient
result |> shouldEqual [ ("id", g1.ToString()); ("id", g2.ToString()) ]

[<Fact>]
let ``toQueryParams handles float32 array``() =
let result = toQueryParams "v" (box [| 1.5f; 2.5f |]) stubClient
result |> shouldEqual [ ("v", "1.5"); ("v", "2.5") ]

[<Fact>]
let ``toQueryParams handles double array``() =
let result = toQueryParams "v" (box [| 1.5; 2.5 |]) stubClient
result |> shouldEqual [ ("v", "1.5"); ("v", "2.5") ]
Comment on lines +176 to +181

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected values for float32 are hard-coded as "1.5"/"2.5", but toQueryParams ultimately uses value.ToString() for floats, which is culture-sensitive. This test can fail on machines with a comma decimal separator. Prefer deriving expected strings from 1.5f.ToString() etc. (or formatting with InvariantCulture if that’s the intended contract).

Suggested change
result |> shouldEqual [ ("v", "1.5"); ("v", "2.5") ]
[<Fact>]
let ``toQueryParams handles double array``() =
let result = toQueryParams "v" (box [| 1.5; 2.5 |]) stubClient
result |> shouldEqual [ ("v", "1.5"); ("v", "2.5") ]
let expected = [ ("v", 1.5f.ToString()); ("v", 2.5f.ToString()) ]
result |> shouldEqual expected
[<Fact>]
let ``toQueryParams handles double array``() =
let result = toQueryParams "v" (box [| 1.5; 2.5 |]) stubClient
let expected = [ ("v", 1.5.ToString()); ("v", 2.5.ToString()) ]
result |> shouldEqual expected

Copilot uses AI. Check for mistakes.
Comment on lines +179 to +181

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same culture-sensitivity issue as the float32 test: toQueryParams uses ToString() for doubles, so hard-coding "1.5"/"2.5" may be flaky under non-invariant cultures. Build the expected strings using 1.5.ToString() (or explicit invariant formatting if you want to lock the behavior down).

Copilot uses AI. Check for mistakes.

[<Fact>]
let ``toQueryParams handles byte array as base64``() =
// byte[] is serialized via client.Serialize (JSON base64) with surrounding quotes trimmed
let bytes = [| 72uy; 101uy; 108uy; 108uy; 111uy |] // "Hello" in ASCII
let expected = (JsonSerializer.Serialize bytes).Trim('"')

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is meant to validate the client.Serialize(bytes).Trim('"') path, but the expected value is computed via JsonSerializer.Serialize directly. To avoid divergence if stubClient.Serialize changes/options are used, compute expected via stubClient.Serialize(bytes).Trim('"') instead.

Suggested change
let expected = (JsonSerializer.Serialize bytes).Trim('"')
let expected = stubClient.Serialize(bytes).Trim('"')

Copilot uses AI. Check for mistakes.
let result = toQueryParams "data" (box bytes) stubClient
result |> shouldEqual [ ("data", expected) ]

[<Fact>]
let ``toQueryParams skips None items in Option<string> array``() =
let values: Option<string>[] = [| Some "a"; None; Some "c" |]
let result = toQueryParams "q" (box values) stubClient
result |> shouldEqual [ ("q", "a"); ("q", "c") ]

[<Fact>]
let ``toQueryParams skips None items in Option<float32> array``() =
let values: Option<float32>[] = [| Some 1.5f; None; Some 3.5f |]
let result = toQueryParams "v" (box values) stubClient
result |> shouldEqual [ ("v", "1.5"); ("v", "3.5") ]
Comment on lines +199 to +201

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded expected strings for Option<float32>[] have the same culture-sensitivity issue as the float array test. Since runtime behavior is ToString(), prefer deriving expected from 1.5f.ToString()/3.5f.ToString() (or explicit invariant formatting if intended).

Suggested change
let values: Option<float32>[] = [| Some 1.5f; None; Some 3.5f |]
let result = toQueryParams "v" (box values) stubClient
result |> shouldEqual [ ("v", "1.5"); ("v", "3.5") ]
let v1 = 1.5f
let v3 = 3.5f
let values: Option<float32>[] = [| Some v1; None; Some v3 |]
let result = toQueryParams "v" (box values) stubClient
result |> shouldEqual [ ("v", v1.ToString()); ("v", v3.ToString()) ]

Copilot uses AI. Check for mistakes.

[<Fact>]
let ``toQueryParams skips None items in Option<double> array``() =
let values: Option<double>[] = [| Some 1.5; None; Some 3.5 |]
let result = toQueryParams "v" (box values) stubClient
result |> shouldEqual [ ("v", "1.5"); ("v", "3.5") ]
Comment on lines +204 to +207

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded expected strings for Option<double>[] can be culture-dependent because toQueryParams uses ToString() for doubles. Prefer deriving expected from 1.5.ToString()/3.5.ToString() (or explicit invariant formatting if intended).

Copilot uses AI. Check for mistakes.


module CombineUrlTests =

Expand Down