add tests for root node unwrap bug in previous versions (#1837)

This commit is contained in:
Valentin Lab 2023-10-23 11:03:51 +02:00 committed by GitHub
parent c8f4ba7f45
commit a60d27975a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -72,6 +72,15 @@ EOL
assertEquals "\"cat\"" "$X"
}
testOutputYamlRawOnRoot() {
cat >test.yml <<EOL
'a'
EOL
X=$(./yq e -r '.' test.yml)
assertEquals "a" "$X"
}
testOutputJsonRaw() {
cat >test.yml <<EOL
a: cat

View File

@ -390,3 +390,23 @@ func TestPrinterNulSeparatorWithJson(t *testing.T) {
writer.Flush()
test.AssertResult(t, expected, output.String())
}
func TestPrinterRootUnwrap(t *testing.T) {
var output bytes.Buffer
var writer = bufio.NewWriter(&output)
printer := NewSimpleYamlPrinter(writer, YamlOutputFormat, true, false, 2, false)
node, err := getExpressionParser().ParseExpression(".")
if err != nil {
panic(err)
}
streamEvaluator := NewStreamEvaluator()
_, err = streamEvaluator.Evaluate("sample", strings.NewReader("'a'"), node, printer, NewYamlDecoder(ConfiguredYamlPreferences))
if err != nil {
panic(err)
}
writer.Flush()
expected := `a
`
test.AssertResult(t, expected, output.String())
}