Better documentation generation

This commit is contained in:
Mike Farah 2020-11-13 21:34:43 +11:00
parent d91b25840a
commit 860655b4cd
2 changed files with 26 additions and 14 deletions

View File

@ -6,11 +6,13 @@ import (
var collectObjectOperatorScenarios = []expressionScenario{ var collectObjectOperatorScenarios = []expressionScenario{
{ {
description: `Collect empty object`,
document: ``, document: ``,
expression: `{}`, expression: `{}`,
expected: []string{}, expected: []string{},
}, },
{ {
description: `Wrap (prefix) existing object`,
document: "{name: Mike}\n", document: "{name: Mike}\n",
expression: `{"wrap": .}`, expression: `{"wrap": .}`,
expected: []string{ expected: []string{
@ -18,6 +20,7 @@ var collectObjectOperatorScenarios = []expressionScenario{
}, },
}, },
{ {
skipDoc: true,
document: "{name: Mike}\n---\n{name: Bob}", document: "{name: Mike}\n---\n{name: Bob}",
expression: `{"wrap": .}`, expression: `{"wrap": .}`,
expected: []string{ expected: []string{
@ -26,6 +29,7 @@ var collectObjectOperatorScenarios = []expressionScenario{
}, },
}, },
{ {
skipDoc: true,
document: `{name: Mike, age: 32}`, document: `{name: Mike, age: 32}`,
expression: `{.name: .age}`, expression: `{.name: .age}`,
expected: []string{ expected: []string{
@ -33,6 +37,7 @@ var collectObjectOperatorScenarios = []expressionScenario{
}, },
}, },
{ {
description: `Using splat to create multiple objects`,
document: `{name: Mike, pets: [cat, dog]}`, document: `{name: Mike, pets: [cat, dog]}`,
expression: `{.name: .pets[]}`, expression: `{.name: .pets[]}`,
expected: []string{ 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]}", document: "{name: Mike, pets: [cat, dog]}\n---\n{name: Rosey, pets: [monkey, sheep]}",
expression: `{.name: .pets[]}`, expression: `{.name: .pets[]}`,
expected: []string{ expected: []string{
"D0, P[], (!!map)::Mike: cat\n", "D0, P[], (!!map)::Mike: cat\n",
"D0, P[], (!!map)::Mike: dog\n", "D0, P[], (!!map)::Mike: dog\n",
"D0, P[], (!!map)::Rosey: monkey\n", "D1, P[], (!!map)::Rosey: monkey\n",
"D0, P[], (!!map)::Rosey: sheep\n", "D1, P[], (!!map)::Rosey: sheep\n",
"this is producing incorrect formatted yaml",
}, },
}, },
{ {
skipDoc: true,
document: `{name: Mike, pets: [cat, dog], food: [hotdog, burger]}`, document: `{name: Mike, pets: [cat, dog], food: [hotdog, burger]}`,
expression: `{.name: .pets[], "f":.food[]}`, expression: `{.name: .pets[], "f":.food[]}`,
expected: []string{ expected: []string{
@ -61,6 +69,7 @@ var collectObjectOperatorScenarios = []expressionScenario{
}, },
}, },
{ {
skipDoc: true,
document: `{name: Mike, pets: {cows: [apl, bba]}}`, document: `{name: Mike, pets: {cows: [apl, bba]}}`,
expression: `{"a":.name, "b":.pets}`, expression: `{"a":.name, "b":.pets}`,
expected: []string{ expected: []string{
@ -70,6 +79,7 @@ b: {cows: [apl, bba]}
}, },
}, },
{ {
description: "Creating yaml from scratch",
document: ``, document: ``,
expression: `{"wrap": "frog"}`, expression: `{"wrap": "frog"}`,
expected: []string{ expected: []string{
@ -77,6 +87,7 @@ b: {cows: [apl, bba]}
}, },
}, },
{ {
skipDoc: true,
document: `{name: Mike}`, document: `{name: Mike}`,
expression: `{"wrap": .}`, expression: `{"wrap": .}`,
expected: []string{ expected: []string{
@ -84,6 +95,7 @@ b: {cows: [apl, bba]}
}, },
}, },
{ {
skipDoc: true,
document: `{name: Mike}`, document: `{name: Mike}`,
expression: `{"wrap": {"further": .}} | (.. style= "flow")`, expression: `{"wrap": {"further": .}} | (.. style= "flow")`,
expected: []string{ expected: []string{

View File

@ -103,7 +103,7 @@ func documentScenarios(t *testing.T, title string, scenarios []expressionScenari
w := bufio.NewWriter(f) w := bufio.NewWriter(f)
writeOrPanic(w, "## Examples\n") writeOrPanic(w, "\n## Examples\n")
for index, s := range scenarios { for index, s := range scenarios {
if !s.skipDoc { if !s.skipDoc {