MCPcopy
hub / github.com/hashicorp/hcl / makeTestTree

Function makeTestTree

hclwrite/ast_test.go:18–50  ·  view source on GitHub ↗
(n *node)

Source from the content-addressed store, hash-verified

16}
17
18func makeTestTree(n *node) (root TestTreeNode) {
19 const us = "hclwrite."
20 const usPtr = "*hclwrite."
21 root.Type = fmt.Sprintf("%T", n.content)
22 if strings.HasPrefix(root.Type, us) {
23 root.Type = root.Type[len(us):]
24 } else if strings.HasPrefix(root.Type, usPtr) {
25 root.Type = root.Type[len(usPtr):]
26 }
27
28 type WithVal interface {
29 testValue() string
30 }
31 hasTestVal := false
32 if withVal, ok := n.content.(WithVal); ok {
33 root.Val = withVal.testValue()
34 hasTestVal = true
35 }
36
37 n.content.walkChildNodes(func(n *node) {
38 root.Children = append(root.Children, makeTestTree(n))
39 })
40
41 // If we didn't end up with any children then this is probably a leaf
42 // node, so we'll set its content value to it raw bytes if we didn't
43 // already set a test value.
44 if !hasTestVal && len(root.Children) == 0 {
45 toks := n.content.BuildTokens(nil)
46 root.Val = toks.testValue()
47 }
48
49 return root
50}

Callers 1

TestParseFunction · 0.85

Calls 3

testValueMethod · 0.65
walkChildNodesMethod · 0.65
BuildTokensMethod · 0.65

Tested by

no test coverage detected