diff --git a/.gitignore b/.gitignore index fac7e030..00b1ab74 100644 --- a/.gitignore +++ b/.gitignore @@ -38,8 +38,12 @@ parts/ prime/ .snapcraft/ yq*.snap + test.yml -test2.yml +test*.yml +0.yml +1.yml +2.yml # man page diff --git a/acceptance_tests/basic.sh b/acceptance_tests/basic.sh index f83f9085..dc9069ae 100755 --- a/acceptance_tests/basic.sh +++ b/acceptance_tests/basic.sh @@ -1,7 +1,7 @@ #!/bin/bash setUp() { - rm -f test.yml + rm test*.yml || true } testBasicEvalRoundTrip() { diff --git a/acceptance_tests/empty.sh b/acceptance_tests/empty.sh index d7f344df..7ffb813f 100755 --- a/acceptance_tests/empty.sh +++ b/acceptance_tests/empty.sh @@ -1,6 +1,7 @@ #!/bin/bash setUp() { + rm test*.yml || true cat >test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test.yml <test2.yml < 0 { - name = result.MatchingNodes.Front().Value.(*CandidateNode).Node.Value - } + indexVariableNode := yaml.Node{Kind: yaml.ScalarNode, Tag: "!!int", Value: fmt.Sprintf("%v", sp.index)} + indexVariableCandidate := CandidateNode{Node: &indexVariableNode} + + context := Context{MatchingNodes: node.AsList()} + context.SetVariable("index", indexVariableCandidate.AsList()) + result, err := sp.treeNavigator.GetMatchingNodes(context, sp.nameExpression) + if err != nil { + return nil, err } - if name == "" { - name = fmt.Sprintf("%v.%v", index, sp.extension) - } else { - name = fmt.Sprintf("%v.%v", name, sp.extension) + if result.MatchingNodes.Len() > 0 { + name = result.MatchingNodes.Front().Value.(*CandidateNode).Node.Value } + name = fmt.Sprintf("%v.%v", name, sp.extension) f, err := os.Create(name) if err != nil { return nil, err } + sp.index = sp.index + 1 return bufio.NewWriter(f), nil