mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Better documentation generation
This commit is contained in:
parent
d91b25840a
commit
860655b4cd
@ -6,11 +6,13 @@ import (
|
||||
|
||||
var collectObjectOperatorScenarios = []expressionScenario{
|
||||
{
|
||||
description: `Collect empty object`,
|
||||
document: ``,
|
||||
expression: `{}`,
|
||||
expected: []string{},
|
||||
},
|
||||
{
|
||||
description: `Wrap (prefix) existing object`,
|
||||
document: "{name: Mike}\n",
|
||||
expression: `{"wrap": .}`,
|
||||
expected: []string{
|
||||
@ -18,6 +20,7 @@ var collectObjectOperatorScenarios = []expressionScenario{
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: "{name: Mike}\n---\n{name: Bob}",
|
||||
expression: `{"wrap": .}`,
|
||||
expected: []string{
|
||||
@ -26,6 +29,7 @@ var collectObjectOperatorScenarios = []expressionScenario{
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{name: Mike, age: 32}`,
|
||||
expression: `{.name: .age}`,
|
||||
expected: []string{
|
||||
@ -33,6 +37,7 @@ var collectObjectOperatorScenarios = []expressionScenario{
|
||||
},
|
||||
},
|
||||
{
|
||||
description: `Using splat to create multiple objects`,
|
||||
document: `{name: Mike, pets: [cat, dog]}`,
|
||||
expression: `{.name: .pets[]}`,
|
||||
expected: []string{
|
||||
@ -41,16 +46,19 @@ var collectObjectOperatorScenarios = []expressionScenario{
|
||||
},
|
||||
},
|
||||
{
|
||||
description: `Working with multiple documents`,
|
||||
document: "{name: Mike, pets: [cat, dog]}\n---\n{name: Rosey, pets: [monkey, sheep]}",
|
||||
expression: `{.name: .pets[]}`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::Mike: cat\n",
|
||||
"D0, P[], (!!map)::Mike: dog\n",
|
||||
"D0, P[], (!!map)::Rosey: monkey\n",
|
||||
"D0, P[], (!!map)::Rosey: sheep\n",
|
||||
"D1, P[], (!!map)::Rosey: monkey\n",
|
||||
"D1, P[], (!!map)::Rosey: sheep\n",
|
||||
"this is producing incorrect formatted yaml",
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{name: Mike, pets: [cat, dog], food: [hotdog, burger]}`,
|
||||
expression: `{.name: .pets[], "f":.food[]}`,
|
||||
expected: []string{
|
||||
@ -61,6 +69,7 @@ var collectObjectOperatorScenarios = []expressionScenario{
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{name: Mike, pets: {cows: [apl, bba]}}`,
|
||||
expression: `{"a":.name, "b":.pets}`,
|
||||
expected: []string{
|
||||
@ -70,6 +79,7 @@ b: {cows: [apl, bba]}
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Creating yaml from scratch",
|
||||
document: ``,
|
||||
expression: `{"wrap": "frog"}`,
|
||||
expected: []string{
|
||||
@ -77,6 +87,7 @@ b: {cows: [apl, bba]}
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{name: Mike}`,
|
||||
expression: `{"wrap": .}`,
|
||||
expected: []string{
|
||||
@ -84,6 +95,7 @@ b: {cows: [apl, bba]}
|
||||
},
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{name: Mike}`,
|
||||
expression: `{"wrap": {"further": .}} | (.. style= "flow")`,
|
||||
expected: []string{
|
||||
|
@ -103,7 +103,7 @@ func documentScenarios(t *testing.T, title string, scenarios []expressionScenari
|
||||
|
||||
w := bufio.NewWriter(f)
|
||||
|
||||
writeOrPanic(w, "## Examples\n")
|
||||
writeOrPanic(w, "\n## Examples\n")
|
||||
|
||||
for index, s := range scenarios {
|
||||
if !s.skipDoc {
|
||||
|
Loading…
Reference in New Issue
Block a user