mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Fixed ability to grow arrays
This commit is contained in:
		
							parent
							
								
									0facf35d60
								
							
						
					
					
						commit
						909b62be54
					
				| @ -82,6 +82,9 @@ func writeArray(context interface{}, paths []string, value interface{}) []interf | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		die("Error accessing array: %v", err) | 		die("Error accessing array: %v", err) | ||||||
| 	} | 	} | ||||||
|  | 	for index >= int64(len(array)) { | ||||||
|  | 		array = append(array, nil) | ||||||
|  | 	} | ||||||
| 	currentChild := array[index] | 	currentChild := array[index] | ||||||
| 
 | 
 | ||||||
| 	log.Debugf("\tcurrentChild %v\n", currentChild) | 	log.Debugf("\tcurrentChild %v\n", currentChild) | ||||||
|  | |||||||
| @ -205,6 +205,21 @@ b: | |||||||
| 	assertResult(t, "4", readMap(updated, "b", []string{"d", "0"})) | 	assertResult(t, "4", readMap(updated, "b", []string{"d", "0"})) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func TestWrite_add_to_array(t *testing.T) { | ||||||
|  |   var data = parseData(` | ||||||
|  | b: | ||||||
|  |   - aa | ||||||
|  | `) | ||||||
|  | 
 | ||||||
|  |   var expected = `b: | ||||||
|  | - aa | ||||||
|  | - bb` | ||||||
|  | 
 | ||||||
|  |   updated := writeMap(data, []string{"b", "1"}, "bb") | ||||||
|  | 
 | ||||||
|  |   assertResult(t, expected, yamlToString(updated)) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func TestWrite_with_no_tail(t *testing.T) { | func TestWrite_with_no_tail(t *testing.T) { | ||||||
| 	var data = parseData(` | 	var data = parseData(` | ||||||
| b: | b: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user