mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 22:35:37 +00:00
Fix tests
This commit is contained in:
parent
f3d302b390
commit
67572e3027
@ -60,6 +60,15 @@ var anchorOperatorScenarios = []expressionScenario{
|
||||
document: "a: &a\n - 0\nc:\n <<: [*a]\n",
|
||||
expectedError: "merge anchor only supports maps, got !!seq instead",
|
||||
expression: "explode(.)",
|
||||
skipForGoccy: true, // goccy yaml parser throws a different error
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
description: "merge anchor not map",
|
||||
document: "a: &a\n - 0\nc:\n <<: [*a]\n",
|
||||
expectedError: "merge anchor only supports maps, got !!seq instead a: &a",
|
||||
expression: "explode(.)",
|
||||
skipForYamlV3: true, // yaml.v3 parser throws a different error
|
||||
},
|
||||
{
|
||||
description: "Merge one map",
|
||||
@ -275,6 +284,15 @@ var anchorOperatorScenarios = []expressionScenario{
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::{f: {a: cat, b: {foo: cat}, cat: {foo: cat}}}\n",
|
||||
},
|
||||
skipForGoccy: true, // can't handle no space between alias
|
||||
},
|
||||
{
|
||||
skipDoc: true,
|
||||
document: `{f : {a: &a cat, b: &b {foo: *a}, *a : *b}}`,
|
||||
expression: `explode(.f)`,
|
||||
expected: []string{
|
||||
"D0, P[], (!!map)::{f: {a: cat, b: {foo: cat}, cat: {foo: cat}}}\n",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "Dereference and update a field",
|
||||
|
||||
@ -30,10 +30,9 @@ type expressionScenario struct {
|
||||
dontFormatInputForDoc bool // dont format input doc for documentation generation
|
||||
requiresFormat string
|
||||
skipForGoccy bool
|
||||
skipForYamlV3 bool
|
||||
}
|
||||
|
||||
var goccyTesting = false
|
||||
|
||||
var testingDecoder = NewYamlDecoder(ConfiguredYamlPreferences)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@ -44,23 +43,19 @@ func TestMain(m *testing.M) {
|
||||
ConfiguredYamlPreferences.ColorsEnabled = false
|
||||
ConfiguredJSONPreferences.ColorsEnabled = false
|
||||
|
||||
goccyTesting = os.Getenv("GOCCY") == "true"
|
||||
|
||||
if goccyTesting {
|
||||
testingDecoder = NewGoccyYAMLDecoder(ConfiguredYamlPreferences)
|
||||
}
|
||||
|
||||
Now = func() time.Time {
|
||||
return time.Date(2021, time.May, 19, 1, 2, 3, 4, time.UTC)
|
||||
}
|
||||
|
||||
ConfiguredYamlPreferences.UseGoccyParser = false
|
||||
testingDecoder = NewGoccyYAMLDecoder(ConfiguredYamlPreferences)
|
||||
ConfiguredYamlPreferences.UseGoccyParser = true
|
||||
exitCode := m.Run()
|
||||
if exitCode != 0 {
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
|
||||
ConfiguredYamlPreferences.UseGoccyParser = true
|
||||
testingDecoder = NewYamlDecoder(ConfiguredYamlPreferences)
|
||||
ConfiguredYamlPreferences.UseGoccyParser = false
|
||||
exitCode = m.Run()
|
||||
|
||||
os.Exit(exitCode)
|
||||
@ -82,8 +77,16 @@ func readDocument(content string, fakefilename string, fakeFileIndex int) (*list
|
||||
|
||||
func testScenario(t *testing.T, s *expressionScenario) {
|
||||
if s.skipForGoccy {
|
||||
return
|
||||
if ConfiguredYamlPreferences.UseGoccyParser {
|
||||
t.Skipf("skipping scenario %v for yaml v3 parser", s.description)
|
||||
}
|
||||
}
|
||||
if s.skipForYamlV3 {
|
||||
if !ConfiguredYamlPreferences.UseGoccyParser {
|
||||
t.Skipf("skipping scenario %v for yaml v3 parser", s.description)
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
node, err := getExpressionParser().ParseExpression(s.expression)
|
||||
if err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user