mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Minor fixes
This commit is contained in:
		
							parent
							
								
									75044e480c
								
							
						
					
					
						commit
						9bd9468526
					
				| @ -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 | ||||
| ``` | ||||
| 
 | ||||
|  | ||||
| @ -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()) | ||||
| 
 | ||||
|  | ||||
| @ -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} | ||||
|  | ||||
| @ -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) { | ||||
|  | ||||
| @ -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"} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user