Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c893dbf25c | |||
| 2a1df71375 | |||
| a2f5197638 | |||
| bb65137dc4 | |||
| 99782c87cf |
@@ -1,9 +1,18 @@
|
|||||||
---
|
---
|
||||||
name: Bug report
|
name: Bug report
|
||||||
about: Create a report to help us improve
|
about: Create a report to help us improve
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<!--
|
||||||
|
‼️ Main development focus is on the upcoming go-toml v2 ⚠️
|
||||||
|
|
||||||
|
As a result, v1.x bugs will likely not see a fix on a v1.x version.
|
||||||
|
However, reporting the bug is the best way to ensure that it will be fixed in v2.
|
||||||
|
|
||||||
|
See https://github.com/pelletier/go-toml/discussions/506.
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
**Describe the bug**
|
**Describe the bug**
|
||||||
A clear and concise description of what the bug is.
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
@@ -14,7 +23,7 @@ Steps to reproduce the behavior. Including TOML files.
|
|||||||
A clear and concise description of what you expected to happen, if other than "should work".
|
A clear and concise description of what you expected to happen, if other than "should work".
|
||||||
|
|
||||||
**Versions**
|
**Versions**
|
||||||
- go-toml: version (git sha)
|
- go-toml: version (or git sha)
|
||||||
- go: version
|
- go: version
|
||||||
- operating system: e.g. macOS, Windows, Linux
|
- operating system: e.g. macOS, Windows, Linux
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: gomod
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
time: "13:00"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
@@ -109,7 +109,7 @@ Go-toml provides three handy command line tools:
|
|||||||
|
|
||||||
### Docker image
|
### Docker image
|
||||||
|
|
||||||
Those tools are also availble as a Docker image from
|
Those tools are also available as a Docker image from
|
||||||
[dockerhub](https://hub.docker.com/r/pelletier/go-toml). For example, to
|
[dockerhub](https://hub.docker.com/r/pelletier/go-toml). For example, to
|
||||||
use `tomljson`:
|
use `tomljson`:
|
||||||
|
|
||||||
|
|||||||
@@ -591,6 +591,7 @@ func (e *Encoder) wrapTomlValue(val interface{}, parent *Tree) interface{} {
|
|||||||
_, isTree := val.(*Tree)
|
_, isTree := val.(*Tree)
|
||||||
_, isTreeS := val.([]*Tree)
|
_, isTreeS := val.([]*Tree)
|
||||||
if isTree || isTreeS {
|
if isTree || isTreeS {
|
||||||
|
e.line++
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -226,7 +226,9 @@ func tomlValueStringRepresentation(v interface{}, commented string, indent strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getTreeArrayLine(trees []*Tree) (line int) {
|
func getTreeArrayLine(trees []*Tree) (line int) {
|
||||||
// get lowest line number that is not 0
|
// Prevent returning 0 for empty trees
|
||||||
|
line = int(^uint(0) >> 1)
|
||||||
|
// get lowest line number >= 0
|
||||||
for _, tv := range trees {
|
for _, tv := range trees {
|
||||||
if tv.position.Line < line || line == 0 {
|
if tv.position.Line < line || line == 0 {
|
||||||
line = tv.position.Line
|
line = tv.position.Line
|
||||||
|
|||||||
@@ -364,6 +364,55 @@ c = nan`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOrderedEmptyTrees(t *testing.T) {
|
||||||
|
type val struct {
|
||||||
|
Key string `toml:"key"`
|
||||||
|
}
|
||||||
|
type structure struct {
|
||||||
|
First val `toml:"first"`
|
||||||
|
Empty []val `toml:"empty"`
|
||||||
|
}
|
||||||
|
input := structure{First: val{Key: "value"}}
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
err := NewEncoder(buf).Order(OrderPreserve).Encode(input)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("failed to encode input")
|
||||||
|
}
|
||||||
|
expected := `
|
||||||
|
[first]
|
||||||
|
key = "value"
|
||||||
|
`
|
||||||
|
if expected != buf.String() {
|
||||||
|
t.Fatal("expected and encoded body aren't equal: ", expected, buf.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOrderedNonIncreasedLine(t *testing.T) {
|
||||||
|
type NiceMap map[string]string
|
||||||
|
type Manifest struct {
|
||||||
|
NiceMap `toml:"dependencies"`
|
||||||
|
Build struct {
|
||||||
|
BuildCommand string `toml:"build-command"`
|
||||||
|
} `toml:"build"`
|
||||||
|
}
|
||||||
|
|
||||||
|
test := &Manifest{}
|
||||||
|
test.Build.BuildCommand = "test"
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
if err := NewEncoder(buf).Order(OrderPreserve).Encode(test); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
expected := `
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[build]
|
||||||
|
build-command = "test"
|
||||||
|
`
|
||||||
|
if expected != buf.String() {
|
||||||
|
t.Fatal("expected and encoded body aren't equal: ", expected, buf.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIssue290(t *testing.T) {
|
func TestIssue290(t *testing.T) {
|
||||||
tomlString :=
|
tomlString :=
|
||||||
`[table]
|
`[table]
|
||||||
|
|||||||
Reference in New Issue
Block a user