hcl/printer: clean up some files, add subtests to testing printer
This commit is contained in:
parent
ef8133da8c
commit
3c8ec494b1
@ -95,7 +95,6 @@ func (p *printer) collectComments(node ast.Node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(ByPosition(p.standaloneComments))
|
sort.Sort(ByPosition(p.standaloneComments))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// output prints creates b printable HCL output and returns it.
|
// output prints creates b printable HCL output and returns it.
|
||||||
@ -104,11 +103,14 @@ func (p *printer) output(n interface{}) []byte {
|
|||||||
|
|
||||||
switch t := n.(type) {
|
switch t := n.(type) {
|
||||||
case *ast.File:
|
case *ast.File:
|
||||||
|
// File doesn't trace so we add the tracing here
|
||||||
|
defer un(trace(p, "File"))
|
||||||
return p.output(t.Node)
|
return p.output(t.Node)
|
||||||
case *ast.ObjectList:
|
case *ast.ObjectList:
|
||||||
|
defer un(trace(p, "ObjectList"))
|
||||||
|
|
||||||
var index int
|
var index int
|
||||||
var nextItem token.Pos
|
var nextItem token.Pos
|
||||||
var commented bool
|
|
||||||
for {
|
for {
|
||||||
// TODO(arslan): refactor below comment printing, we have the same in objectType
|
// TODO(arslan): refactor below comment printing, we have the same in objectType
|
||||||
for _, c := range p.standaloneComments {
|
for _, c := range p.standaloneComments {
|
||||||
@ -140,7 +142,7 @@ func (p *printer) output(n interface{}) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf.Write(p.output(t.Items[index]))
|
buf.Write(p.output(t.Items[index]))
|
||||||
if !commented && index != len(t.Items)-1 {
|
if index != len(t.Items)-1 {
|
||||||
buf.Write([]byte{newline, newline})
|
buf.Write([]byte{newline, newline})
|
||||||
}
|
}
|
||||||
index++
|
index++
|
||||||
|
@ -42,7 +42,9 @@ func TestFiles(t *testing.T) {
|
|||||||
for _, e := range data {
|
for _, e := range data {
|
||||||
source := filepath.Join(dataDir, e.source)
|
source := filepath.Join(dataDir, e.source)
|
||||||
golden := filepath.Join(dataDir, e.golden)
|
golden := filepath.Join(dataDir, e.golden)
|
||||||
check(t, source, golden)
|
t.Run(e.source, func(t *testing.T) {
|
||||||
|
check(t, source, golden)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user