diff options
| author | Austin Burdine <aburdine@redventures.com> | 2019-01-16 05:33:06 -0500 |
|---|---|---|
| committer | Martin Atkins <mart@degeneration.co.uk> | 2019-01-16 12:05:48 -0800 |
| commit | 7b147fbae47a39a84792258ad4017a940a752d46 (patch) | |
| tree | 5e86f7494e3a1127ccc5d16c990271a015e34641 | |
| parent | 40e962e08e80f350603feac3ca64495a2fbfaa79 (diff) | |
hclwrite: fix space being added between interpolated items
closes #65
- add missing edge case for two interpolated items next to each other
- add tests for both quote and heredoc cases
| -rw-r--r-- | hclwrite/format.go | 4 | ||||
| -rw-r--r-- | hclwrite/format_test.go | 20 |
2 files changed, 24 insertions, 0 deletions
diff --git a/hclwrite/format.go b/hclwrite/format.go index ef50e09..eed0694 100644 --- a/hclwrite/format.go +++ b/hclwrite/format.go @@ -325,6 +325,10 @@ func spaceAfterToken(subject, before, after *Token) bool { case subject.Type == hclsyntax.TokenCBrace && after.Type == hclsyntax.TokenTemplateSeqEnd: return true + // Don't add spaces between interpolated items + case subject.Type == hclsyntax.TokenTemplateSeqEnd && after.Type == hclsyntax.TokenTemplateInterp: + return false + case tokenBracketChange(subject) > 0: // No spaces after open brackets return false diff --git a/hclwrite/format_test.go b/hclwrite/format_test.go index b4783c2..c07be97 100644 --- a/hclwrite/format_test.go +++ b/hclwrite/format_test.go @@ -72,6 +72,10 @@ func TestFormat(t *testing.T) { `a = "hello ${~name~}"`, }, { + `a="${b}${c}${ d } ${e}"`, + `a = "${b}${c}${d} ${e}"`, + }, + { `b{}`, `b {}`, }, @@ -502,6 +506,22 @@ EOT } `, }, + { + ` +foo { + bar = <<-EOT + ${a}${b}${ c } ${d} +EOT +} +`, + ` +foo { + bar = <<-EOT + ${a}${b}${c} ${d} +EOT +} +`, + }, } for i, test := range tests { |
