diff --git a/.golangci.yml b/.golangci.yml index a06e95e8f..0fe2eb496 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -37,6 +37,17 @@ linters: - wrapcheck - stylecheck - thelper + - nonamedreturns + - revive + - dupword + - exhaustruct + - varnamelen + - forcetypeassert + - ireturn + - maintidx + - govet + - nosnakecase + - testableexamples linters-settings: govet: diff --git a/bin/.go@1.17.pkg b/bin/.go-1.19.2.pkg similarity index 100% rename from bin/.go@1.17.pkg rename to bin/.go-1.19.2.pkg diff --git a/bin/.golangci-lint-1.37.0.pkg b/bin/.golangci-lint-1.50.0.pkg similarity index 100% rename from bin/.golangci-lint-1.37.0.pkg rename to bin/.golangci-lint-1.50.0.pkg diff --git a/bin/go b/bin/go index 9797b799e..50baf1754 120000 --- a/bin/go +++ b/bin/go @@ -1 +1 @@ -.go@1.17.pkg \ No newline at end of file +.go-1.19.2.pkg \ No newline at end of file diff --git a/bin/gofmt b/bin/gofmt index 9797b799e..50baf1754 120000 --- a/bin/gofmt +++ b/bin/gofmt @@ -1 +1 @@ -.go@1.17.pkg \ No newline at end of file +.go-1.19.2.pkg \ No newline at end of file diff --git a/bin/golangci-lint b/bin/golangci-lint index cf27348e6..b32e1a3b1 120000 --- a/bin/golangci-lint +++ b/bin/golangci-lint @@ -1 +1 @@ -.golangci-lint-1.37.0.pkg \ No newline at end of file +.golangci-lint-1.50.0.pkg \ No newline at end of file diff --git a/cmd/chroma/go.mod b/cmd/chroma/go.mod index 1cb1e7e10..29ecb0475 100644 --- a/cmd/chroma/go.mod +++ b/cmd/chroma/go.mod @@ -1,6 +1,6 @@ module github.com/alecthomas/chroma/v2/cmd/chroma -go 1.17 +go 1.19 replace github.com/alecthomas/chroma/v2 => ../../ diff --git a/cmd/chroma/go.sum b/cmd/chroma/go.sum index 19cd2e604..eeade3bdb 100644 --- a/cmd/chroma/go.sum +++ b/cmd/chroma/go.sum @@ -1,12 +1,13 @@ +github.com/alecthomas/assert/v2 v2.2.0 h1:f6L/b7KE2bfA+9O4FL3CM/xJccDEwPVYd5fALBiuwvw= github.com/alecthomas/kong v0.2.17 h1:URDISCI96MIgcIlQyoCAlhOmrSw6pZScBNkctg8r0W0= github.com/alecthomas/kong v0.2.17/go.mod h1:ka3VZ8GZNPXv9Ov+j4YNLkI8mTuhXyr/0ktSlqIydQQ= -github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae h1:zzGwJfFlFGD94CyyYwCJeSuD32Gj9GTaSi5y9hoVzdY= -github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= +github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE= 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/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= diff --git a/cmd/chromad/go.mod b/cmd/chromad/go.mod index d31551fb3..830455775 100644 --- a/cmd/chromad/go.mod +++ b/cmd/chromad/go.mod @@ -1,6 +1,6 @@ module github.com/alecthomas/chroma/v2/cmd/chromad -go 1.17 +go 1.19 require ( github.com/alecthomas/chroma/v2 v2.0.0-00010101000000-000000000000 diff --git a/cmd/chromad/go.sum b/cmd/chromad/go.sum index f64caf2b4..2f9e7c5e3 100644 --- a/cmd/chromad/go.sum +++ b/cmd/chromad/go.sum @@ -1,11 +1,10 @@ +github.com/alecthomas/assert/v2 v2.2.0 h1:f6L/b7KE2bfA+9O4FL3CM/xJccDEwPVYd5fALBiuwvw= github.com/alecthomas/kong v0.2.1-0.20190721020729-f7d3d9bfb5ed/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI= github.com/alecthomas/kong v0.2.4 h1:Y0ZBCHAvHhTHw7FFJ2FzCAAG4pkbTgA45nc7BpMhDNk= github.com/alecthomas/kong v0.2.4/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE= github.com/alecthomas/kong-hcl v0.2.0 h1:l1+pkGJm2BtRJF9dCq9hw6KZWEanteY4Ar9suW3Qm0g= github.com/alecthomas/kong-hcl v0.2.0/go.mod h1:S5D46RHGG8Ubdxk8TuXBT9wndShsA8/JYSxxiI9y01Y= -github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae h1:zzGwJfFlFGD94CyyYwCJeSuD32Gj9GTaSi5y9hoVzdY= -github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE= 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/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= @@ -20,16 +19,12 @@ github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyC github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/coalesce_test.go b/coalesce_test.go index bc26e038f..d003ffa51 100644 --- a/coalesce_test.go +++ b/coalesce_test.go @@ -3,7 +3,7 @@ package chroma import ( "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" ) func TestCoalesce(t *testing.T) { diff --git a/colour_test.go b/colour_test.go index 87f32a642..45e215cd5 100644 --- a/colour_test.go +++ b/colour_test.go @@ -4,7 +4,7 @@ import ( "math" "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" ) func TestColourRGB(t *testing.T) { @@ -62,12 +62,10 @@ func hue(c Colour) float64 { } func TestColourClampBrightness(t *testing.T) { - const delta = 0.01 // used for brightness and hue comparisons - // Start with a colour with a brightness close to 0.5. initial := NewColour(0, 128, 255) br := initial.Brightness() - assert.InDelta(t, 0.5, br, delta) + assertInDelta(t, 0.5, br) // Passing a range that includes the colour's brightness should be a no-op. assert.Equal(t, initial.String(), initial.ClampBrightness(br-0.01, br+0.01).String()) @@ -79,10 +77,15 @@ func TestColourClampBrightness(t *testing.T) { // Clamping to a brighter or darker range should produce the requested // brightness while preserving the colour's hue. brighter := initial.ClampBrightness(0.75, 1) - assert.InDelta(t, 0.75, brighter.Brightness(), delta) - assert.InDelta(t, hue(initial), hue(brighter), delta) + assertInDelta(t, 0.75, brighter.Brightness()) + assertInDelta(t, hue(initial), hue(brighter)) darker := initial.ClampBrightness(0, 0.25) - assert.InDelta(t, 0.25, darker.Brightness(), delta) - assert.InDelta(t, hue(initial), hue(darker), delta) + assertInDelta(t, 0.25, darker.Brightness()) + assertInDelta(t, hue(initial), hue(darker)) +} + +func assertInDelta(t *testing.T, expected, actual float64) { + const delta = 0.01 // used for brightness and hue comparisons + assert.True(t, actual > (expected-delta) && actual < (expected+delta)) } diff --git a/delegate_test.go b/delegate_test.go index f37d18740..083896afa 100644 --- a/delegate_test.go +++ b/delegate_test.go @@ -3,7 +3,7 @@ package chroma import ( "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" ) func makeDelegationTestLexers(t *testing.T) (lang Lexer, root Lexer) { diff --git a/formatters/html/html_test.go b/formatters/html/html_test.go index d86eb7791..2670a9073 100644 --- a/formatters/html/html_test.go +++ b/formatters/html/html_test.go @@ -4,10 +4,11 @@ import ( "bytes" "fmt" "io/ioutil" + "regexp" "strings" "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/lexers" @@ -117,7 +118,7 @@ func TestTabWidthStyle(t *testing.T) { err = f.Format(&buf, styles.Fallback, it) assert.NoError(t, err) - assert.Regexp(t, `echo FOO`, buf.String()) + assert.True(t, regexp.MustCompile(`echo FOO`).MatchString(buf.String())) } func TestWithCustomCSSStyleInheritance(t *testing.T) { @@ -144,7 +145,7 @@ func TestWithCustomCSSStyleInheritance(t *testing.T) { err = f.Format(&buf, styles.Fallback, it) assert.NoError(t, err) - assert.Regexp(t, ` "FOO"`, buf.String()) + assert.True(t, regexp.MustCompile(` "FOO"`).MatchString(buf.String())) } func TestWrapLongLines(t *testing.T) { @@ -156,7 +157,7 @@ func TestWrapLongLines(t *testing.T) { err = f.Format(&buf, styles.Fallback, it) assert.NoError(t, err) - assert.Regexp(t, `\necho FOO\n\n", buf.String()) - assert.Regexp(t, `\.bg { .+ }`, buf.String()) - assert.Regexp(t, `\.chroma { .+ }`, buf.String()) + assert.True(t, regexp.MustCompile("\necho FOO\n\n").MatchString(buf.String())) + assert.True(t, regexp.MustCompile(`\.bg { .+ }`).MatchString(buf.String())) + assert.True(t, regexp.MustCompile(`\.chroma { .+ }`).MatchString(buf.String())) } func TestLinkeableLineNumbers(t *testing.T) { @@ -306,7 +307,7 @@ func TestWithPreWrapper(t *testing.T) { t.Run("InlineCode, inline styles", func(t *testing.T) { s := format(New(InlineCode(true))) - assert.Regexp(t, `echo FOO`, s) + assert.True(t, regexp.MustCompile(`echo FOO`).MatchString(s)) }) t.Run("Wrapper", func(t *testing.T) { diff --git a/formatters/tty_indexed_test.go b/formatters/tty_indexed_test.go index cfac27c96..0892c20f8 100644 --- a/formatters/tty_indexed_test.go +++ b/formatters/tty_indexed_test.go @@ -3,8 +3,8 @@ package formatters import ( "testing" + assert "github.com/alecthomas/assert/v2" "github.com/alecthomas/chroma/v2" - "github.com/stretchr/testify/assert" ) func TestClosestColour(t *testing.T) { diff --git a/go.mod b/go.mod index e7cd288c7..705bf4b1a 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,11 @@ module github.com/alecthomas/chroma/v2 -go 1.17 +go 1.19 require ( + github.com/alecthomas/assert/v2 v2.2.0 github.com/alecthomas/repr v0.1.0 github.com/dlclark/regexp2 v1.4.0 - github.com/stretchr/testify v1.8.0 ) -require ( - 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 -) +require github.com/hexops/gotextdiff v1.0.3 // indirect diff --git a/go.sum b/go.sum index 263d22d6d..dd3c0b099 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,8 @@ +github.com/alecthomas/assert/v2 v2.2.0 h1:f6L/b7KE2bfA+9O4FL3CM/xJccDEwPVYd5fALBiuwvw= +github.com/alecthomas/assert/v2 v2.2.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA= github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE= github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8= -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/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= -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/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -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.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= diff --git a/lexer_test.go b/lexer_test.go index 75e0d9072..5e9fb89b9 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -3,13 +3,13 @@ package chroma import ( "testing" - "github.com/stretchr/testify/require" + assert "github.com/alecthomas/assert/v2" ) func TestTokenTypeClassifiers(t *testing.T) { - require.True(t, GenericDeleted.InCategory(Generic)) - require.True(t, LiteralStringBacktick.InSubCategory(String)) - require.Equal(t, LiteralStringBacktick.String(), "LiteralStringBacktick") + assert.True(t, GenericDeleted.InCategory(Generic)) + assert.True(t, LiteralStringBacktick.InSubCategory(String)) + assert.Equal(t, LiteralStringBacktick.String(), "LiteralStringBacktick") } func TestSimpleLexer(t *testing.T) { @@ -30,7 +30,7 @@ func TestSimpleLexer(t *testing.T) { [section] a = 10 `) - require.NoError(t, err) + assert.NoError(t, err) expected := []Token{ {Whitespace, "\n\t"}, {Comment, "; this is a comment"}, @@ -44,5 +44,5 @@ func TestSimpleLexer(t *testing.T) { {LiteralString, "10"}, {Whitespace, "\n"}, } - require.Equal(t, expected, actual) + assert.Equal(t, expected, actual) } diff --git a/lexers/cpp_test.go b/lexers/cpp_test.go index 16a8ba2d7..50ee8c88b 100644 --- a/lexers/cpp_test.go +++ b/lexers/cpp_test.go @@ -3,7 +3,7 @@ package lexers_test import ( "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/lexers" diff --git a/lexers/go_test.go b/lexers/go_test.go index 3713f2449..12128446d 100644 --- a/lexers/go_test.go +++ b/lexers/go_test.go @@ -3,8 +3,8 @@ package lexers import ( "testing" + assert "github.com/alecthomas/assert/v2" "github.com/alecthomas/chroma/v2" - "github.com/stretchr/testify/assert" ) func TestGoHTMLTemplateIssue126(t *testing.T) { diff --git a/lexers/lexer_benchmark_test.go b/lexers/lexer_benchmark_test.go index c97512c88..1fdf1fa60 100644 --- a/lexers/lexer_benchmark_test.go +++ b/lexers/lexer_benchmark_test.go @@ -3,7 +3,7 @@ package lexers_test import ( "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/lexers" diff --git a/lexers/lexers_test.go b/lexers/lexers_test.go index e77dd5e6a..2f78968be 100644 --- a/lexers/lexers_test.go +++ b/lexers/lexers_test.go @@ -9,9 +9,8 @@ import ( "strings" "testing" + assert "github.com/alecthomas/assert/v2" "github.com/alecthomas/repr" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/formatters" @@ -50,11 +49,11 @@ func TestGlobs(t *testing.T) { config := lexer.Config() for _, glob := range config.Filenames { _, err := filepath.Match(glob, filename) - require.NoError(t, err) + assert.NoError(t, err) } for _, glob := range config.AliasFilenames { _, err := filepath.Match(glob, filename) - require.NoError(t, err) + assert.NoError(t, err) } } } @@ -110,7 +109,7 @@ func TestLexers(t *testing.T) { if file.IsDir() { dirname := filepath.Join("testdata", file.Name()) lexer := lexers.Get(file.Name()) - assert.NotNil(t, lexer) + assert.NotZero(t, lexer) subFiles, err := ioutil.ReadDir(dirname) assert.NoError(t, err) @@ -135,7 +134,7 @@ func TestLexers(t *testing.T) { base := strings.Split(strings.TrimSuffix(file.Name(), filepath.Ext(file.Name())), ".")[0] lexer := lexers.Get(base) - assert.NotNil(t, lexer, base) + assert.NotZero(t, lexer, base) filename := filepath.Join("testdata", file.Name()) expectedFilename := strings.TrimSuffix(filename, filepath.Ext(filename)) + ".expected" @@ -187,7 +186,7 @@ func TestLexersTextAnalyser(t *testing.T) { lexerName := strings.Split(baseFilename, ".")[0] lexer := lexers.Get(lexerName) - assert.NotNil(t, lexer, "no lexer found for name %q", lexerName) + assert.NotZero(t, lexer, "no lexer found for name %q", lexerName) expectedFilepath := "testdata/analysis/" + baseFilename + ".expected" diff --git a/mutators_test.go b/mutators_test.go index 6b6c75853..ca346c24f 100644 --- a/mutators_test.go +++ b/mutators_test.go @@ -3,7 +3,7 @@ package chroma import ( "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" ) func TestInclude(t *testing.T) { diff --git a/regexp_test.go b/regexp_test.go index cc2dcd832..3cb746df3 100644 --- a/regexp_test.go +++ b/regexp_test.go @@ -3,15 +3,14 @@ package chroma import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + assert "github.com/alecthomas/assert/v2" ) func mustNewLexer(t *testing.T, config *Config, rules Rules) *RegexLexer { // nolint: forbidigo lexer, err := NewLexer(config, func() Rules { return rules }) - require.NoError(t, err) + assert.NoError(t, err) return lexer } diff --git a/remap.go b/remap.go index 440761be7..bcf5e66d1 100644 --- a/remap.go +++ b/remap.go @@ -60,10 +60,10 @@ type TypeMapping []struct { // // eg. Map "defvaralias" tokens of type NameVariable to NameFunction: // -// mapping := TypeMapping{ -// {NameVariable, NameFunction, []string{"defvaralias"}, -// } -// lexer = TypeRemappingLexer(lexer, mapping) +// mapping := TypeMapping{ +// {NameVariable, NameFunction, []string{"defvaralias"}, +// } +// lexer = TypeRemappingLexer(lexer, mapping) func TypeRemappingLexer(lexer Lexer, mapping TypeMapping) Lexer { // Lookup table for fast remapping. lut := map[TokenType]map[string]TokenType{} diff --git a/remap_test.go b/remap_test.go index 4f9cc7c7f..3b76c42db 100644 --- a/remap_test.go +++ b/remap_test.go @@ -3,7 +3,7 @@ package chroma import ( "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" ) func TestRemappingLexer(t *testing.T) { diff --git a/serialise.go b/serialise.go index 0369639f9..084396b55 100644 --- a/serialise.go +++ b/serialise.go @@ -15,42 +15,42 @@ import ( // Serialisation of Chroma rules to XML. The format is: // -// -// -// -// [<$EMITTER ...>] -// [<$MUTATOR ...>] -// -// -// +// +// +// +// [<$EMITTER ...>] +// [<$MUTATOR ...>] +// +// +// // // eg. Include("String") would become: // -// -// -// +// +// +// // -// [null, null, {"kind": "include", "state": "String"}] +// [null, null, {"kind": "include", "state": "String"}] // // eg. Rule{`\d+`, Text, nil} would become: // -// -// -// +// +// +// // // eg. Rule{`"`, String, Push("String")} // -// -// -// -// +// +// +// +// // // eg. Rule{`(\w+)(\n)`, ByGroups(Keyword, Whitespace), nil}, // -// -// -// -// +// +// +// +// var ( // ErrNotSerialisable is returned if a lexer contains Rules that cannot be serialised. ErrNotSerialisable = fmt.Errorf("not serialisable") diff --git a/serialise_test.go b/serialise_test.go index ea78df165..558e5d490 100644 --- a/serialise_test.go +++ b/serialise_test.go @@ -8,7 +8,7 @@ import ( "regexp" "testing" - "github.com/stretchr/testify/require" + assert "github.com/alecthomas/assert/v2" ) func TestEmitterSerialisationRoundTrip(t *testing.T) { @@ -26,12 +26,12 @@ func TestEmitterSerialisationRoundTrip(t *testing.T) { // nolint: scopelint t.Run(test.name, func(t *testing.T) { data, err := xml.Marshal(test.emitter) - require.NoError(t, err) + assert.NoError(t, err) t.Logf("%s", data) value, target := newFromTemplate(test.emitter) err = xml.Unmarshal(data, target) - require.NoError(t, err) - require.Equal(t, test.emitter, value()) + assert.NoError(t, err) + assert.Equal(t, test.emitter, value().(Emitter)) }) } } @@ -51,12 +51,12 @@ func TestMutatorSerialisationRoundTrip(t *testing.T) { // nolint: scopelint t.Run(test.name, func(t *testing.T) { data, err := xml.Marshal(test.mutator) - require.NoError(t, err) + assert.NoError(t, err) t.Logf("%s", data) value, target := newFromTemplate(test.mutator) err = xml.Unmarshal(data, target) - require.NoError(t, err) - require.Equal(t, test.mutator, value()) + assert.NoError(t, err) + assert.Equal(t, test.mutator, value().(Mutator)) }) } } @@ -94,17 +94,17 @@ func TestMarshal(t *testing.T) { } }) data, err := Marshal(actual) - require.NoError(t, err) + assert.NoError(t, err) expected, err := Unmarshal(data) - require.NoError(t, err) - require.Equal(t, expected.Config(), actual.Config()) - require.Equal(t, mustRules(t, expected), mustRules(t, actual)) + assert.NoError(t, err) + assert.Equal(t, expected.Config(), actual.Config()) + assert.Equal(t, mustRules(t, expected), mustRules(t, actual)) } func mustRules(t testing.TB, r *RegexLexer) Rules { t.Helper() rules, err := r.Rules() - require.NoError(t, err) + assert.NoError(t, err) return rules } @@ -116,12 +116,12 @@ func TestRuleSerialisation(t *testing.T) { } for _, test := range tests { data, err := xml.Marshal(test) - require.NoError(t, err) + assert.NoError(t, err) t.Log(string(data)) actual := Rule{} err = xml.Unmarshal(data, &actual) - require.NoError(t, err) - require.Equal(t, test, actual) + assert.NoError(t, err) + assert.Equal(t, test, actual) } } @@ -152,7 +152,7 @@ func TestRulesSerialisation(t *testing.T) { }, } data, err := xml.MarshalIndent(expected, " ", " ") - require.NoError(t, err) + assert.NoError(t, err) re := regexp.MustCompile(`>`) data = re.ReplaceAll(data, []byte(`/>`)) b := &bytes.Buffer{} @@ -161,6 +161,6 @@ func TestRulesSerialisation(t *testing.T) { w.Close() actual := Rules{} err = xml.Unmarshal(data, &actual) - require.NoError(t, err) - require.Equal(t, expected, actual) + assert.NoError(t, err) + assert.Equal(t, expected, actual) } diff --git a/style_test.go b/style_test.go index c3952765e..7e4835fe3 100644 --- a/style_test.go +++ b/style_test.go @@ -3,7 +3,7 @@ package chroma import ( "testing" - "github.com/stretchr/testify/assert" + assert "github.com/alecthomas/assert/v2" ) func TestStyleInherit(t *testing.T) { @@ -82,19 +82,19 @@ func TestStyleBuilderTransform(t *testing.T) { se.Colour = se.Colour.ClampBrightness(0.9, 1) return se }).Build() - assert.Nilf(t, err, "Transform failed: %v", err) - assert.GreaterOrEqual(t, light.Get(Name).Colour.Brightness(), 0.89) - assert.GreaterOrEqual(t, light.Get(NameVariable).Colour.Brightness(), 0.89) - assert.GreaterOrEqual(t, light.Get(NameVariableGlobal).Colour.Brightness(), 0.89) + assert.NoError(t, err, "Transform failed: %v", err) + assert.True(t, light.Get(Name).Colour.Brightness() >= 0.89) + assert.True(t, light.Get(NameVariable).Colour.Brightness() >= 0.89) + assert.True(t, light.Get(NameVariableGlobal).Colour.Brightness() >= 0.89) dark, err := deriv.Builder().Transform(func(se StyleEntry) StyleEntry { se.Colour = se.Colour.ClampBrightness(0, 0.1) return se }).Build() - assert.Nilf(t, err, "Transform failed: %v", err) - assert.LessOrEqual(t, dark.Get(Name).Colour.Brightness(), 0.11) - assert.LessOrEqual(t, dark.Get(NameVariable).Colour.Brightness(), 0.11) - assert.LessOrEqual(t, dark.Get(NameVariableGlobal).Colour.Brightness(), 0.11) + assert.NoError(t, err, "Transform failed: %v", err) + assert.True(t, dark.Get(Name).Colour.Brightness() <= 0.11) + assert.True(t, dark.Get(NameVariable).Colour.Brightness() <= 0.11) + assert.True(t, dark.Get(NameVariableGlobal).Colour.Brightness() <= 0.11) // The original styles should be unchanged. assert.Equal(t, "#000000", orig.Get(Name).Colour.String())