mirror of
https://github.com/mikefarah/yq.git
synced 2026-08-24 08:22:13 +08:00
Added "debug-node-info" flag for inspecting yq AST
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package yqlib
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"container/list"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mikefarah/yq/v4/test"
|
||||
)
|
||||
|
||||
func TestNodeInfoPrinter_PrintResults(t *testing.T) {
|
||||
// Create a simple CandidateNode
|
||||
node := &CandidateNode{
|
||||
Kind: ScalarNode,
|
||||
Style: DoubleQuotedStyle,
|
||||
Tag: "!!str",
|
||||
Value: "hello world",
|
||||
Line: 5,
|
||||
Column: 7,
|
||||
HeadComment: "head",
|
||||
LineComment: "line",
|
||||
FootComment: "foot",
|
||||
Anchor: "anchor",
|
||||
}
|
||||
listNodes := list.New()
|
||||
listNodes.PushBack(node)
|
||||
|
||||
var output bytes.Buffer
|
||||
writer := bufio.NewWriter(&output)
|
||||
printer := NewNodeInfoPrinter(NewSinglePrinterWriter(writer))
|
||||
err := printer.PrintResults(listNodes)
|
||||
writer.Flush()
|
||||
if err != nil {
|
||||
t.Fatalf("PrintResults error: %v", err)
|
||||
}
|
||||
|
||||
outStr := output.String()
|
||||
// Check for key NodeInfo fields in YAML output using substring checks
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "kind: ScalarNode"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "style: DoubleQuotedStyle"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "tag: '!!str'"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "value: hello world"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "line: 5"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "column: 7"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "headComment: head"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "lineComment: line"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "footComment: foot"))
|
||||
test.AssertResult(t, true, strings.Contains(outStr, "anchor: anchor"))
|
||||
}
|
||||
Reference in New Issue
Block a user