package hclwrite import ( "fmt" "testing" "reflect" "github.com/davecgh/go-spew/spew" "github.com/hashicorp/hcl2/hcl/hclsyntax" ) func TestFormat(t *testing.T) { tests := []struct { input string want string }{ { ``, ``, }, { `a=1`, `a = 1`, }, { `a=b.c`, `a = b.c`, }, { `a=b[c]`, `a = b[c]`, }, { `a=b()[c]`, `a = b()[c]`, }, { `a=["hello"][0]`, `a = ["hello"][0]`, }, { `( a+2 )`, `(a + 2)`, }, { `( a*2 )`, `(a * 2)`, }, { `( a+-2 )`, `(a + -2)`, }, { `( a*-2 )`, `(a * -2)`, }, { `(-2+1)`, `(-2 + 1)`, }, { `foo(1, -2,a*b, b,c)`, `foo(1, -2, a * b, b, c)`, }, { `foo(a,b...)`, `foo(a, b...)`, }, { `a="hello ${ name }"`, `a = "hello ${name}"`, }, { `a="hello ${~ name ~}"`, `a = "hello ${~name~}"`, }, { `a="${b}${c}${ d } ${e}"`, `a = "${b}${c}${d} ${e}"`, }, { `"%{if true}${var.foo}%{endif}"`, `"%{if true}${var.foo}%{endif}"`, }, { `b{}`, `b {}`, }, { ` "${ hello }" `, ` "${ hello }" `, }, { ` foo( 1, - 2, a*b, b, c, ) `, ` foo( 1, -2, a * b, b, c, ) `, }, { `a?b:c`, `a ? b : c`, }, { `[ [ ] ]`, `[[]]`, }, { `[for x in y : x]`, `[for x in y : x]`, }, { `[for x in [y] : x]`, `[for x in [y] : x]`, }, { ` [ [ a ] ] `, ` [ [ a ] ] `, }, { ` [[ a ]] `, ` [[ a ]] `, }, { ` [[ [ a ] ]] `, ` [[ [ a ] ]] `, }, { // degenerate case with asymmetrical brackets ` [[ [ a ]] ] `, ` [[ [ a ]] ] `, }, { ` b { a = 1 } `, ` b { a = 1 } `, }, { ` b {a = 1} `, ` b { a = 1 } `, }, { ` a = 1 bungle = 2 `, ` a = 1 bungle = 2 `, }, { ` a = 1 bungle = 2 `, ` a = 1 bungle = 2 `, }, { ` a = 1 # foo bungle = 2 `, ` a = 1 # foo bungle = 2 `, }, { ` a = 1 # foo bungle = "bonce" # baz `, ` a = 1 # foo bungle = "bonce" # baz `, }, { ` # here we go a = 1 # foo bungle = "bonce" # baz `, ` # here we go a = 1 # foo bungle = "bonce" # baz `, }, { ` foo {} # here we go a = 1 # foo bungle = "bonce" # baz `, ` foo {} # here we go a = 1 # foo bungle = "bonce" # baz `, }, { ` a = 1 # foo bungle = "bonce" # baz zebra = "striped" # baz `, ` a = 1 # foo bungle = "bonce" # baz zebra = "striped" # baz `, }, { ` a = 1 # foo bungle = ( "bonce" ) # baz zebra = "striped" # baz `, ` a = 1 # foo bungle = ( "bonce" ) # baz zebra = "striped" # baz `, }, { ` a="apple"# foo bungle=(# woo parens "bonce" )# baz zebra="striped"# baz `, ` a = "apple" # foo bungle = ( # woo parens "bonce" ) # baz zebra = "striped" # baz `, }, { ` 𝒜 = 1 # foo bungle = "🇬🇧" # baz zebra = "striped" # baz `, ` 𝒜 = 1 # foo bungle = "🇬🇧" # baz zebra = "striped" # baz `, }, { ` foo { # ... } `, ` foo { # ... } `, }, { ` foo = { # ... } `, ` foo = { # ... } `, }, { ` foo = [ # ... ] `, ` foo = [ # ... ] `, }, { ` foo = [{ # ... }] `, ` foo = [{ # ... }] `, }, { ` foo { bar { # ... } } `, ` foo { bar { # ... } } `, }, { ` foo { bar = { # ... } } `, ` foo { bar = { # ... } } `, }, { ` foo { bar = [ # ... ] } `, ` foo { bar = [ # ... ] } `, }, { ` foo { bar = <