Skip to content

Commit e6eb778

Browse files
authored
fix: inset shadow tailwind-merge v2.2.2 (#9)
* chore: installed testing lib * test: test cases for bug * fix: fixed regex
1 parent 959ab34 commit e6eb778

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module github.com/Oudwins/tailwind-merge-go
22

33
go 1.21.5
4+
5+
require github.com/stretchr/testify v1.9.0
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
6+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/twmerge/validators.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func IsTshirtSize(val string) bool {
7676
}
7777

7878
func IsShadow(val string) bool {
79-
pattern := regexp.MustCompile(`^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)`)
79+
pattern := regexp.MustCompile(`^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)`)
8080
return pattern.MatchString(val)
8181
}
8282

pkg/twmerge/validators_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package twmerge
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestArbitraryShadow(t *testing.T) {
10+
assert.Equal(t, IsArbitraryShadow("[inset_0_1px_0,inset_0_-1px_0]"), true)
11+
assert.Equal(t, IsArbitraryShadow("[0_35px_60px_-15px_rgba(0,0,0,0.3)]"), true)
12+
assert.Equal(t, IsArbitraryShadow("[inset_0_1px_0,inset_0_-1px_0]"), true)
13+
assert.Equal(t, IsArbitraryShadow("[0_0_#00f]"), true)
14+
assert.Equal(t, IsArbitraryShadow("[.5rem_0_rgba(5,5,5,5)]"), true)
15+
assert.Equal(t, IsArbitraryShadow("[-.5rem_0_#123456]"), true)
16+
assert.Equal(t, IsArbitraryShadow("[0.5rem_-0_#123456]"), true)
17+
assert.Equal(t, IsArbitraryShadow("[0.5rem_-0.005vh_#123456]"), true)
18+
assert.Equal(t, IsArbitraryShadow("[0.5rem_-0.005vh]"), true)
19+
20+
assert.Equal(t, IsArbitraryShadow("[rgba(5,5,5,5)]"), false)
21+
assert.Equal(t, IsArbitraryShadow("[#00f]"), false)
22+
assert.Equal(t, IsArbitraryShadow("[something-else]"), false)
23+
}

0 commit comments

Comments
 (0)