mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Unit tests pass!
This commit is contained in:
parent
b2415f2ca5
commit
584ec998bc
@ -83,7 +83,6 @@ yq -o=props '... comments = ""' sample.yml
|
||||
```
|
||||
will output
|
||||
```properties
|
||||
# block comments come through
|
||||
person.name = Mike Wazowski
|
||||
person.pets.0 = cat
|
||||
person.food.0 = pizza
|
||||
|
@ -93,7 +93,7 @@ func (e *xmlEncoder) Encode(writer io.Writer, node *CandidateNode) error {
|
||||
}
|
||||
return encoder.Flush()
|
||||
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)
|
||||
|
@ -11,7 +11,7 @@ var uniqueOperatorScenarios = []expressionScenario{
|
||||
document: `[2,1,3,2]`,
|
||||
expression: `unique`,
|
||||
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]`,
|
||||
expression: `unique`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!seq)::- ~\n- null\n",
|
||||
"D0, P[], (!!seq)::[~, null]\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -29,7 +29,7 @@ var uniqueOperatorScenarios = []expressionScenario{
|
||||
document: `[~,null, ~, null]`,
|
||||
expression: `unique_by(tag)`,
|
||||
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}]`,
|
||||
expression: `unique_by(.name)`,
|
||||
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}]`,
|
||||
expression: `unique_by(.name)`,
|
||||
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}]`,
|
||||
expression: `unique_by(.cat.dog)`,
|
||||
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",
|
||||
expression: `unique_by(.name)`,
|
||||
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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -98,6 +98,16 @@ const expectedDecodedYaml = `person:
|
||||
- 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
|
||||
person.pets.0 = cat
|
||||
person.food.0 = pizza
|
||||
@ -153,7 +163,7 @@ var propertyScenarios = []formatScenario{
|
||||
description: "Decode properties - keeps key information",
|
||||
input: expectedPropertiesUnwrapped,
|
||||
expression: ".person.name | key",
|
||||
expected: "name",
|
||||
expected: "name\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
@ -161,7 +171,7 @@ var propertyScenarios = []formatScenario{
|
||||
description: "Decode properties - keeps parent information",
|
||||
input: expectedPropertiesUnwrapped,
|
||||
expression: ".person.name | parent",
|
||||
expected: "name",
|
||||
expected: expectedDecodedPersonYaml,
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
@ -169,7 +179,7 @@ var propertyScenarios = []formatScenario{
|
||||
description: "Decode properties - keeps path information",
|
||||
input: expectedPropertiesUnwrapped,
|
||||
expression: ".person.name | path",
|
||||
expected: "name",
|
||||
expected: "- person\n- name\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
|
||||
|
@ -107,7 +107,7 @@ var tomlScenarios = []formatScenario{
|
||||
description: "Parse: include parent information",
|
||||
input: "person.name = \"hello\"\nperson.address = \"12 cat st\"\n",
|
||||
expression: ".person.name | parent",
|
||||
expected: "person\n",
|
||||
expected: "name: hello\naddress: 12 cat st\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
|
@ -523,13 +523,6 @@ var xmlScenarios = []formatScenario{
|
||||
expectedError: "cannot encode !!seq to XML - only maps can be encoded",
|
||||
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",
|
||||
subdescription: "Fields with the matching xml-content-name is assumed to be content.",
|
||||
|
Loading…
Reference in New Issue
Block a user