MCPcopy
hub / github.com/hashicorp/hcl / TestRoundTripVerbatim

Function TestRoundTripVerbatim

hclwrite/round_trip_test.go:19–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestRoundTripVerbatim(t *testing.T) {
20 tests := []string{
21 ``,
22 `foo = 1
23`,
24 `
25foobar = 1
26baz = 1
27`,
28 `
29# this file is awesome
30
31# tossed salads and scrambled eggs
32foobar = 1
33baz = 1
34
35block {
36 a = "a"
37 b = "b"
38 c = "c"
39 d = "d"
40
41 subblock {
42 }
43
44 subblock {
45 e = "e"
46 }
47}
48
49# and they all lived happily ever after
50`,
51 }
52
53 for _, test := range tests {
54 t.Run(test, func(t *testing.T) {
55 src := []byte(test)
56 file, diags := parse(src, "", hcl.Pos{Line: 1, Column: 1})
57 if len(diags) != 0 {
58 for _, diag := range diags {
59 t.Logf(" - %s", diag.Error())
60 }
61 t.Fatalf("unexpected diagnostics")
62 }
63
64 wr := &bytes.Buffer{}
65 n, err := file.WriteTo(wr)
66 if n != int64(len(test)) {
67 t.Errorf("wrong number of bytes %d; want %d", n, len(test))
68 }
69 if err != nil {
70 t.Fatalf("error from WriteTo")
71 }
72
73 result := wr.Bytes()
74 if !bytes.Equal(result, src) {
75 t.Errorf("wrong result\ndiff:\n%s", cmp.Diff(string(src), string(result)))
76 }

Callers

nothing calls this directly

Calls 6

parseFunction · 0.85
RunMethod · 0.80
EqualMethod · 0.80
ErrorMethod · 0.45
WriteToMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected