yq/pkg/yqlib/operatory_style_test.go

55 lines
1.1 KiB
Go
Raw Normal View History

2020-11-03 23:48:43 +00:00
package yqlib
2020-11-02 00:20:38 +00:00
import (
"testing"
)
var styleOperatorScenarios = []expressionScenario{
{
document: `{a: cat}`,
expression: `.a style="single"`,
expected: []string{
"D0, P[], (doc)::{a: 'cat'}\n",
},
},
2020-11-06 00:23:26 +00:00
{
description: "Set style using a path",
document: `{a: cat, b: double}`,
expression: `.a style=.b`,
expected: []string{
"D0, P[], (doc)::{a: \"cat\", b: double}\n",
},
},
2020-11-02 00:20:38 +00:00
{
document: `{a: "cat", b: 'dog'}`,
expression: `.. style=""`,
expected: []string{
"D0, P[], (!!map)::a: cat\nb: dog\n",
},
},
{
document: `{a: "cat", b: 'thing'}`,
expression: `.. | style`,
expected: []string{
"D0, P[], (!!str)::flow\n",
"D0, P[a], (!!str)::double\n",
"D0, P[b], (!!str)::single\n",
},
},
{
document: `a: cat`,
expression: `.. | style`,
expected: []string{
"D0, P[], (!!str)::\"\"\n",
"D0, P[a], (!!str)::\"\"\n",
},
},
}
func TestStyleOperatorScenarios(t *testing.T) {
for _, tt := range styleOperatorScenarios {
testScenario(t, &tt)
}
2020-11-06 00:23:26 +00:00
documentScenarios(t, "Style Operator", styleOperatorScenarios)
2020-11-02 00:20:38 +00:00
}