From 858f6116bf9f7d19fc943bc3c32038a243b1e42d Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Sun, 1 Nov 2015 01:28:11 +0300 Subject: [PATCH] printer: complex.golden is now fixed --- printer/nodes.go | 8 +++----- printer/testdata/complexhcl.golden | 1 + printer/testdata/complexhcl.input | 3 --- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/printer/nodes.go b/printer/nodes.go index a2f72f1..1cf158d 100644 --- a/printer/nodes.go +++ b/printer/nodes.go @@ -33,6 +33,8 @@ func (b ByPosition) Len() int { return len(b) } func (b ByPosition) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func (b ByPosition) Less(i, j int) bool { return b[i].Pos().Before(b[j].Pos()) } +// collectComments comments all standalone comments which are not lead or line +// comment func (p *printer) collectComments(node ast.Node) { // first collect all comments. This is already stored in // ast.File.(comments) @@ -83,25 +85,21 @@ func (p *printer) collectComments(node ast.Node) { sort.Sort(ByPosition(p.standaloneComments)) } -var count int - // output prints creates b printable HCL output and returns it. func (p *printer) output(n interface{}) []byte { var buf bytes.Buffer - count++ switch t := n.(type) { case *ast.File: return p.output(t.Node) case *ast.ObjectList: - var index int var nextItem token.Pos var commented bool for { // TODO(arslan): refactor below comment printing, we have the same in objectType - // print stand alone upper level stand alone comments + // print upper leve stand alone comments for _, c := range p.standaloneComments { for _, comment := range c.List { if index != len(t.Items) { diff --git a/printer/testdata/complexhcl.golden b/printer/testdata/complexhcl.golden index d46e1c1..1e9562e 100644 --- a/printer/testdata/complexhcl.golden +++ b/printer/testdata/complexhcl.golden @@ -35,6 +35,7 @@ resource aws_instance "web" { resource "aws_instance" "db" { security_groups = "${aws_security_group.firewall.*.id}" VPC = "foo" + depends_on = ["aws_instance.web"] } diff --git a/printer/testdata/complexhcl.input b/printer/testdata/complexhcl.input index aa83f90..899f5fc 100644 --- a/printer/testdata/complexhcl.input +++ b/printer/testdata/complexhcl.input @@ -36,9 +36,6 @@ resource "aws_instance" "db" { VPC = "foo" depends_on = ["aws_instance.web"] - - - } output "web_ip" {