Skip to content

Commit

Permalink
Run Go 1.16 in CI
Browse files Browse the repository at this point in the history
The only reason I retained backwards-compatibility is because Debian 11
is still on Go 1.15, but Debian 12 should be released this week with Go
1.19 so we can fairly safely drop it.
  • Loading branch information
arp242 committed Jun 8, 2023
1 parent b324da5 commit cfb3ca9
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -5,7 +5,7 @@
"test": {
"strategy": {
"matrix": {
"go-version": ["1.13.x", "1.20.x"],
"go-version": ["1.16.x", "1.20.x"],
"os": ["ubuntu-latest", "macos-latest", "windows-latest"]
}
},
Expand Down
6 changes: 1 addition & 5 deletions bench_test.go
@@ -1,12 +1,8 @@
//go:build go1.16
// +build go1.16

package toml_test

import (
"bytes"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -132,7 +128,7 @@ func BenchmarkEncode(b *testing.B) {
}

func BenchmarkExample(b *testing.B) {
d, err := ioutil.ReadFile("_example/example.toml")
d, err := os.ReadFile("_example/example.toml")
if err != nil {
b.Fatal(err)
}
Expand Down
15 changes: 13 additions & 2 deletions decode.go
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"io/fs"
"math"
"os"
"reflect"
Expand Down Expand Up @@ -46,6 +46,17 @@ func DecodeFile(path string, v interface{}) (MetaData, error) {
return NewDecoder(fp).Decode(v)
}

// DecodeFS reads the contents of a file from [fs.FS] and decodes it with
// [Decode].
func DecodeFS(fsys fs.FS, path string, v interface{}) (MetaData, error) {
fp, err := fsys.Open(path)
if err != nil {
return MetaData{}, err
}
defer fp.Close()
return NewDecoder(fp).Decode(v)
}

// Primitive is a TOML value that hasn't been decoded into a Go value.
//
// This type can be used for any value, which will cause decoding to be delayed.
Expand Down Expand Up @@ -148,7 +159,7 @@ func (dec *Decoder) Decode(v interface{}) (MetaData, error) {

// TODO: parser should read from io.Reader? Or at the very least, make it
// read from []byte rather than string
data, err := ioutil.ReadAll(dec.r)
data, err := io.ReadAll(dec.r)
if err != nil {
return MetaData{}, err
}
Expand Down
19 changes: 0 additions & 19 deletions decode_go116.go

This file was deleted.

29 changes: 0 additions & 29 deletions decode_go116_test.go

This file was deleted.

23 changes: 21 additions & 2 deletions decode_test.go
Expand Up @@ -5,14 +5,14 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"reflect"
"strconv"
"strings"
"sync"
"testing"
"testing/fstest"
"time"

"github.com/BurntSushi/toml/internal"
Expand All @@ -38,7 +38,7 @@ func TestDecodeReader(t *testing.T) {
}

func TestDecodeFile(t *testing.T) {
tmp, err := ioutil.TempFile("", "toml-")
tmp, err := os.CreateTemp("", "toml-")
if err != nil {
t.Fatal(err)
}
Expand All @@ -63,6 +63,25 @@ func TestDecodeFile(t *testing.T) {
}
}

func TestDecodeFS(t *testing.T) {
fsys := fstest.MapFS{
"test.toml": &fstest.MapFile{
Data: []byte("a = 42"),
},
}

var i struct{ A int }
meta, err := DecodeFS(fsys, "test.toml", &i)
if err != nil {
t.Fatal(err)
}
have := fmt.Sprintf("%v %v %v", i, meta.Keys(), meta.Type("a"))
want := "{42} [a] Integer"
if have != want {
t.Errorf("\nhave: %s\nwant: %s", have, want)
}
}

func TestDecodeBOM(t *testing.T) {
for _, tt := range [][]byte{
[]byte("\xff\xfea = \"b\""),
Expand Down
3 changes: 0 additions & 3 deletions error_test.go
@@ -1,6 +1,3 @@
//go:build go1.16
// +build go1.16

package toml_test

import (
Expand Down
3 changes: 0 additions & 3 deletions internal/toml-test/json.go
@@ -1,6 +1,3 @@
//go:build go1.16
// +build go1.16

package tomltest

import (
Expand Down
3 changes: 0 additions & 3 deletions internal/toml-test/runner.go
@@ -1,8 +1,5 @@
//go:generate ./gen-multi.py

//go:build go1.16
// +build go1.16

package tomltest

import (
Expand Down
3 changes: 0 additions & 3 deletions internal/toml-test/toml.go
@@ -1,6 +1,3 @@
//go:build go1.16
// +build go1.16

package tomltest

import (
Expand Down
3 changes: 0 additions & 3 deletions internal/toml-test/version.go
@@ -1,6 +1,3 @@
//go:build go1.16
// +build go1.16

package tomltest

type versionSpec struct {
Expand Down
3 changes: 0 additions & 3 deletions toml_test.go
@@ -1,6 +1,3 @@
//go:build go1.16
// +build go1.16

package toml_test

import (
Expand Down

0 comments on commit cfb3ca9

Please sign in to comment.