From b026ebf2c3176752d33fc9926da236c1ee64623c Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 17 Oct 2020 22:58:18 +1100 Subject: [PATCH] more refinement --- pkg/yqlib/treeops/data_tree_navigator_test.go | 74 ------------------- pkg/yqlib/treeops/operator_assign_test.go | 18 +++++ pkg/yqlib/treeops/operators_test.go | 2 + 3 files changed, 20 insertions(+), 74 deletions(-) diff --git a/pkg/yqlib/treeops/data_tree_navigator_test.go b/pkg/yqlib/treeops/data_tree_navigator_test.go index e5349a54..01654d70 100644 --- a/pkg/yqlib/treeops/data_tree_navigator_test.go +++ b/pkg/yqlib/treeops/data_tree_navigator_test.go @@ -628,80 +628,6 @@ func TestDataTreeNavigatorArraySimple(t *testing.T) { test.AssertResult(t, expected, resultsToString(results)) } -func TestDataTreeNavigatorSimpleAssignBooleanCmd(t *testing.T) { - - nodes := readDoc(t, `a: - b: apple`) - path, errPath := treeCreator.ParsePath(`.a.b |= true`) - if errPath != nil { - t.Error(errPath) - } - results, errNav := treeNavigator.GetMatchingNodes(nodes, path) - - if errNav != nil { - t.Error(errNav) - } - - expected := ` --- Node -- - Document 0, path: [a b] - Tag: !!bool, Kind: ScalarNode, Anchor: - true -` - - test.AssertResult(t, expected, resultsToString(results)) -} - -func TestDataTreeNavigatorSimpleAssignChildCmd(t *testing.T) { - - nodes := readDoc(t, `a: - b: {g: 3}`) - - path, errPath := treeCreator.ParsePath(`.a |= .b`) - if errPath != nil { - t.Error(errPath) - } - results, errNav := treeNavigator.GetMatchingNodes(nodes, path) - - if errNav != nil { - t.Error(errNav) - } - - expected := ` --- Node -- - Document 0, path: [a] - Tag: !!map, Kind: MappingNode, Anchor: - {g: 3} -` - - test.AssertResult(t, expected, resultsToString(results)) -} - -func TestDataTreeNavigatorSimpleAssignSelf(t *testing.T) { - - nodes := readDoc(t, `a: - b: apple`) - - path, errPath := treeCreator.ParsePath("a(. == apple)(. := frog)") - if errPath != nil { - t.Error(errPath) - } - results, errNav := treeNavigator.GetMatchingNodes(nodes, path) - - if errNav != nil { - t.Error(errNav) - } - - expected := ` --- Node -- - Document 0, path: [a b] - Tag: !!str, Kind: ScalarNode, Anchor: - frog -` - - test.AssertResult(t, expected, resultsToString(results)) -} - func TestDataTreeNavigatorSimpleAssignByFind(t *testing.T) { nodes := readDoc(t, `a: diff --git a/pkg/yqlib/treeops/operator_assign_test.go b/pkg/yqlib/treeops/operator_assign_test.go index 979363a9..e44b1864 100644 --- a/pkg/yqlib/treeops/operator_assign_test.go +++ b/pkg/yqlib/treeops/operator_assign_test.go @@ -29,6 +29,24 @@ var assignOperatorScenarios = []expressionScenario{ expected: []string{ "D0, P[], (!!map)::{a: {b: 3.142}}\n", }, + }, { + document: `{a: {b: {g: foof}}}`, + expression: `.a |= .b`, + expected: []string{ + "D0, P[], (!!map)::{a: {g: foof}}\n", + }, + }, { + document: `{a: {b: apple, c: cactus}}`, + expression: `.a[] | select(. == "apple") |= "frog"`, + expected: []string{ + "D0, P[], (!!map)::{a: {b: frog, c: cactus}}\n", + }, + }, { + document: `[candy, apple, sandy]`, + expression: `.[] | select(. == "*andy") |= "bogs"`, + expected: []string{ + "D0, P[], (!!seq)::[bogs, apple, bogs]\n", + }, // document: `{}`, // expression: `["cat", "dog"]`, // expected: []string{ diff --git a/pkg/yqlib/treeops/operators_test.go b/pkg/yqlib/treeops/operators_test.go index fedd6dd9..434a7a13 100644 --- a/pkg/yqlib/treeops/operators_test.go +++ b/pkg/yqlib/treeops/operators_test.go @@ -18,11 +18,13 @@ func testScenario(t *testing.T, s *expressionScenario) { path, errPath := treeCreator.ParsePath(s.expression) if errPath != nil { t.Error(errPath) + return } results, errNav := treeNavigator.GetMatchingNodes(nodes, path) if errNav != nil { t.Error(errNav) + return } test.AssertResultComplexWithContext(t, s.expected, resultsToString(results), s.expression) }