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{
{
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{

View File

@ -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 {