1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-07-05 00:38:52 +02:00

Upgrade project to Go 1.19 and switch to alecthomas/assert/v2

This commit is contained in:
Alec Thomas
2022-10-17 20:46:53 +11:00
parent b338844a9a
commit 40b7a9135a
29 changed files with 127 additions and 133 deletions

View File

@ -37,6 +37,17 @@ linters:
- wrapcheck
- stylecheck
- thelper
- nonamedreturns
- revive
- dupword
- exhaustruct
- varnamelen
- forcetypeassert
- ireturn
- maintidx
- govet
- nosnakecase
- testableexamples
linters-settings:
govet:

2
bin/go
View File

@ -1 +1 @@
.go@1.17.pkg
.go-1.19.2.pkg

View File

@ -1 +1 @@
.go@1.17.pkg
.go-1.19.2.pkg

View File

@ -1 +1 @@
.golangci-lint-1.37.0.pkg
.golangci-lint-1.50.0.pkg

View File

@ -1,6 +1,6 @@
module github.com/alecthomas/chroma/v2/cmd/chroma
go 1.17
go 1.19
replace github.com/alecthomas/chroma/v2 => ../../

View File

@ -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=

View File

@ -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

View File

@ -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=

View File

@ -3,7 +3,7 @@ package chroma
import (
"testing"
"github.com/stretchr/testify/assert"
assert "github.com/alecthomas/assert/v2"
)
func TestCoalesce(t *testing.T) {

View File

@ -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))
}

View File

@ -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) {

View File

@ -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, `<pre.*style=".*background-color:[^;]+;-moz-tab-size:4;-o-tab-size:4;tab-size:4;[^"]*".+`, buf.String())
assert.True(t, regexp.MustCompile(`<pre.*style=".*background-color:[^;]+;-moz-tab-size:4;-o-tab-size:4;tab-size:4;[^"]*".+`).MatchString(buf.String()))
}
func TestWithCustomCSS(t *testing.T) {
@ -129,7 +130,7 @@ func TestWithCustomCSS(t *testing.T) {
err = f.Format(&buf, styles.Fallback, it)
assert.NoError(t, err)
assert.Regexp(t, `<span style="display:flex;display:inline;"><span><span style=".*">echo</span> FOO</span></span>`, buf.String())
assert.True(t, regexp.MustCompile(`<span style="display:flex;display:inline;"><span><span style=".*">echo</span> FOO</span></span>`).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, ` <span style=".*;background:blue;color:tomato;">&#34;FOO&#34;</span>`, buf.String())
assert.True(t, regexp.MustCompile(` <span style=".*;background:blue;color:tomato;">&#34;FOO&#34;</span>`).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, `<pre.*style=".*white-space:pre-wrap;word-break:break-word;`, buf.String())
assert.True(t, regexp.MustCompile(`<pre.*style=".*white-space:pre-wrap;word-break:break-word;`).MatchString(buf.String()))
}
func TestHighlightLines(t *testing.T) {
@ -192,9 +193,9 @@ func TestPreWrapper(t *testing.T) {
err = f.Format(&buf, styles.Fallback, it)
assert.NoError(t, err)
assert.Regexp(t, "<body class=\"bg\">\n<pre.*class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"nb\">echo</span> FOO</span></span></code></pre>\n</body>\n</html>", buf.String())
assert.Regexp(t, `\.bg { .+ }`, buf.String())
assert.Regexp(t, `\.chroma { .+ }`, buf.String())
assert.True(t, regexp.MustCompile("<body class=\"bg\">\n<pre.*class=\"chroma\"><code><span class=\"line\"><span class=\"cl\"><span class=\"nb\">echo</span> FOO</span></span></code></pre>\n</body>\n</html>").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, `<code style=".+?"><span style=".+?">echo</span> FOO</code>`, s)
assert.True(t, regexp.MustCompile(`<code style=".+?"><span style=".+?">echo</span> FOO</code>`).MatchString(s))
})
t.Run("Wrapper", func(t *testing.T) {

View File

@ -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) {

10
go.mod
View File

@ -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

19
go.sum
View File

@ -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=

View File

@ -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)
}

View File

@ -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"

View File

@ -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) {

View File

@ -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"

View File

@ -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"

View File

@ -3,7 +3,7 @@ package chroma
import (
"testing"
"github.com/stretchr/testify/assert"
assert "github.com/alecthomas/assert/v2"
)
func TestInclude(t *testing.T) {

View File

@ -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
}

View File

@ -3,7 +3,7 @@ package chroma
import (
"testing"
"github.com/stretchr/testify/assert"
assert "github.com/alecthomas/assert/v2"
)
func TestRemappingLexer(t *testing.T) {

View File

@ -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(`></[a-zA-Z]+>`)
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)
}

View File

@ -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())