mirror of
				https://github.com/taigrr/yq
				synced 2025-01-18 04:53:17 -08:00 
			
		
		
		
	Better documentation generation
This commit is contained in:
		
							parent
							
								
									d91b25840a
								
							
						
					
					
						commit
						860655b4cd
					
				| @ -6,18 +6,21 @@ import ( | |||||||
| 
 | 
 | ||||||
| var collectObjectOperatorScenarios = []expressionScenario{ | var collectObjectOperatorScenarios = []expressionScenario{ | ||||||
| 	{ | 	{ | ||||||
| 		document:   ``, | 		description: `Collect empty object`, | ||||||
| 		expression: `{}`, | 		document:    ``, | ||||||
| 		expected:   []string{}, | 		expression:  `{}`, | ||||||
|  | 		expected:    []string{}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
| 		document:   "{name: Mike}\n", | 		description: `Wrap (prefix) existing object`, | ||||||
| 		expression: `{"wrap": .}`, | 		document:    "{name: Mike}\n", | ||||||
|  | 		expression:  `{"wrap": .}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| 			"D0, P[], (!!map)::wrap: {name: Mike}\n", | 			"D0, P[], (!!map)::wrap: {name: Mike}\n", | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
|  | 		skipDoc:    true, | ||||||
| 		document:   "{name: Mike}\n---\n{name: Bob}", | 		document:   "{name: Mike}\n---\n{name: Bob}", | ||||||
| 		expression: `{"wrap": .}`, | 		expression: `{"wrap": .}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| @ -26,6 +29,7 @@ var collectObjectOperatorScenarios = []expressionScenario{ | |||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
|  | 		skipDoc:    true, | ||||||
| 		document:   `{name: Mike, age: 32}`, | 		document:   `{name: Mike, age: 32}`, | ||||||
| 		expression: `{.name: .age}`, | 		expression: `{.name: .age}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| @ -33,24 +37,28 @@ var collectObjectOperatorScenarios = []expressionScenario{ | |||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
| 		document:   `{name: Mike, pets: [cat, dog]}`, | 		description: `Using splat to create multiple objects`, | ||||||
| 		expression: `{.name: .pets[]}`, | 		document:    `{name: Mike, pets: [cat, dog]}`, | ||||||
|  | 		expression:  `{.name: .pets[]}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| 			"D0, P[], (!!map)::Mike: cat\n", | 			"D0, P[], (!!map)::Mike: cat\n", | ||||||
| 			"D0, P[], (!!map)::Mike: dog\n", | 			"D0, P[], (!!map)::Mike: dog\n", | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
| 		document:   "{name: Mike, pets: [cat, dog]}\n---\n{name: Rosey, pets: [monkey, sheep]}", | 		description: `Working with multiple documents`, | ||||||
| 		expression: `{.name: .pets[]}`, | 		document:    "{name: Mike, pets: [cat, dog]}\n---\n{name: Rosey, pets: [monkey, sheep]}", | ||||||
|  | 		expression:  `{.name: .pets[]}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| 			"D0, P[], (!!map)::Mike: cat\n", | 			"D0, P[], (!!map)::Mike: cat\n", | ||||||
| 			"D0, P[], (!!map)::Mike: dog\n", | 			"D0, P[], (!!map)::Mike: dog\n", | ||||||
| 			"D0, P[], (!!map)::Rosey: monkey\n", | 			"D1, P[], (!!map)::Rosey: monkey\n", | ||||||
| 			"D0, P[], (!!map)::Rosey: sheep\n", | 			"D1, P[], (!!map)::Rosey: sheep\n", | ||||||
|  | 			"this is producing incorrect formatted yaml", | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
|  | 		skipDoc:    true, | ||||||
| 		document:   `{name: Mike, pets: [cat, dog], food: [hotdog, burger]}`, | 		document:   `{name: Mike, pets: [cat, dog], food: [hotdog, burger]}`, | ||||||
| 		expression: `{.name: .pets[], "f":.food[]}`, | 		expression: `{.name: .pets[], "f":.food[]}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| @ -61,6 +69,7 @@ var collectObjectOperatorScenarios = []expressionScenario{ | |||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
|  | 		skipDoc:    true, | ||||||
| 		document:   `{name: Mike, pets: {cows: [apl, bba]}}`, | 		document:   `{name: Mike, pets: {cows: [apl, bba]}}`, | ||||||
| 		expression: `{"a":.name, "b":.pets}`, | 		expression: `{"a":.name, "b":.pets}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| @ -70,13 +79,15 @@ b: {cows: [apl, bba]} | |||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
| 		document:   ``, | 		description: "Creating yaml from scratch", | ||||||
| 		expression: `{"wrap": "frog"}`, | 		document:    ``, | ||||||
|  | 		expression:  `{"wrap": "frog"}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| 			"D0, P[], (!!map)::wrap: frog\n", | 			"D0, P[], (!!map)::wrap: frog\n", | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
|  | 		skipDoc:    true, | ||||||
| 		document:   `{name: Mike}`, | 		document:   `{name: Mike}`, | ||||||
| 		expression: `{"wrap": .}`, | 		expression: `{"wrap": .}`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
| @ -84,6 +95,7 @@ b: {cows: [apl, bba]} | |||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
| 	{ | 	{ | ||||||
|  | 		skipDoc:    true, | ||||||
| 		document:   `{name: Mike}`, | 		document:   `{name: Mike}`, | ||||||
| 		expression: `{"wrap": {"further": .}} | (.. style= "flow")`, | 		expression: `{"wrap": {"further": .}} | (.. style= "flow")`, | ||||||
| 		expected: []string{ | 		expected: []string{ | ||||||
|  | |||||||
| @ -103,7 +103,7 @@ func documentScenarios(t *testing.T, title string, scenarios []expressionScenari | |||||||
| 
 | 
 | ||||||
| 	w := bufio.NewWriter(f) | 	w := bufio.NewWriter(f) | ||||||
| 
 | 
 | ||||||
| 	writeOrPanic(w, "## Examples\n") | 	writeOrPanic(w, "\n## Examples\n") | ||||||
| 
 | 
 | ||||||
| 	for index, s := range scenarios { | 	for index, s := range scenarios { | ||||||
| 		if !s.skipDoc { | 		if !s.skipDoc { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user