Minor fixes

This commit is contained in:
Mike Farah 2020-11-19 22:11:26 +11:00
parent 75044e480c
commit 9bd9468526
5 changed files with 50 additions and 9 deletions

View File

@ -48,3 +48,19 @@ a: cat
b: dog
```
### Delete matching entries
Given a sample.yml file of:
```yaml
a: cat
b: dog
c: bat
```
then
```bash
yq eval 'del( .[] | select(. == "*at") )' sample.yml
```
will output
```yaml
b: dog
```

View File

@ -37,7 +37,10 @@ func TestJsonEncoderPreservesObjectOrder(t *testing.T) {
panic(err)
}
node := inputs.Front().Value.(*CandidateNode).Node
jsonEncoder.Encode(node)
err = jsonEncoder.Encode(node)
if err != nil {
panic(err)
}
writer.Flush()
test.AssertResult(t, expectedJson, output.String())

View File

@ -68,10 +68,7 @@ var Empty = &OperationType{Type: "EMPTY", NumArgs: 50, Handler: EmptyOperator}
var RecursiveDescent = &OperationType{Type: "RECURSIVE_DESCENT", NumArgs: 0, Precedence: 50, Handler: RecursiveDescentOperator}
// not sure yet
var Select = &OperationType{Type: "SELECT", NumArgs: 1, Precedence: 50, Handler: SelectOperator}
var DeleteChild = &OperationType{Type: "DELETE", NumArgs: 1, Precedence: 40, Handler: DeleteChildOperator}
// var Exists = &OperationType{Type: "Length", NumArgs: 2, Precedence: 35}

View File

@ -29,6 +29,14 @@ var deleteOperatorScenarios = []expressionScenario{
"D0, P[], (doc)::{a: cat, b: dog}\n",
},
},
{
description: "Delete matching entries",
document: `{a: cat, b: dog, c: bat}`,
expression: `del( .[] | select(. == "*at") )`,
expected: []string{
"D0, P[], (doc)::{b: dog}\n",
},
},
}
func TestDeleteOperatorScenarios(t *testing.T) {

View File

@ -35,9 +35,20 @@ func TestPrinterMultipleDocsInSequence(t *testing.T) {
el = el.Next()
sample3 := nodeToMap(el.Value.(*CandidateNode))
printer.PrintResults(sample1)
printer.PrintResults(sample2)
printer.PrintResults(sample3)
err = printer.PrintResults(sample1)
if err != nil {
panic(err)
}
err = printer.PrintResults(sample2)
if err != nil {
panic(err)
}
err = printer.PrintResults(sample3)
if err != nil {
panic(err)
}
writer.Flush()
test.AssertResult(t, multiDocSample, output.String())
@ -54,7 +65,10 @@ func TestPrinterMultipleDocsInSinglePrint(t *testing.T) {
panic(err)
}
printer.PrintResults(inputs)
err = printer.PrintResults(inputs)
if err != nil {
panic(err)
}
writer.Flush()
test.AssertResult(t, multiDocSample, output.String())
@ -70,7 +84,10 @@ func TestPrinterMultipleDocsJson(t *testing.T) {
panic(err)
}
printer.PrintResults(inputs)
err = printer.PrintResults(inputs)
if err != nil {
panic(err)
}
expected := `{"a":"banana"}
{"a":"apple"}