Unit tests pass!

This commit is contained in:
Mike Farah 2023-06-06 11:06:23 -07:00
parent b2415f2ca5
commit 584ec998bc
6 changed files with 22 additions and 20 deletions

View File

@ -83,7 +83,6 @@ yq -o=props '... comments = ""' sample.yml
``` ```
will output will output
```properties ```properties
# block comments come through
person.name = Mike Wazowski person.name = Mike Wazowski
person.pets.0 = cat person.pets.0 = cat
person.food.0 = pizza person.food.0 = pizza

View File

@ -93,7 +93,7 @@ func (e *xmlEncoder) Encode(writer io.Writer, node *CandidateNode) error {
} }
return encoder.Flush() return encoder.Flush()
default: default:
return fmt.Errorf("unsupported type %v", node.Tag) return fmt.Errorf("cannot encode %v to XML - only maps can be encoded", node.Tag)
} }
return encoder.EncodeToken(newLine) return encoder.EncodeToken(newLine)

View File

@ -11,7 +11,7 @@ var uniqueOperatorScenarios = []expressionScenario{
document: `[2,1,3,2]`, document: `[2,1,3,2]`,
expression: `unique`, expression: `unique`,
expected: []string{ expected: []string{
"D0, P[], (!!seq)::- 2\n- 1\n- 3\n", "D0, P[], (!!seq)::[2, 1, 3]\n",
}, },
}, },
{ {
@ -20,7 +20,7 @@ var uniqueOperatorScenarios = []expressionScenario{
document: `[~,null, ~, null]`, document: `[~,null, ~, null]`,
expression: `unique`, expression: `unique`,
expected: []string{ expected: []string{
"D0, P[], (!!seq)::- ~\n- null\n", "D0, P[], (!!seq)::[~, null]\n",
}, },
}, },
{ {
@ -29,7 +29,7 @@ var uniqueOperatorScenarios = []expressionScenario{
document: `[~,null, ~, null]`, document: `[~,null, ~, null]`,
expression: `unique_by(tag)`, expression: `unique_by(tag)`,
expected: []string{ expected: []string{
"D0, P[], (!!seq)::- ~\n", "D0, P[], (!!seq)::[~]\n",
}, },
}, },
{ {
@ -37,7 +37,7 @@ var uniqueOperatorScenarios = []expressionScenario{
document: `[{name: harry, pet: cat}, {name: billy, pet: dog}, {name: harry, pet: dog}]`, document: `[{name: harry, pet: cat}, {name: billy, pet: dog}, {name: harry, pet: dog}]`,
expression: `unique_by(.name)`, expression: `unique_by(.name)`,
expected: []string{ expected: []string{
"D0, P[], (!!seq)::- {name: harry, pet: cat}\n- {name: billy, pet: dog}\n", "D0, P[], (!!seq)::[{name: harry, pet: cat}, {name: billy, pet: dog}]\n",
}, },
}, },
{ {
@ -45,7 +45,7 @@ var uniqueOperatorScenarios = []expressionScenario{
document: `[{name: harry, pet: cat}, {pet: fish}, {name: harry, pet: dog}]`, document: `[{name: harry, pet: cat}, {pet: fish}, {name: harry, pet: dog}]`,
expression: `unique_by(.name)`, expression: `unique_by(.name)`,
expected: []string{ expected: []string{
"D0, P[], (!!seq)::- {name: harry, pet: cat}\n- {pet: fish}\n", "D0, P[], (!!seq)::[{name: harry, pet: cat}, {pet: fish}]\n",
}, },
}, },
{ {
@ -53,7 +53,7 @@ var uniqueOperatorScenarios = []expressionScenario{
document: `[{name: harry, pet: cat}, {pet: fish}, {name: harry, pet: dog}]`, document: `[{name: harry, pet: cat}, {pet: fish}, {name: harry, pet: dog}]`,
expression: `unique_by(.cat.dog)`, expression: `unique_by(.cat.dog)`,
expected: []string{ expected: []string{
"D0, P[], (!!seq)::- {name: harry, pet: cat}\n", "D0, P[], (!!seq)::[{name: harry, pet: cat}]\n",
}, },
}, },
{ {
@ -61,7 +61,7 @@ var uniqueOperatorScenarios = []expressionScenario{
document: "# abc\n[{name: harry, pet: cat}, {pet: fish}, {name: harry, pet: dog}]\n# xyz", document: "# abc\n[{name: harry, pet: cat}, {pet: fish}, {name: harry, pet: dog}]\n# xyz",
expression: `unique_by(.name)`, expression: `unique_by(.name)`,
expected: []string{ expected: []string{
"D0, P[], (!!seq)::# abc\n- {name: harry, pet: cat}\n- {pet: fish}\n# xyz\n", "D0, P[], (!!seq)::# abc\n[{name: harry, pet: cat}, {pet: fish}]\n# xyz\n",
}, },
}, },
} }

View File

@ -98,6 +98,16 @@ const expectedDecodedYaml = `person:
- pizza - pizza
` `
const expectedDecodedPersonYaml = `# block comments come through
# comments on values appear
name: Mike Wazowski
pets:
# comments on array values appear
- cat
food:
- pizza
`
const expectedPropertiesNoComments = `person.name = Mike Wazowski const expectedPropertiesNoComments = `person.name = Mike Wazowski
person.pets.0 = cat person.pets.0 = cat
person.food.0 = pizza person.food.0 = pizza
@ -153,7 +163,7 @@ var propertyScenarios = []formatScenario{
description: "Decode properties - keeps key information", description: "Decode properties - keeps key information",
input: expectedPropertiesUnwrapped, input: expectedPropertiesUnwrapped,
expression: ".person.name | key", expression: ".person.name | key",
expected: "name", expected: "name\n",
scenarioType: "decode", scenarioType: "decode",
}, },
{ {
@ -161,7 +171,7 @@ var propertyScenarios = []formatScenario{
description: "Decode properties - keeps parent information", description: "Decode properties - keeps parent information",
input: expectedPropertiesUnwrapped, input: expectedPropertiesUnwrapped,
expression: ".person.name | parent", expression: ".person.name | parent",
expected: "name", expected: expectedDecodedPersonYaml,
scenarioType: "decode", scenarioType: "decode",
}, },
{ {
@ -169,7 +179,7 @@ var propertyScenarios = []formatScenario{
description: "Decode properties - keeps path information", description: "Decode properties - keeps path information",
input: expectedPropertiesUnwrapped, input: expectedPropertiesUnwrapped,
expression: ".person.name | path", expression: ".person.name | path",
expected: "name", expected: "- person\n- name\n",
scenarioType: "decode", scenarioType: "decode",
}, },

View File

@ -107,7 +107,7 @@ var tomlScenarios = []formatScenario{
description: "Parse: include parent information", description: "Parse: include parent information",
input: "person.name = \"hello\"\nperson.address = \"12 cat st\"\n", input: "person.name = \"hello\"\nperson.address = \"12 cat st\"\n",
expression: ".person.name | parent", expression: ".person.name | parent",
expected: "person\n", expected: "name: hello\naddress: 12 cat st\n",
scenarioType: "decode", scenarioType: "decode",
}, },
{ {

View File

@ -523,13 +523,6 @@ var xmlScenarios = []formatScenario{
expectedError: "cannot encode !!seq to XML - only maps can be encoded", expectedError: "cannot encode !!seq to XML - only maps can be encoded",
scenarioType: "encode-error", scenarioType: "encode-error",
}, },
{
description: "scalars cannot be encoded",
skipDoc: true,
input: "mike",
expectedError: "cannot encode !!str to XML - only maps can be encoded",
scenarioType: "encode-error",
},
{ {
description: "Encode xml: attributes with content", description: "Encode xml: attributes with content",
subdescription: "Fields with the matching xml-content-name is assumed to be content.", subdescription: "Fields with the matching xml-content-name is assumed to be content.",