Fixed merge comment issue #919

This commit is contained in:
Mike Farah 2021-08-26 16:31:26 +10:00
parent 063d40de25
commit cb95ab1494
4 changed files with 36 additions and 12 deletions

View File

@ -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
---

View File

@ -1,4 +1,3 @@
a: simple # just the best
b: [1, 2]
c:
test: 1
# a1
a: 1
# a2

View File

@ -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

View File

@ -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
}