Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ run:
linters:
enable-all: true
disable:
- gomnd
- exhaustivestruct
- testpackage
- godox
- wrapcheck

issues:
exclude-rules:
- path: _test\.go
linters:
- funlen
- forbidigo
- errorlint
6 changes: 6 additions & 0 deletions bareitem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

func TestParseBareItem(t *testing.T) {
t.Parallel()

data := []struct {
in string
out interface{}
Expand Down Expand Up @@ -40,6 +42,8 @@ func TestParseBareItem(t *testing.T) {
}

func TestMarshalBareItem(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
Expand All @@ -51,6 +55,8 @@ func TestMarshalBareItem(t *testing.T) {
}

func TestAssertBareItem(t *testing.T) {
t.Parallel()

defer func() {
if r := recover(); r == nil {
t.Errorf("The code did not panic")
Expand Down
4 changes: 4 additions & 0 deletions binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
)

func TestBinary(t *testing.T) {
t.Parallel()

var bd strings.Builder
_ = marshalBinary(&bd, []byte{4, 2})

Expand All @@ -16,6 +18,8 @@ func TestBinary(t *testing.T) {
}

func TestParseBinary(t *testing.T) {
t.Parallel()

data := []struct {
in string
out []byte
Expand Down
4 changes: 4 additions & 0 deletions boolean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestBooleanMarshalSFV(t *testing.T) {
t.Parallel()

var b strings.Builder

_ = marshalBoolean(&b, true)
Expand All @@ -23,6 +25,8 @@ func TestBooleanMarshalSFV(t *testing.T) {
}

func TestParseBoolean(t *testing.T) {
t.Parallel()

data := []struct {
in string
out bool
Expand Down
4 changes: 2 additions & 2 deletions decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func marshalDecimal(b io.StringWriter, d float64) error {
const TH = 0.001

rounded := math.RoundToEven(d/TH) * TH
int, frac := math.Modf(math.RoundToEven(d/TH) * TH)
i, frac := math.Modf(math.RoundToEven(d/TH) * TH)

if int < -999999999999 || int > 999999999999 {
if i < -999999999999 || i > 999999999999 {
return ErrInvalidDecimal
}

Expand Down
2 changes: 2 additions & 0 deletions decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestDecimalMarshalSFV(t *testing.T) {
t.Parallel()

data := []struct {
in float64
expected string
Expand Down
2 changes: 2 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package httpsfv
import "testing"

func TestDecodeError(t *testing.T) {
t.Parallel()

_, err := UnmarshalItem([]string{"invalid-é"})

if err.Error() != "unmarshal error: character 8" {
Expand Down
7 changes: 5 additions & 2 deletions dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
)

func TestDictionnary(t *testing.T) {
t.Parallel()

dict := NewDictionary()

add := []struct {
Expand Down Expand Up @@ -67,8 +69,7 @@ func TestDictionnary(t *testing.T) {
t.Errorf(`Get("notexist") = %v, %v; nil, false expected`, v, ok)
}

k := dict.Names()
if len(k) != 5 {
if k := dict.Names(); len(k) != 5 {
t.Errorf(`Names() = %v; {"f_o1o3-", "*f0.o*"} expected`, k)
}

Expand All @@ -85,6 +86,8 @@ func TestDictionnary(t *testing.T) {
}

func TestUnmarshalDictionary(t *testing.T) {
t.Parallel()

d1 := NewDictionary()
d1.Add("a", NewItem(false))
d1.Add("b", NewItem(true))
Expand Down
7 changes: 5 additions & 2 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package httpsfv
import "testing"

func TestMarshal(t *testing.T) {
t.Parallel()

i := NewItem(22.1)
i.Params.Add("foo", true)
i.Params.Add("bar", Token("baz"))
Expand All @@ -14,13 +16,14 @@ func TestMarshal(t *testing.T) {
tok.Params.Add("a", "b")
d.Add("tok", tok)

res, _ := Marshal(d)
if res != `i=22.1;foo;bar=baz, tok=foo;a="b"` {
if res, _ := Marshal(d); res != `i=22.1;foo;bar=baz, tok=foo;a="b"` {
t.Errorf("marshal: bad result")
}
}

func TestMarshalError(t *testing.T) {
t.Parallel()

if _, err := Marshal(NewItem(Token("à"))); err == nil {
t.Errorf("marshal: error expected")
}
Expand Down
4 changes: 4 additions & 0 deletions httpwg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ func valToDictionary(e interface{}) *Dictionary {
}

func TestOfficialTestSuiteParsing(t *testing.T) {
t.Parallel()

const dir = "structured-field-tests/"
f, _ := os.Open(dir)
files, _ := f.Readdir(-1)
Expand Down Expand Up @@ -245,6 +247,8 @@ func BenchmarkSerializingOfficialExamples(b *testing.B) {
}

func TestOfficialTestSuiteSerialization(t *testing.T) {
t.Parallel()

const dir = "structured-field-tests/serialisation-tests/"

f, _ := os.Open(dir)
Expand Down
2 changes: 2 additions & 0 deletions innerlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestInnerList(t *testing.T) {
t.Parallel()

foo := NewItem("foo")
foo.Params.Add("a", true)
foo.Params.Add("b", 1936)
Expand Down
4 changes: 4 additions & 0 deletions integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestIntegerMarshalSFV(t *testing.T) {
t.Parallel()

data := []struct {
in int64
expected string
Expand Down Expand Up @@ -39,6 +41,8 @@ func TestIntegerMarshalSFV(t *testing.T) {
}

func TestParseIntegerOrDecimal(t *testing.T) {
t.Parallel()

data := []struct {
in string
expected interface{}
Expand Down
6 changes: 6 additions & 0 deletions item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
)

func TestMarshalItem(t *testing.T) {
t.Parallel()

data := []struct {
in Item
expected string
Expand Down Expand Up @@ -49,6 +51,8 @@ func TestMarshalItem(t *testing.T) {
}

func TestItemParamsMarshalSFV(t *testing.T) {
t.Parallel()

i := NewItem(Token("bar"))
i.Params.Add("foo", 0.0)
i.Params.Add("baz", true)
Expand All @@ -62,6 +66,8 @@ func TestItemParamsMarshalSFV(t *testing.T) {
}

func TestUnmarshalItem(t *testing.T) {
t.Parallel()

i1 := NewItem(true)
i1.Params.Add("foo", true)
i1.Params.Add("*bar", Token("tok"))
Expand Down
4 changes: 4 additions & 0 deletions key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestKeyMarshalSFV(t *testing.T) {
t.Parallel()

data := []struct {
in string
expected string
Expand Down Expand Up @@ -37,6 +39,8 @@ func TestKeyMarshalSFV(t *testing.T) {
}

func TestParseKey(t *testing.T) {
t.Parallel()

data := []struct {
in string
expected string
Expand Down
1 change: 1 addition & 0 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func parseItemOrInnerList(s *scanner) (Member, error) {
if s.eof() {
return nil, &UnmarshalError{s.off, ErrInvalidInnerListFormat}
}

if s.data[s.off] == '(' {
return parseInnerList(s)
}
Expand Down
4 changes: 4 additions & 0 deletions list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestList(t *testing.T) {
t.Parallel()

params := NewParams()
params.Add("foo", true)
params.Add("bar", Token("baz"))
Expand Down Expand Up @@ -49,6 +51,8 @@ func TestList(t *testing.T) {
}

func TestUnmarshalList(t *testing.T) {
t.Parallel()

l1 := List{Item{Token("foo"), NewParams()}, Item{Token("bar"), NewParams()}}

il2 := Item{"foo", NewParams()}
Expand Down
10 changes: 6 additions & 4 deletions params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
)

func TestParameters(t *testing.T) {
t.Parallel()

p := NewParams()

add := []struct {
Expand Down Expand Up @@ -66,20 +68,20 @@ func TestParameters(t *testing.T) {
t.Errorf(`Get("notexist") = %v, %v; nil, false expected`, v, ok)
}

k := p.Names()
if len(k) != 5 {
if k := p.Names(); len(k) != 5 {
t.Errorf(`Names() = %v; {"f_o1o3-", "*f0.o*"} expected`, k)
}

b.Reset()
err := p.marshalSFV(&b)

if b.String() != `;f_o1o3-=123.0;*f0.o*="";t;f=?0;b=:AAE=:` {
if err := p.marshalSFV(&b); b.String() != `;f_o1o3-=123.0;*f0.o*="";t;f=?0;b=:AAE=:` {
t.Errorf(`marshalSFV(): invalid serialization: %v (%v)`, b.String(), err)
}
}

func TestParseParameters(t *testing.T) {
t.Parallel()

p0 := NewParams()
p0.Add("foo", true)
p0.Add("*bar", "baz")
Expand Down
4 changes: 4 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
)

func TestStringMarshalSFV(t *testing.T) {
t.Parallel()

data := []struct {
in string
expected string
Expand Down Expand Up @@ -44,6 +46,8 @@ func TestStringMarshalSFV(t *testing.T) {
}

func TestParseString(t *testing.T) {
t.Parallel()

data := []struct {
in string
out string
Expand Down
4 changes: 4 additions & 0 deletions token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestTokenMarshalSFV(t *testing.T) {
t.Parallel()

data := []struct {
in string
valid bool
Expand Down Expand Up @@ -59,6 +61,8 @@ func TestTokenMarshalSFV(t *testing.T) {
}

func TestParseToken(t *testing.T) {
t.Parallel()

data := []struct {
in string
out Token
Expand Down