2023-02-10 18:08:20 +00:00
|
|
|
package yqlib
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
var shuffleOperatorScenarios = []expressionScenario{
|
|
|
|
{
|
|
|
|
description: "Shuffle array",
|
|
|
|
document: "[1, 2, 3, 4, 5]",
|
|
|
|
expression: `shuffle`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[], (!!seq)::[5, 2, 4, 1, 3]\n",
|
|
|
|
},
|
|
|
|
},
|
2024-06-15 12:13:58 +00:00
|
|
|
{
|
|
|
|
description: "Shuffle array",
|
|
|
|
skipDoc: true,
|
|
|
|
document: "[1, 2, 3]",
|
|
|
|
expression: `shuffle[]`,
|
|
|
|
expected: []string{
|
|
|
|
"D0, P[2], (!!int)::3\n",
|
|
|
|
"D0, P[0], (!!int)::1\n",
|
|
|
|
"D0, P[1], (!!int)::2\n",
|
|
|
|
},
|
|
|
|
},
|
2023-02-10 18:08:20 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
description: "Shuffle array in place",
|
|
|
|
document: "cool: [1, 2, 3, 4, 5]",
|
|
|
|
expression: `.cool |= shuffle`,
|
|
|
|
expected: []string{
|
2023-10-18 01:11:53 +00:00
|
|
|
"D0, P[], (!!map)::cool: [5, 2, 4, 1, 3]\n",
|
2023-02-10 18:08:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShuffleByOperatorScenarios(t *testing.T) {
|
|
|
|
for _, tt := range shuffleOperatorScenarios {
|
|
|
|
testScenario(t, &tt)
|
|
|
|
}
|
|
|
|
documentOperatorScenarios(t, "shuffle", shuffleOperatorScenarios)
|
|
|
|
}
|