mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Fixed delete bug
This commit is contained in:
		
							parent
							
								
									a50e154652
								
							
						
					
					
						commit
						0bb53ec770
					
				| @ -13,8 +13,8 @@ func deleteChildOperator(d *dataTreeNavigator, context Context, expressionNode * | ||||
| 	if err != nil { | ||||
| 		return Context{}, err | ||||
| 	} | ||||
| 
 | ||||
| 	for el := nodesToDelete.MatchingNodes.Front(); el != nil; el = el.Next() { | ||||
| 	//need to iterate backwards to ensure correct indices when deleting multiple | ||||
| 	for el := nodesToDelete.MatchingNodes.Back(); el != nil; el = el.Prev() { | ||||
| 		candidate := el.Value.(*CandidateNode) | ||||
| 
 | ||||
| 		deleteImmediateChildOp := &Operation{ | ||||
|  | ||||
| @ -37,6 +37,22 @@ var deleteOperatorScenarios = []expressionScenario{ | ||||
| 			"D0, P[], (doc)::[1, 3]\n", | ||||
| 		}, | ||||
| 	}, | ||||
| 	{ | ||||
| 		skipDoc:    true, | ||||
| 		document:   `a: [1,2,3]`, | ||||
| 		expression: `del(.a[])`, | ||||
| 		expected: []string{ | ||||
| 			"D0, P[], (doc)::a: []\n", | ||||
| 		}, | ||||
| 	}, | ||||
| 	{ | ||||
| 		skipDoc:    true, | ||||
| 		document:   `a: [10,x,10, 10, x, 10]`, | ||||
| 		expression: `del(.a[] | select(. == 10))`, | ||||
| 		expected: []string{ | ||||
| 			"D0, P[], (doc)::a: [x, x]\n", | ||||
| 		}, | ||||
| 	}, | ||||
| 	{ | ||||
| 		description: "Delete nested entry in array", | ||||
| 		document:    `[{a: cat, b: dog}]`, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user