diff --git a/pkg/yqlib/operator_anchors_aliases_test.go b/pkg/yqlib/operator_anchors_aliases_test.go index a24f3fdd..743e8179 100644 --- a/pkg/yqlib/operator_anchors_aliases_test.go +++ b/pkg/yqlib/operator_anchors_aliases_test.go @@ -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", diff --git a/pkg/yqlib/operators_test.go b/pkg/yqlib/operators_test.go index ff557ac2..3aa69fda 100644 --- a/pkg/yqlib/operators_test.go +++ b/pkg/yqlib/operators_test.go @@ -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 {