Closed pelletier closed 1 year ago
@Felixoid merged a patch for this. It should now indent array tables as you expect. Feel free to reopen and let me know if it doesn't work for you!
Thanks, it works.
But do you think it's an error or a new design? Looks strange to me, and feels like the comment # custom config
should be aligned with [[
> git diff
diff --git a/marshaler_test.go b/marshaler_test.go
index b4b8e28..514c885 100644
--- a/marshaler_test.go
+++ b/marshaler_test.go
@@ -1208,7 +1208,7 @@ func TestMarhsalIssue888(t *testing.T) {
}
type Cfg struct {
- Custom []Thing
+ Custom []Thing `comment:"custom config"`
}
buf := new(bytes.Buffer)
@@ -1223,7 +1223,8 @@ func TestMarhsalIssue888(t *testing.T) {
encoder := toml.NewEncoder(buf).SetIndentTables(true)
encoder.Encode(config)
- expected := `[[Custom]]
+ expected := `# custom config
+[[Custom]]
# my field A
FieldA = 'field a 1'
# my field B
> go test ./marshaler_test.go -test.run TestMarhsalIssue888
--- FAIL: TestMarhsalIssue888 (0.00s)
marshaler_test.go:1240:
Error Trace: /home/felixoid/Space/Felixoid/github/pelletier/go-toml/marshaler_test.go:1240
Error: Not equal:
expected: "# custom config\n[[Custom]]\n # my field A\n FieldA = 'field a 1'\n # my field B\n FieldB = 'field b 1'\n\n[[Custom]]\n # my field A\n FieldA = 'field a 2'\n # my field B\n FieldB = 'field b 2'\n"
actual : " # custom config\n[[Custom]]\n # my field A\n FieldA = 'field a 1'\n # my field B\n FieldB = 'field b 1'\n\n[[Custom]]\n # my field A\n FieldA = 'field a 2'\n # my field B\n FieldB = 'field b 2'\n"
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,2 @@
-# custom config
+ # custom config
[[Custom]]
Test: TestMarhsalIssue888
FAIL
The code is in https://github.com/pelletier/go-toml/commit/61d5d1127c793eb49113bb89ea0eff50077a8319
You're right it seems wrong. I think the comment decorating the array table should be aligned with it.
Looks like an easy fix, https://github.com/pelletier/go-toml/pull/892
Describe the bug
Follow up from https://github.com/pelletier/go-toml/issues/786. In https://go.dev/play/p/i30ktekXzYD, array tables are not indented even though the option has been enabled.
To Reproduce Steps to reproduce the behavior. Including TOML files.
https://go.dev/play/p/EjEVbGp7xKD
Expected behavior
Output should be:
Versions