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" 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() { testLeadingSeperatorMultiDocEvalCommentsStripComments() {
cat >test.yml <<EOL cat >test.yml <<EOL
--- ---

View File

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

View File

@ -1,7 +1,3 @@
a: other # better than the original #b1
b: [3, 4] b: 2
c: #b2
toast: leave
test: 1
tell: 1
tasty.taco: cool

View File

@ -52,7 +52,7 @@ func (e *allAtOnceEvaluator) EvaluateFiles(expression string, filenames []string
var allDocuments *list.List = list.New() var allDocuments *list.List = list.New()
for _, filename := range filenames { for _, filename := range filenames {
reader, leadingContent, err := readStream(filename, leadingContentPreProcessing) reader, leadingContent, err := readStream(filename, fileIndex == 0 && leadingContentPreProcessing)
if err != nil { if err != nil {
return err return err
} }