Skip to content

Commit

Permalink
Fixed merge comment issue #919
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Aug 26, 2021
1 parent 063d40d commit cb95ab1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
29 changes: 29 additions & 0 deletions acceptance_tests/leading-seperator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,35 @@ EOM
assertEquals "$expected" "$X"
}

# https://github.com/mikefarah/yq/issues/919
testLeadingSeparatorDoesNotBreakCommentsOnOtherFiles() {
cat >test.yml <<EOL
# a1
a: 1
# a2
EOL

cat >test2.yml <<EOL
# b1
b: 2
# b2
EOL

read -r -d '' expected << EOM
# a1
a: 1
# a2
# b1
b: 2
# b2
EOM


X=$(./yq ea 'select(fi == 0) * select(fi == 1)' test.yml test2.yml)
assertEquals "$expected" "$X"
}

testLeadingSeperatorMultiDocEvalCommentsStripComments() {
cat >test.yml <<EOL
---
Expand Down
7 changes: 3 additions & 4 deletions examples/data1.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
a: simple # just the best
b: [1, 2]
c:
test: 1
# a1
a: 1
# a2
10 changes: 3 additions & 7 deletions examples/data2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
a: other # better than the original
b: [3, 4]
c:
toast: leave
test: 1
tell: 1
tasty.taco: cool
#b1
b: 2
#b2
2 changes: 1 addition & 1 deletion pkg/yqlib/all_at_once_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (e *allAtOnceEvaluator) EvaluateFiles(expression string, filenames []string

var allDocuments *list.List = list.New()
for _, filename := range filenames {
reader, leadingContent, err := readStream(filename, leadingContentPreProcessing)
reader, leadingContent, err := readStream(filename, fileIndex == 0 && leadingContentPreProcessing)
if err != nil {
return err
}
Expand Down

0 comments on commit cb95ab1

Please sign in to comment.