From 3a165313dbc2b8dc8b502212398709edb267edab Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Wed, 28 Oct 2015 01:07:37 +0300 Subject: [PATCH] printer: improvements on comment aligning --- printer/nodes.go | 8 -------- printer/printer_test.go | 6 +++--- printer/testdata/comment.golden | 2 +- printer/testdata/comment_aligned.golden | 10 ++++------ printer/testdata/comment_aligned.input | 6 +++--- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/printer/nodes.go b/printer/nodes.go index 9e753e2..92a7c4c 100644 --- a/printer/nodes.go +++ b/printer/nodes.go @@ -158,16 +158,9 @@ func (p *printer) objectType(o *ast.ObjectType) []byte { } } - // fmt.Printf("len(oneLines) = %+v\n", len(oneLines)) - // for _, i := range oneLines { - // a := i.Keys[0] - // fmt.Printf("a = %+v\n", a) - // } - if len(oneLines) != 0 { items := p.alignedItems(oneLines) buf.Write(p.indent(items)) - if index != len(o.List.Items) { buf.WriteByte(newline) } @@ -183,7 +176,6 @@ func (p *printer) objectType(o *ast.ObjectType) []byte { } buf.WriteString("}") - buf.WriteByte(newline) return buf.Bytes() } diff --git a/printer/printer_test.go b/printer/printer_test.go index 7e2b132..54c86dd 100644 --- a/printer/printer_test.go +++ b/printer/printer_test.go @@ -24,9 +24,9 @@ type entry struct { // Use go test -update to create/update the respective golden files. var data = []entry{ - // {"complexhcl.input", "complexhcl.golden"}, - // {"list.input", "list.golden"}, - // {"comment.input", "comment.golden"}, + {"complexhcl.input", "complexhcl.golden"}, + {"list.input", "list.golden"}, + {"comment.input", "comment.golden"}, {"comment_aligned.input", "comment_aligned.golden"}, } diff --git a/printer/testdata/comment.golden b/printer/testdata/comment.golden index 1d327f6..65a4e4e 100644 --- a/printer/testdata/comment.golden +++ b/printer/testdata/comment.golden @@ -20,4 +20,4 @@ variable = { // lead comment foo = { bar = "fatih" // line comment 2 -} // line comment 3 +} // line comment 3 \ No newline at end of file diff --git a/printer/testdata/comment_aligned.golden b/printer/testdata/comment_aligned.golden index bab08b0..60347c3 100644 --- a/printer/testdata/comment_aligned.golden +++ b/printer/testdata/comment_aligned.golden @@ -7,12 +7,10 @@ aligned = { deneme = { bar = "fatih" } + bar = "bar" # yoo3 + fatih = ["fatih", "arslan"] // yoo4 - projects = ["vim-go"] # yoo5 - default = "foo" # yoo6 - - example = { + deneme = { bar = "fatih" } - -} +} \ No newline at end of file diff --git a/printer/testdata/comment_aligned.input b/printer/testdata/comment_aligned.input index 1b98b48..87c330a 100644 --- a/printer/testdata/comment_aligned.input +++ b/printer/testdata/comment_aligned.input @@ -6,9 +6,9 @@ aligned { deneme = { bar = "fatih" } - projects = ["vim-go"] # yoo5 - default = "foo" # yoo6 - example = { + bar = "bar" # yoo3 + fatih = ["fatih", "arslan"] // yoo4 + deneme = { bar = "fatih" } }