diff --git a/.travis.gofmt.sh b/.travis.gofmt.sh deleted file mode 100755 index ef44ef3..0000000 --- a/.travis.gofmt.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -if [[ -n "$(gofmt -l .)" ]]; then - echo "Go code is not formatted:" - gofmt -d . - exit 1 -fi \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a8c777b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ -language: go - -sudo: false - -go: -- '1.12' - -script: -- ./.travis.gofmt.sh -- go test github.com/Wing924/ltsv -v -race -coverprofile=coverage.txt -covermode=atomic - -after_success: -- bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/bench/go.mod b/bench/go.mod index 66a556b..b49ab8c 100644 --- a/bench/go.mod +++ b/bench/go.mod @@ -1,14 +1,20 @@ module github.com/Wing924/ltsv/bench -go 1.12 +go 1.23.1 require ( github.com/Songmu/go-ltsv v0.0.0-20181014062614-c30af2b7b171 github.com/Wing924/ltsv v0.3.1 - github.com/kr/pretty v0.1.0 // indirect github.com/najeira/ltsv v0.0.0-20150303073528-40eb84a5b5d2 - github.com/stretchr/objx v0.2.0 // indirect - github.com/stretchr/testify v1.3.0 + github.com/stretchr/testify v1.9.0 github.com/ymotongpoo/goltsv v0.0.0-20130216005312-84f1da826252 - golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522 // indirect ) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/kr/pretty v0.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +replace github.com/Wing924/ltsv => ../ diff --git a/bench/go.sum b/bench/go.sum index 1b2e584..9ccd11c 100644 --- a/bench/go.sum +++ b/bench/go.sum @@ -1,10 +1,5 @@ github.com/Songmu/go-ltsv v0.0.0-20181014062614-c30af2b7b171 h1:nwdeQV2pNjaTv3os4N4/bKDqv0PxW/9DoEAdtW6sY9o= github.com/Songmu/go-ltsv v0.0.0-20181014062614-c30af2b7b171/go.mod h1:LBP+tS9C2iiUoR7AGPaZYY+kjXgB5eZxZKbSEBL9UFw= -github.com/Wing924/ltsv v0.3.0 h1:MZ3hwx9we3SBDPDyyhrC9s7/y4on5BedGbEQA3Epcz0= -github.com/Wing924/ltsv v0.3.0/go.mod h1:zl47wq7H23LocdDHg7yJAH/Qdc4MWHXu1Evx9Ahilmo= -github.com/Wing924/ltsv v0.3.1 h1:hbjzQ6YuS/sOm7nQJG7ddT9ua1yYmcH25Q8lsuiQE0A= -github.com/Wing924/ltsv v0.3.1/go.mod h1:zl47wq7H23LocdDHg7yJAH/Qdc4MWHXu1Evx9Ahilmo= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -16,14 +11,11 @@ github.com/najeira/ltsv v0.0.0-20150303073528-40eb84a5b5d2 h1:woADZdsnRYjTG+9Rb4 github.com/najeira/ltsv v0.0.0-20150303073528-40eb84a5b5d2/go.mod h1:VY0nAG+hmZziT1y1MBJFouy+Xkk4VYcONGlZv0uYtjg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/ymotongpoo/goltsv v0.0.0-20130216005312-84f1da826252 h1:zXhSTcwTFZgFo1z8IksjN05O9pHxVSQV3gtUfwlRIzw= github.com/ymotongpoo/goltsv v0.0.0-20130216005312-84f1da826252/go.mod h1:c1XsgVhgPubV0wqCuPeGZnptBjba8XpA+5mPaYTka0w= -golang.org/x/xerrors v0.0.0-20190510150013-5403a72a6aaf h1:46YZosxRq9YDy5kLloc61WBGDQ5byv6wcwMyDQNzOE8= -golang.org/x/xerrors v0.0.0-20190510150013-5403a72a6aaf/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522 h1:bhOzK9QyoD0ogCnFro1m2mz41+Ib0oOhfJnBp5MR4K4= -golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go.mod b/go.mod index 39d7240..823e898 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,11 @@ module github.com/Wing924/ltsv -go 1.12 +go 1.23.1 + +require github.com/stretchr/testify v1.9.0 require ( - github.com/stretchr/testify v1.3.0 - golang.org/x/xerrors v0.0.0-20190510150013-5403a72a6aaf + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 6ee49c8..60ce688 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,10 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -golang.org/x/xerrors v0.0.0-20190510150013-5403a72a6aaf h1:46YZosxRq9YDy5kLloc61WBGDQ5byv6wcwMyDQNzOE8= -golang.org/x/xerrors v0.0.0-20190510150013-5403a72a6aaf/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/parser.go b/parser.go index b83e035..21c9bc7 100644 --- a/parser.go +++ b/parser.go @@ -2,8 +2,8 @@ package ltsv import ( "bytes" - - "golang.org/x/xerrors" + "errors" + "fmt" ) type ( @@ -38,15 +38,15 @@ var DefaultParser = Parser{ var ( // ErrMissingLabel is an error to describe label is missing (ex. 'my_value') - ErrMissingLabel = xerrors.New("missing label") + ErrMissingLabel = errors.New("missing label") // ErrEmptyLabel is an error to describe label is empty (ex. ':my_value') - ErrEmptyLabel = xerrors.New("empty label") + ErrEmptyLabel = errors.New("empty label") // ErrInvalidLabel is an error to describe label contains invalid char (ex. 'my\tlabel:my_value') - ErrInvalidLabel = xerrors.New("invalid label") + ErrInvalidLabel = errors.New("invalid label") // ErrInvalidValue is an error to describe value contains invalid char (ex. 'my_label:my_value\n') - ErrInvalidValue = xerrors.New("invalid value") + ErrInvalidValue = errors.New("invalid value") // Break is an error for break loop - Break = xerrors.New("break") + Break = errors.New("break") ) // ParseField parse LTSV-encoded field and return the label and value. @@ -58,18 +58,18 @@ func (p Parser) ParseField(field []byte) (label []byte, value []byte, err error) value = field[idx+1:] if p.StrictMode { if err = validateLabel(label); err != nil { - return nil, nil, xerrors.Errorf("bad field label syntax %q: %w", string(field), err) + return nil, nil, fmt.Errorf("bad field label syntax %q: %w", string(field), err) } if err = validateValue(value); err != nil { - return nil, nil, xerrors.Errorf("bad field value syntax %q: %w", string(field), err) + return nil, nil, fmt.Errorf("bad field value syntax %q: %w", string(field), err) } } } else { switch idx { case -1: - err = xerrors.Errorf("bad field syntax %q: %w", string(field), ErrMissingLabel) + err = fmt.Errorf("bad field syntax %q: %w", string(field), ErrMissingLabel) case 0: - err = xerrors.Errorf("bad field syntax %q: %w", string(field), ErrEmptyLabel) + err = fmt.Errorf("bad field syntax %q: %w", string(field), ErrEmptyLabel) } } return @@ -94,14 +94,14 @@ func (p Parser) ParseLine(line []byte, callback func(label []byte, value []byte) } label, value, err := p.ParseField(field) if err != nil { - return xerrors.Errorf("bad line syntax %q: %w", string(oriLine), err) + return fmt.Errorf("bad line syntax %q: %w", string(oriLine), err) } if err = callback(label, value); err != nil { - if err == Break { + if errors.Is(err, Break) { break } - return xerrors.Errorf("ParseLine callback error: %w", err) + return fmt.Errorf("ParseLine callback error: %w", err) } } return nil @@ -118,7 +118,7 @@ func (p Parser) ParseLineAsMap(line []byte, record map[string]string) (map[strin return nil }) if err != nil { - return nil, xerrors.Errorf(": %w", err) + return nil, fmt.Errorf(": %w", err) } return record, nil } @@ -132,7 +132,7 @@ func (p Parser) ParseLineAsSlice(line []byte, record []Field) ([]Field, error) { return nil }) if err != nil { - return nil, xerrors.Errorf(": %w", err) + return nil, fmt.Errorf(": %w", err) } return record, nil } @@ -140,7 +140,7 @@ func (p Parser) ParseLineAsSlice(line []byte, record []Field) ([]Field, error) { func validateLabel(label []byte) error { for _, c := range label { if !isValidKey(c) { - return xerrors.Errorf("invalid char %q used in label %q: %w", c, string(label), ErrInvalidLabel) + return fmt.Errorf("invalid char %q used in label %q: %w", c, string(label), ErrInvalidLabel) } } return nil @@ -149,7 +149,7 @@ func validateLabel(label []byte) error { func validateValue(value []byte) error { for _, c := range value { if !isValidValue(c) { - return xerrors.Errorf("invalid char %q used in value %q: %w", c, string(value), ErrInvalidValue) + return fmt.Errorf("invalid char %q used in value %q: %w", c, string(value), ErrInvalidValue) } } return nil diff --git a/parser_test.go b/parser_test.go index 00eb512..656e67b 100644 --- a/parser_test.go +++ b/parser_test.go @@ -1,11 +1,10 @@ package ltsv import ( + "errors" "fmt" "testing" - "golang.org/x/xerrors" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -40,13 +39,13 @@ func TestParseLine_break(t *testing.T) { func TestParseLine_error(t *testing.T) { line := []byte("foo:123\tbar:456") counter := 0 - customErr := xerrors.New("custom error") + customErr := errors.New("custom error") err := ParseLine(line, func(label []byte, value []byte) error { counter++ return customErr }) assert.Error(t, err) - assert.True(t, xerrors.Is(err, customErr)) + assert.True(t, errors.Is(err, customErr)) assert.Equal(t, 1, counter) } @@ -72,7 +71,7 @@ func TestParseLineAsMap(t *testing.T) { m, err := ParseLineAsMap([]byte(test.line), nil) if test.err != nil { assert.Error(t, err) - assert.True(t, xerrors.Is(err, test.err)) + assert.ErrorIs(t, err, test.err) return } require.NoError(t, err) @@ -112,7 +111,7 @@ func TestParseLineAsSlice(t *testing.T) { m, err := ParseLineAsSlice([]byte(test.line), nil) if test.err != nil { assert.Error(t, err) - assert.True(t, xerrors.Is(err, test.err)) + assert.ErrorIs(t, err, test.err) return } require.NoError(t, err) @@ -151,7 +150,7 @@ func TestParseField(t *testing.T) { label, value, err := ParseField([]byte(test.line)) if test.err != nil { assert.Error(t, err) - assert.Truef(t, xerrors.Is(err, test.err), "%+v", err) + assert.ErrorIs(t, err, test.err) return } require.NoError(t, err)