mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
Handle leading comment with no new-line
This commit is contained in:
parent
8508d3309b
commit
3b91ad5764
@ -8,7 +8,27 @@ EOL
|
|||||||
|
|
||||||
testEmptyEval() {
|
testEmptyEval() {
|
||||||
X=$(./yq e test.yml)
|
X=$(./yq e test.yml)
|
||||||
|
expected=$(cat test.yml)
|
||||||
assertEquals 0 $?
|
assertEquals 0 $?
|
||||||
|
assertEquals "$expected" "$X"
|
||||||
|
}
|
||||||
|
|
||||||
|
testEmptyEvalNoNewLine() {
|
||||||
|
echo -n "#comment" >test.yml
|
||||||
|
X=$(./yq e test.yml)
|
||||||
|
expected=$(cat test.yml)
|
||||||
|
assertEquals 0 $?
|
||||||
|
assertEquals "$expected" "$X"
|
||||||
|
}
|
||||||
|
|
||||||
|
testEmptyEvalNoNewLineWithExpression() {
|
||||||
|
echo -n "# comment" >test.yml
|
||||||
|
X=$(./yq e '.apple = "tree"' test.yml)
|
||||||
|
read -r -d '' expected << EOM
|
||||||
|
# comment
|
||||||
|
apple: tree
|
||||||
|
EOM
|
||||||
|
assertEquals "$expected" "$X"
|
||||||
}
|
}
|
||||||
|
|
||||||
testEmptyEvalPipe() {
|
testEmptyEvalPipe() {
|
||||||
|
@ -147,6 +147,12 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if errReading == io.EOF {
|
if errReading == io.EOF {
|
||||||
|
if readline != "" {
|
||||||
|
// the last comment we read didn't have a new line, put one in
|
||||||
|
if err := p.writeString(bufferedWriter, "\n"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user