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:
@ -37,6 +37,17 @@ linters:
|
|||||||
- wrapcheck
|
- wrapcheck
|
||||||
- stylecheck
|
- stylecheck
|
||||||
- thelper
|
- thelper
|
||||||
|
- nonamedreturns
|
||||||
|
- revive
|
||||||
|
- dupword
|
||||||
|
- exhaustruct
|
||||||
|
- varnamelen
|
||||||
|
- forcetypeassert
|
||||||
|
- ireturn
|
||||||
|
- maintidx
|
||||||
|
- govet
|
||||||
|
- nosnakecase
|
||||||
|
- testableexamples
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
govet:
|
govet:
|
||||||
|
@ -1 +1 @@
|
|||||||
.golangci-lint-1.37.0.pkg
|
.golangci-lint-1.50.0.pkg
|
@ -1,6 +1,6 @@
|
|||||||
module github.com/alecthomas/chroma/v2/cmd/chroma
|
module github.com/alecthomas/chroma/v2/cmd/chroma
|
||||||
|
|
||||||
go 1.17
|
go 1.19
|
||||||
|
|
||||||
replace github.com/alecthomas/chroma/v2 => ../../
|
replace github.com/alecthomas/chroma/v2 => ../../
|
||||||
|
|
||||||
|
@ -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 h1:URDISCI96MIgcIlQyoCAlhOmrSw6pZScBNkctg8r0W0=
|
||||||
github.com/alecthomas/kong v0.2.17/go.mod h1:ka3VZ8GZNPXv9Ov+j4YNLkI8mTuhXyr/0ktSlqIydQQ=
|
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.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
|
||||||
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/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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
|
||||||
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
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 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module github.com/alecthomas/chroma/v2/cmd/chromad
|
module github.com/alecthomas/chroma/v2/cmd/chromad
|
||||||
|
|
||||||
go 1.17
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alecthomas/chroma/v2 v2.0.0-00010101000000-000000000000
|
github.com/alecthomas/chroma/v2 v2.0.0-00010101000000-000000000000
|
||||||
|
@ -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.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 h1:Y0ZBCHAvHhTHw7FFJ2FzCAAG4pkbTgA45nc7BpMhDNk=
|
||||||
github.com/alecthomas/kong v0.2.4/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq+lElKxE=
|
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 h1:l1+pkGJm2BtRJF9dCq9hw6KZWEanteY4Ar9suW3Qm0g=
|
||||||
github.com/alecthomas/kong-hcl v0.2.0/go.mod h1:S5D46RHGG8Ubdxk8TuXBT9wndShsA8/JYSxxiI9y01Y=
|
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.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
|
||||||
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/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
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/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 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/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 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
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/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.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 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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.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=
|
|
||||||
|
@ -3,7 +3,7 @@ package chroma
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCoalesce(t *testing.T) {
|
func TestCoalesce(t *testing.T) {
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestColourRGB(t *testing.T) {
|
func TestColourRGB(t *testing.T) {
|
||||||
@ -62,12 +62,10 @@ func hue(c Colour) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestColourClampBrightness(t *testing.T) {
|
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.
|
// Start with a colour with a brightness close to 0.5.
|
||||||
initial := NewColour(0, 128, 255)
|
initial := NewColour(0, 128, 255)
|
||||||
br := initial.Brightness()
|
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.
|
// 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())
|
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
|
// Clamping to a brighter or darker range should produce the requested
|
||||||
// brightness while preserving the colour's hue.
|
// brightness while preserving the colour's hue.
|
||||||
brighter := initial.ClampBrightness(0.75, 1)
|
brighter := initial.ClampBrightness(0.75, 1)
|
||||||
assert.InDelta(t, 0.75, brighter.Brightness(), delta)
|
assertInDelta(t, 0.75, brighter.Brightness())
|
||||||
assert.InDelta(t, hue(initial), hue(brighter), delta)
|
assertInDelta(t, hue(initial), hue(brighter))
|
||||||
|
|
||||||
darker := initial.ClampBrightness(0, 0.25)
|
darker := initial.ClampBrightness(0, 0.25)
|
||||||
assert.InDelta(t, 0.25, darker.Brightness(), delta)
|
assertInDelta(t, 0.25, darker.Brightness())
|
||||||
assert.InDelta(t, hue(initial), hue(darker), delta)
|
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))
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package chroma
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeDelegationTestLexers(t *testing.T) (lang Lexer, root Lexer) {
|
func makeDelegationTestLexers(t *testing.T) (lang Lexer, root Lexer) {
|
||||||
|
@ -4,10 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
"github.com/alecthomas/chroma/v2/lexers"
|
"github.com/alecthomas/chroma/v2/lexers"
|
||||||
@ -117,7 +118,7 @@ func TestTabWidthStyle(t *testing.T) {
|
|||||||
err = f.Format(&buf, styles.Fallback, it)
|
err = f.Format(&buf, styles.Fallback, it)
|
||||||
assert.NoError(t, err)
|
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) {
|
func TestWithCustomCSS(t *testing.T) {
|
||||||
@ -129,7 +130,7 @@ func TestWithCustomCSS(t *testing.T) {
|
|||||||
err = f.Format(&buf, styles.Fallback, it)
|
err = f.Format(&buf, styles.Fallback, it)
|
||||||
assert.NoError(t, err)
|
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) {
|
func TestWithCustomCSSStyleInheritance(t *testing.T) {
|
||||||
@ -144,7 +145,7 @@ func TestWithCustomCSSStyleInheritance(t *testing.T) {
|
|||||||
err = f.Format(&buf, styles.Fallback, it)
|
err = f.Format(&buf, styles.Fallback, it)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Regexp(t, ` <span style=".*;background:blue;color:tomato;">"FOO"</span>`, buf.String())
|
assert.True(t, regexp.MustCompile(` <span style=".*;background:blue;color:tomato;">"FOO"</span>`).MatchString(buf.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWrapLongLines(t *testing.T) {
|
func TestWrapLongLines(t *testing.T) {
|
||||||
@ -156,7 +157,7 @@ func TestWrapLongLines(t *testing.T) {
|
|||||||
err = f.Format(&buf, styles.Fallback, it)
|
err = f.Format(&buf, styles.Fallback, it)
|
||||||
assert.NoError(t, err)
|
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) {
|
func TestHighlightLines(t *testing.T) {
|
||||||
@ -192,9 +193,9 @@ func TestPreWrapper(t *testing.T) {
|
|||||||
err = f.Format(&buf, styles.Fallback, it)
|
err = f.Format(&buf, styles.Fallback, it)
|
||||||
assert.NoError(t, err)
|
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.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.Regexp(t, `\.bg { .+ }`, buf.String())
|
assert.True(t, regexp.MustCompile(`\.bg { .+ }`).MatchString(buf.String()))
|
||||||
assert.Regexp(t, `\.chroma { .+ }`, buf.String())
|
assert.True(t, regexp.MustCompile(`\.chroma { .+ }`).MatchString(buf.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinkeableLineNumbers(t *testing.T) {
|
func TestLinkeableLineNumbers(t *testing.T) {
|
||||||
@ -306,7 +307,7 @@ func TestWithPreWrapper(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("InlineCode, inline styles", func(t *testing.T) {
|
t.Run("InlineCode, inline styles", func(t *testing.T) {
|
||||||
s := format(New(InlineCode(true)))
|
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) {
|
t.Run("Wrapper", func(t *testing.T) {
|
||||||
|
@ -3,8 +3,8 @@ package formatters
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
assert "github.com/alecthomas/assert/v2"
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClosestColour(t *testing.T) {
|
func TestClosestColour(t *testing.T) {
|
||||||
|
10
go.mod
10
go.mod
@ -1,15 +1,11 @@
|
|||||||
module github.com/alecthomas/chroma/v2
|
module github.com/alecthomas/chroma/v2
|
||||||
|
|
||||||
go 1.17
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/alecthomas/assert/v2 v2.2.0
|
||||||
github.com/alecthomas/repr v0.1.0
|
github.com/alecthomas/repr v0.1.0
|
||||||
github.com/dlclark/regexp2 v1.4.0
|
github.com/dlclark/regexp2 v1.4.0
|
||||||
github.com/stretchr/testify v1.8.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require github.com/hexops/gotextdiff v1.0.3 // indirect
|
||||||
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
|
|
||||||
)
|
|
||||||
|
19
go.sum
19
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 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
|
||||||
github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
|
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 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
|
||||||
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
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/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
|
||||||
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=
|
|
||||||
|
@ -3,13 +3,13 @@ package chroma
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTokenTypeClassifiers(t *testing.T) {
|
func TestTokenTypeClassifiers(t *testing.T) {
|
||||||
require.True(t, GenericDeleted.InCategory(Generic))
|
assert.True(t, GenericDeleted.InCategory(Generic))
|
||||||
require.True(t, LiteralStringBacktick.InSubCategory(String))
|
assert.True(t, LiteralStringBacktick.InSubCategory(String))
|
||||||
require.Equal(t, LiteralStringBacktick.String(), "LiteralStringBacktick")
|
assert.Equal(t, LiteralStringBacktick.String(), "LiteralStringBacktick")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleLexer(t *testing.T) {
|
func TestSimpleLexer(t *testing.T) {
|
||||||
@ -30,7 +30,7 @@ func TestSimpleLexer(t *testing.T) {
|
|||||||
[section]
|
[section]
|
||||||
a = 10
|
a = 10
|
||||||
`)
|
`)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
expected := []Token{
|
expected := []Token{
|
||||||
{Whitespace, "\n\t"},
|
{Whitespace, "\n\t"},
|
||||||
{Comment, "; this is a comment"},
|
{Comment, "; this is a comment"},
|
||||||
@ -44,5 +44,5 @@ func TestSimpleLexer(t *testing.T) {
|
|||||||
{LiteralString, "10"},
|
{LiteralString, "10"},
|
||||||
{Whitespace, "\n"},
|
{Whitespace, "\n"},
|
||||||
}
|
}
|
||||||
require.Equal(t, expected, actual)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package lexers_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
"github.com/alecthomas/chroma/v2/lexers"
|
"github.com/alecthomas/chroma/v2/lexers"
|
||||||
|
@ -3,8 +3,8 @@ package lexers
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
assert "github.com/alecthomas/assert/v2"
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGoHTMLTemplateIssue126(t *testing.T) {
|
func TestGoHTMLTemplateIssue126(t *testing.T) {
|
||||||
|
@ -3,7 +3,7 @@ package lexers_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
"github.com/alecthomas/chroma/v2/lexers"
|
"github.com/alecthomas/chroma/v2/lexers"
|
||||||
|
@ -9,9 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
assert "github.com/alecthomas/assert/v2"
|
||||||
"github.com/alecthomas/repr"
|
"github.com/alecthomas/repr"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
"github.com/alecthomas/chroma/v2/formatters"
|
"github.com/alecthomas/chroma/v2/formatters"
|
||||||
@ -50,11 +49,11 @@ func TestGlobs(t *testing.T) {
|
|||||||
config := lexer.Config()
|
config := lexer.Config()
|
||||||
for _, glob := range config.Filenames {
|
for _, glob := range config.Filenames {
|
||||||
_, err := filepath.Match(glob, filename)
|
_, err := filepath.Match(glob, filename)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
for _, glob := range config.AliasFilenames {
|
for _, glob := range config.AliasFilenames {
|
||||||
_, err := filepath.Match(glob, filename)
|
_, 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() {
|
if file.IsDir() {
|
||||||
dirname := filepath.Join("testdata", file.Name())
|
dirname := filepath.Join("testdata", file.Name())
|
||||||
lexer := lexers.Get(file.Name())
|
lexer := lexers.Get(file.Name())
|
||||||
assert.NotNil(t, lexer)
|
assert.NotZero(t, lexer)
|
||||||
|
|
||||||
subFiles, err := ioutil.ReadDir(dirname)
|
subFiles, err := ioutil.ReadDir(dirname)
|
||||||
assert.NoError(t, err)
|
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]
|
base := strings.Split(strings.TrimSuffix(file.Name(), filepath.Ext(file.Name())), ".")[0]
|
||||||
lexer := lexers.Get(base)
|
lexer := lexers.Get(base)
|
||||||
assert.NotNil(t, lexer, base)
|
assert.NotZero(t, lexer, base)
|
||||||
|
|
||||||
filename := filepath.Join("testdata", file.Name())
|
filename := filepath.Join("testdata", file.Name())
|
||||||
expectedFilename := strings.TrimSuffix(filename, filepath.Ext(filename)) + ".expected"
|
expectedFilename := strings.TrimSuffix(filename, filepath.Ext(filename)) + ".expected"
|
||||||
@ -187,7 +186,7 @@ func TestLexersTextAnalyser(t *testing.T) {
|
|||||||
lexerName := strings.Split(baseFilename, ".")[0]
|
lexerName := strings.Split(baseFilename, ".")[0]
|
||||||
|
|
||||||
lexer := lexers.Get(lexerName)
|
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"
|
expectedFilepath := "testdata/analysis/" + baseFilename + ".expected"
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package chroma
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInclude(t *testing.T) {
|
func TestInclude(t *testing.T) {
|
||||||
|
@ -3,15 +3,14 @@ package chroma
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustNewLexer(t *testing.T, config *Config, rules Rules) *RegexLexer { // nolint: forbidigo
|
func mustNewLexer(t *testing.T, config *Config, rules Rules) *RegexLexer { // nolint: forbidigo
|
||||||
lexer, err := NewLexer(config, func() Rules {
|
lexer, err := NewLexer(config, func() Rules {
|
||||||
return rules
|
return rules
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return lexer
|
return lexer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package chroma
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRemappingLexer(t *testing.T) {
|
func TestRemappingLexer(t *testing.T) {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEmitterSerialisationRoundTrip(t *testing.T) {
|
func TestEmitterSerialisationRoundTrip(t *testing.T) {
|
||||||
@ -26,12 +26,12 @@ func TestEmitterSerialisationRoundTrip(t *testing.T) {
|
|||||||
// nolint: scopelint
|
// nolint: scopelint
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
data, err := xml.Marshal(test.emitter)
|
data, err := xml.Marshal(test.emitter)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
t.Logf("%s", data)
|
t.Logf("%s", data)
|
||||||
value, target := newFromTemplate(test.emitter)
|
value, target := newFromTemplate(test.emitter)
|
||||||
err = xml.Unmarshal(data, target)
|
err = xml.Unmarshal(data, target)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
require.Equal(t, test.emitter, value())
|
assert.Equal(t, test.emitter, value().(Emitter))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,12 +51,12 @@ func TestMutatorSerialisationRoundTrip(t *testing.T) {
|
|||||||
// nolint: scopelint
|
// nolint: scopelint
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
data, err := xml.Marshal(test.mutator)
|
data, err := xml.Marshal(test.mutator)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
t.Logf("%s", data)
|
t.Logf("%s", data)
|
||||||
value, target := newFromTemplate(test.mutator)
|
value, target := newFromTemplate(test.mutator)
|
||||||
err = xml.Unmarshal(data, target)
|
err = xml.Unmarshal(data, target)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
require.Equal(t, test.mutator, value())
|
assert.Equal(t, test.mutator, value().(Mutator))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,17 +94,17 @@ func TestMarshal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
data, err := Marshal(actual)
|
data, err := Marshal(actual)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
expected, err := Unmarshal(data)
|
expected, err := Unmarshal(data)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
require.Equal(t, expected.Config(), actual.Config())
|
assert.Equal(t, expected.Config(), actual.Config())
|
||||||
require.Equal(t, mustRules(t, expected), mustRules(t, actual))
|
assert.Equal(t, mustRules(t, expected), mustRules(t, actual))
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustRules(t testing.TB, r *RegexLexer) Rules {
|
func mustRules(t testing.TB, r *RegexLexer) Rules {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
rules, err := r.Rules()
|
rules, err := r.Rules()
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
return rules
|
return rules
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,12 +116,12 @@ func TestRuleSerialisation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
data, err := xml.Marshal(test)
|
data, err := xml.Marshal(test)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
t.Log(string(data))
|
t.Log(string(data))
|
||||||
actual := Rule{}
|
actual := Rule{}
|
||||||
err = xml.Unmarshal(data, &actual)
|
err = xml.Unmarshal(data, &actual)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
require.Equal(t, test, actual)
|
assert.Equal(t, test, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ func TestRulesSerialisation(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
data, err := xml.MarshalIndent(expected, " ", " ")
|
data, err := xml.MarshalIndent(expected, " ", " ")
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
re := regexp.MustCompile(`></[a-zA-Z]+>`)
|
re := regexp.MustCompile(`></[a-zA-Z]+>`)
|
||||||
data = re.ReplaceAll(data, []byte(`/>`))
|
data = re.ReplaceAll(data, []byte(`/>`))
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
@ -161,6 +161,6 @@ func TestRulesSerialisation(t *testing.T) {
|
|||||||
w.Close()
|
w.Close()
|
||||||
actual := Rules{}
|
actual := Rules{}
|
||||||
err = xml.Unmarshal(data, &actual)
|
err = xml.Unmarshal(data, &actual)
|
||||||
require.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
require.Equal(t, expected, actual)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package chroma
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
assert "github.com/alecthomas/assert/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStyleInherit(t *testing.T) {
|
func TestStyleInherit(t *testing.T) {
|
||||||
@ -82,19 +82,19 @@ func TestStyleBuilderTransform(t *testing.T) {
|
|||||||
se.Colour = se.Colour.ClampBrightness(0.9, 1)
|
se.Colour = se.Colour.ClampBrightness(0.9, 1)
|
||||||
return se
|
return se
|
||||||
}).Build()
|
}).Build()
|
||||||
assert.Nilf(t, err, "Transform failed: %v", err)
|
assert.NoError(t, err, "Transform failed: %v", err)
|
||||||
assert.GreaterOrEqual(t, light.Get(Name).Colour.Brightness(), 0.89)
|
assert.True(t, light.Get(Name).Colour.Brightness() >= 0.89)
|
||||||
assert.GreaterOrEqual(t, light.Get(NameVariable).Colour.Brightness(), 0.89)
|
assert.True(t, light.Get(NameVariable).Colour.Brightness() >= 0.89)
|
||||||
assert.GreaterOrEqual(t, light.Get(NameVariableGlobal).Colour.Brightness(), 0.89)
|
assert.True(t, light.Get(NameVariableGlobal).Colour.Brightness() >= 0.89)
|
||||||
|
|
||||||
dark, err := deriv.Builder().Transform(func(se StyleEntry) StyleEntry {
|
dark, err := deriv.Builder().Transform(func(se StyleEntry) StyleEntry {
|
||||||
se.Colour = se.Colour.ClampBrightness(0, 0.1)
|
se.Colour = se.Colour.ClampBrightness(0, 0.1)
|
||||||
return se
|
return se
|
||||||
}).Build()
|
}).Build()
|
||||||
assert.Nilf(t, err, "Transform failed: %v", err)
|
assert.NoError(t, err, "Transform failed: %v", err)
|
||||||
assert.LessOrEqual(t, dark.Get(Name).Colour.Brightness(), 0.11)
|
assert.True(t, dark.Get(Name).Colour.Brightness() <= 0.11)
|
||||||
assert.LessOrEqual(t, dark.Get(NameVariable).Colour.Brightness(), 0.11)
|
assert.True(t, dark.Get(NameVariable).Colour.Brightness() <= 0.11)
|
||||||
assert.LessOrEqual(t, dark.Get(NameVariableGlobal).Colour.Brightness(), 0.11)
|
assert.True(t, dark.Get(NameVariableGlobal).Colour.Brightness() <= 0.11)
|
||||||
|
|
||||||
// The original styles should be unchanged.
|
// The original styles should be unchanged.
|
||||||
assert.Equal(t, "#000000", orig.Get(Name).Colour.String())
|
assert.Equal(t, "#000000", orig.Get(Name).Colour.String())
|
||||||
|
Reference in New Issue
Block a user