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))
|
||||
|
||||
}
|
||||
|
||||
// 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) {
|
||||
case *ast.File:
|
||||
// File doesn't trace so we add the tracing here
|
||||
defer un(trace(p, "File"))
|
||||
return p.output(t.Node)
|
||||
case *ast.ObjectList:
|
||||
defer un(trace(p, "ObjectList"))
|
||||
|
||||
var index int
|
||||
var nextItem token.Pos
|
||||
var commented bool
|
||||
for {
|
||||
// TODO(arslan): refactor below comment printing, we have the same in objectType
|
||||
for _, c := range p.standaloneComments {
|
||||
@ -140,7 +142,7 @@ func (p *printer) output(n interface{}) []byte {
|
||||
}
|
||||
|
||||
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})
|
||||
}
|
||||
index++
|
||||
|
@ -42,7 +42,9 @@ func TestFiles(t *testing.T) {
|
||||
for _, e := range data {
|
||||
source := filepath.Join(dataDir, e.source)
|
||||
golden := filepath.Join(dataDir, e.golden)
|
||||
check(t, source, golden)
|
||||
t.Run(e.source, func(t *testing.T) {
|
||||
check(t, source, golden)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user