diff --git a/hclwrite/roundup_test.go b/hclwrite/examples_test.go similarity index 66% rename from hclwrite/roundup_test.go rename to hclwrite/examples_test.go index 31543d1..170572f 100644 --- a/hclwrite/roundup_test.go +++ b/hclwrite/examples_test.go @@ -1,17 +1,13 @@ package hclwrite_test import ( - "bytes" - "strings" - "testing" + "fmt" "github.com/hashicorp/hcl2/hclwrite" "github.com/zclconf/go-cty/cty" ) -// TestRoundupCreate is a test that exercises a number of different codepaths -// to create a file from scratch, like a calling application might. -func TestRoundupCreate(t *testing.T) { +func Example_generateFromScratch() { f := hclwrite.NewEmptyFile() rootBody := f.Body() rootBody.SetAttributeValue("string", cty.StringVal("bar")) // this is overwritten later @@ -39,28 +35,24 @@ func TestRoundupCreate(t *testing.T) { bazBody.SetAttributeValue("beep", cty.StringVal("boop")) bazBody.SetAttributeValue("baz", cty.ListValEmpty(cty.String)) - got := string(bytes.TrimSpace(f.Bytes())) - want := strings.TrimSpace(` -string = "foo" - -object = {bar = 5, baz = true, foo = "foo"} -bool = false - -foo { - hello = "world" -} -empty { -} - -bar "a" "b" { - baz { - foo = 10 - beep = "boop" - baz = [] - } -} -`) - if got != want { - t.Errorf("wrong result\ngot:\n%s\n\nwant:\n%s", got, want) - } + fmt.Printf("%s", f.Bytes()) + // Output: + // string = "foo" + // + // object = {bar = 5, baz = true, foo = "foo"} + // bool = false + // + // foo { + // hello = "world" + // } + // empty { + // } + // + // bar "a" "b" { + // baz { + // foo = 10 + // beep = "boop" + // baz = [] + // } + // } }