Skip to content

Commit

Permalink
support go 1.23 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wing924 authored Sep 27, 2024
1 parent 6290a7c commit 86cc90a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 74 deletions.
7 changes: 0 additions & 7 deletions .travis.gofmt.sh

This file was deleted.

13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

16 changes: 11 additions & 5 deletions bench/go.mod
Original file line number Diff line number Diff line change
@@ -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 => ../
20 changes: 6 additions & 14 deletions bench/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
36 changes: 18 additions & 18 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ltsv

import (
"bytes"

"golang.org/x/xerrors"
"errors"
"fmt"
)

type (
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -132,15 +132,15 @@ 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
}

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
Expand All @@ -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
Expand Down
13 changes: 6 additions & 7 deletions parser_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ltsv

import (
"errors"
"fmt"
"testing"

"golang.org/x/xerrors"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 86cc90a

Please sign in to comment.