General cleanup (#999)
This commit is contained in:
+3
-3
@@ -33,7 +33,7 @@ The documentation is present in the [README][readme] and thorough the source
|
||||
code. On release, it gets updated on [pkg.go.dev][pkg.go.dev]. To make a change
|
||||
to the documentation, create a pull request with your proposed changes. For
|
||||
simple changes like that, the easiest way to go is probably the "Fork this
|
||||
project and edit the file" button on Github, displayed at the top right of the
|
||||
project and edit the file" button on GitHub, displayed at the top right of the
|
||||
file. Unless it's a trivial change (for example a typo), provide a little bit of
|
||||
context in your pull request description or commit message.
|
||||
|
||||
@@ -111,7 +111,7 @@ code lowers the coverage.
|
||||
|
||||
Go-toml aims to stay efficient. We rely on a set of scenarios executed with Go's
|
||||
builtin benchmark systems. Because of their noisy nature, containers provided by
|
||||
Github Actions cannot be reliably used for benchmarking. As a result, you are
|
||||
GitHub Actions cannot be reliably used for benchmarking. As a result, you are
|
||||
responsible for checking that your changes do not incur a performance penalty.
|
||||
You can run their following to execute benchmarks:
|
||||
|
||||
@@ -174,7 +174,7 @@ git pull
|
||||
git tag v2.2.0
|
||||
git push --tags
|
||||
```
|
||||
3. CI automatically builds a draft Github release. Review it and edit as
|
||||
3. CI automatically builds a draft GitHub release. Review it and edit as
|
||||
necessary. Look for "Other changes". That would indicate a pull request not
|
||||
labeled properly. Tweak labels and pull request titles until changelog looks
|
||||
good for users.
|
||||
|
||||
@@ -3,7 +3,7 @@ package benchmark_test
|
||||
import (
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -74,7 +74,7 @@ func fixture(tb testing.TB, path string) []byte {
|
||||
gz, err := gzip.NewReader(f)
|
||||
assert.NoError(tb, err)
|
||||
|
||||
buf, err := ioutil.ReadAll(gz)
|
||||
buf, err := io.ReadAll(gz)
|
||||
assert.NoError(tb, err)
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package benchmark_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -59,7 +59,7 @@ func BenchmarkUnmarshal(b *testing.B) {
|
||||
})
|
||||
|
||||
b.Run("ReferenceFile", func(b *testing.B) {
|
||||
bytes, err := ioutil.ReadFile("benchmark.toml")
|
||||
bytes, err := os.ReadFile("benchmark.toml")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func BenchmarkMarshal(b *testing.B) {
|
||||
})
|
||||
|
||||
b.Run("ReferenceFile", func(b *testing.B) {
|
||||
bytes, err := ioutil.ReadFile("benchmark.toml")
|
||||
bytes, err := os.ReadFile("benchmark.toml")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
@@ -344,7 +344,7 @@ type benchmarkDoc struct {
|
||||
}
|
||||
|
||||
func TestUnmarshalReferenceFile(t *testing.T) {
|
||||
bytes, err := ioutil.ReadFile("benchmark.toml")
|
||||
bytes, err := os.ReadFile("benchmark.toml")
|
||||
assert.NoError(t, err)
|
||||
d := benchmarkDoc{}
|
||||
err = toml.Unmarshal(bytes, &d)
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package toml_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func FuzzUnmarshal(f *testing.F) {
|
||||
file, err := ioutil.ReadFile("benchmark/benchmark.toml")
|
||||
file, err := os.ReadFile("benchmark/benchmark.toml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
+2
-3
@@ -6,7 +6,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
@@ -72,7 +71,7 @@ func (p *Program) runAllFilesInPlace(files []string) error {
|
||||
}
|
||||
|
||||
func (p *Program) runFileInPlace(path string) error {
|
||||
in, err := ioutil.ReadFile(path)
|
||||
in, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -84,5 +83,5 @@ func (p *Program) runFileInPlace(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(path, out.Bytes(), 0600)
|
||||
return os.WriteFile(path, out.Bytes(), 0600)
|
||||
}
|
||||
|
||||
+10
-11
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
@@ -63,7 +62,7 @@ func TestProcessMainStdinDecodeErr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessMainFileExists(t *testing.T) {
|
||||
tmpfile, err := ioutil.TempFile("", "example")
|
||||
tmpfile, err := os.CreateTemp("", "example")
|
||||
assert.NoError(t, err)
|
||||
defer os.Remove(tmpfile.Name())
|
||||
_, err = tmpfile.Write([]byte(`some data`))
|
||||
@@ -95,16 +94,16 @@ func TestProcessMainFileDoesNotExist(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessMainFilesInPlace(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
assert.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
path1 := path.Join(dir, "file1")
|
||||
path2 := path.Join(dir, "file2")
|
||||
|
||||
err = ioutil.WriteFile(path1, []byte("content 1"), 0600)
|
||||
err = os.WriteFile(path1, []byte("content 1"), 0600)
|
||||
assert.NoError(t, err)
|
||||
err = ioutil.WriteFile(path2, []byte("content 2"), 0600)
|
||||
err = os.WriteFile(path2, []byte("content 2"), 0600)
|
||||
assert.NoError(t, err)
|
||||
|
||||
p := Program{
|
||||
@@ -116,11 +115,11 @@ func TestProcessMainFilesInPlace(t *testing.T) {
|
||||
|
||||
assert.Equal(t, 0, exit)
|
||||
|
||||
v1, err := ioutil.ReadFile(path1)
|
||||
v1, err := os.ReadFile(path1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "1", string(v1))
|
||||
|
||||
v2, err := ioutil.ReadFile(path2)
|
||||
v2, err := os.ReadFile(path2)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "2", string(v2))
|
||||
}
|
||||
@@ -137,13 +136,13 @@ func TestProcessMainFilesInPlaceErrRead(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcessMainFilesInPlaceFailFn(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
assert.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
path1 := path.Join(dir, "file1")
|
||||
|
||||
err = ioutil.WriteFile(path1, []byte("content 1"), 0600)
|
||||
err = os.WriteFile(path1, []byte("content 1"), 0600)
|
||||
assert.NoError(t, err)
|
||||
|
||||
p := Program{
|
||||
@@ -155,13 +154,13 @@ func TestProcessMainFilesInPlaceFailFn(t *testing.T) {
|
||||
|
||||
assert.Equal(t, -1, exit)
|
||||
|
||||
v1, err := ioutil.ReadFile(path1)
|
||||
v1, err := os.ReadFile(path1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "content 1", string(v1))
|
||||
}
|
||||
|
||||
func dummyFileFn(r io.Reader, w io.Writer) error {
|
||||
b, err := ioutil.ReadAll(r)
|
||||
b, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2283,7 +2283,7 @@ func (c *Custom) UnmarshalTOML(v interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestGithubIssue431(t *testing.T) {
|
||||
func TestGitHubIssue431(t *testing.T) {
|
||||
doc := `key = "value"`
|
||||
var c Config
|
||||
if err := toml.Unmarshal([]byte(doc), &c); err != nil {
|
||||
@@ -2321,7 +2321,7 @@ type config437 struct {
|
||||
} `toml:"HTTP"`
|
||||
}
|
||||
|
||||
func TestGithubIssue437(t *testing.T) {
|
||||
func TestGitHubIssue437(t *testing.T) {
|
||||
t.Skipf("unmarshalTOML not implemented")
|
||||
src := `
|
||||
[HTTP]
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
// Marshal is a helpfer function for calling toml.Marshal
|
||||
// Marshal is a helper function for calling toml.Marshal
|
||||
//
|
||||
// Only needed to avoid package import loops.
|
||||
func Marshal(v interface{}) ([]byte, error) {
|
||||
|
||||
+1
-1
@@ -846,7 +846,7 @@ func parseTag(tag string) (string, tagOptions) {
|
||||
}
|
||||
|
||||
raw := tag[idx+1:]
|
||||
tag = string(tag[:idx])
|
||||
tag = tag[:idx]
|
||||
for raw != "" {
|
||||
var o string
|
||||
i := strings.Index(raw, ",")
|
||||
|
||||
+4
-2
@@ -1326,7 +1326,8 @@ func TestIssue786(t *testing.T) {
|
||||
config.Custom = []Custom{{Name: "omit", General: General{Randomize: false}}}
|
||||
config.Custom = append(config.Custom, Custom{Name: "present", General: General{From: "-2d", Randomize: true}})
|
||||
encoder := toml.NewEncoder(buf)
|
||||
encoder.Encode(config)
|
||||
err = encoder.Encode(config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expected := `# from in graphite-web format, the local TZ is used
|
||||
from = '-2d'
|
||||
@@ -1372,7 +1373,8 @@ func TestMarshalIssue888(t *testing.T) {
|
||||
}
|
||||
|
||||
encoder := toml.NewEncoder(buf).SetIndentTables(true)
|
||||
encoder.Encode(config)
|
||||
err := encoder.Encode(config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
expected := `# custom config
|
||||
[[Custom]]
|
||||
|
||||
@@ -52,7 +52,7 @@ func testgenValid(t *testing.T, input string, jsonRef string) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
var actual interface{}
|
||||
err = json.Unmarshal([]byte(j), &actual)
|
||||
err = json.Unmarshal(j, &actual)
|
||||
assert.NoError(t, err)
|
||||
|
||||
testsuite.CmpJSON(t, "", ref, actual)
|
||||
|
||||
+6
-3
@@ -2977,7 +2977,8 @@ func TestIssue931(t *testing.T) {
|
||||
Name = 'd'
|
||||
`)
|
||||
|
||||
toml.Unmarshal(b, &its)
|
||||
err := toml.Unmarshal(b, &its)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, items{[]item{{"c"}, {"d"}}}, its)
|
||||
}
|
||||
|
||||
@@ -2998,7 +2999,8 @@ func TestIssue931Interface(t *testing.T) {
|
||||
Name = 'd'
|
||||
`)
|
||||
|
||||
toml.Unmarshal(b, &its)
|
||||
err := toml.Unmarshal(b, &its)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, items{[]interface{}{item{"Name": "c"}, item{"Name": "d"}}}, its)
|
||||
}
|
||||
|
||||
@@ -3024,7 +3026,8 @@ func TestIssue931SliceInterface(t *testing.T) {
|
||||
Name = 'd'
|
||||
`)
|
||||
|
||||
toml.Unmarshal(b, &its)
|
||||
err := toml.Unmarshal(b, &its)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, items{[]interface{}{item{"Name": "c"}, item{"Name": "d"}}}, its)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ func (n *Node) Next() *Node {
|
||||
}
|
||||
|
||||
// Child returns a pointer to the first child node of this node. Other children
|
||||
// can be accessed calling Next on the first child. Returns an nil if this Node
|
||||
// can be accessed calling Next on the first child. Returns nil if this Node
|
||||
// has no child.
|
||||
func (n *Node) Child() *Node {
|
||||
if n.child == 0 {
|
||||
|
||||
+1
-1
@@ -1076,7 +1076,7 @@ byteLoop:
|
||||
}
|
||||
case c == 'T' || c == 't' || c == ':' || c == '.':
|
||||
hasTime = true
|
||||
case c == '+' || c == '-' || c == 'Z' || c == 'z':
|
||||
case c == '+' || c == 'Z' || c == 'z':
|
||||
hasTz = true
|
||||
case c == ' ':
|
||||
if !seenSpace && i+1 < len(b) && isDigit(b[i+1]) {
|
||||
|
||||
Reference in New Issue
Block a user