Skip to content

Commit efe0f65

Browse files
authored
Order slices of strings to be sure what the output of Println in doctests will be. (#3241)
* Sort the slices of strings in doctest to make the output deterministic * fix wording
1 parent 0e3ea5f commit efe0f65

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: doctests/sets_example_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package example_commands_test
55
import (
66
"context"
77
"fmt"
8+
"sort"
89

910
"github.com/redis/go-redis/v9"
1011
)
@@ -215,6 +216,9 @@ func ExampleClient_saddsmembers() {
215216
panic(err)
216217
}
217218

219+
// Sort the strings in the slice to make sure the output is lexicographical
220+
sort.Strings(res10)
221+
218222
fmt.Println(res10) // >>> [bike:1 bike:2 bike:3]
219223
// STEP_END
220224

@@ -294,6 +298,10 @@ func ExampleClient_sdiff() {
294298
panic(err)
295299
}
296300

301+
302+
// Sort the strings in the slice to make sure the output is lexicographical
303+
sort.Strings(res13)
304+
297305
fmt.Println(res13) // >>> [bike:2 bike:3]
298306
// STEP_END
299307

@@ -349,6 +357,9 @@ func ExampleClient_multisets() {
349357
panic(err)
350358
}
351359

360+
// Sort the strings in the slice to make sure the output is lexicographical
361+
sort.Strings(res15)
362+
352363
fmt.Println(res15) // >>> [bike:1 bike:2 bike:3 bike:4]
353364

354365
res16, err := rdb.SDiff(ctx, "bikes:racing:france", "bikes:racing:usa", "bikes:racing:italy").Result()
@@ -373,6 +384,9 @@ func ExampleClient_multisets() {
373384
panic(err)
374385
}
375386

387+
// Sort the strings in the slice to make sure the output is lexicographical
388+
sort.Strings(res18)
389+
376390
fmt.Println(res18) // >>> [bike:2 bike:3]
377391
// STEP_END
378392

0 commit comments

Comments
 (0)