mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Fixed has operator for top level node
This commit is contained in:
		
							parent
							
								
									6bb8b1fb77
								
							
						
					
					
						commit
						f7d95021c1
					
				| @ -24,8 +24,9 @@ func hasOperator(d *dataTreeNavigator, matchingNodes *list.List, pathNode *PathT | |||||||
| 		candidate := el.Value.(*CandidateNode) | 		candidate := el.Value.(*CandidateNode) | ||||||
| 
 | 
 | ||||||
| 		// grab the first value | 		// grab the first value | ||||||
| 		var contents = candidate.Node.Content | 		candidateNode := UnwrapDoc(candidate.Node) | ||||||
| 		switch candidate.Node.Kind { | 		var contents = candidateNode.Content | ||||||
|  | 		switch candidateNode.Kind { | ||||||
| 		case yaml.MappingNode: | 		case yaml.MappingNode: | ||||||
| 			candidateHasKey := false | 			candidateHasKey := false | ||||||
| 			for index := 0; index < len(contents) && !candidateHasKey; index = index + 2 { | 			for index := 0; index < len(contents) && !candidateHasKey; index = index + 2 { | ||||||
|  | |||||||
| @ -5,6 +5,14 @@ import ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var hasOperatorScenarios = []expressionScenario{ | var hasOperatorScenarios = []expressionScenario{ | ||||||
|  | 	{ | ||||||
|  | 		skipDoc:    true, | ||||||
|  | 		document:   `a: hello`, | ||||||
|  | 		expression: `has("a")`, | ||||||
|  | 		expected: []string{ | ||||||
|  | 			"D0, P[], (!!bool)::true\n", | ||||||
|  | 		}, | ||||||
|  | 	}, | ||||||
| 	{ | 	{ | ||||||
| 		description: "Has map key", | 		description: "Has map key", | ||||||
| 		document: `- a: "yes" | 		document: `- a: "yes" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user