Manually merge from 'pre-kjol' into 'master'
This commit is contained in:
@@ -42,6 +42,71 @@ func TestEngineEdgeCases(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// @source inline(...) safelists candidates that aren't present in the scanned
|
||||
// source files at all (brace expansion covers the color/shade cross product).
|
||||
func TestSourceInlineSafelist(t *testing.T) {
|
||||
css, _, err := twCompile(
|
||||
`@import "tailwindcss";
|
||||
@source inline("{text,bg}-{red,blue}-{100,500}");`,
|
||||
".", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("twCompile error: %v", err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"color: var(--color-red-100)",
|
||||
"color: var(--color-red-500)",
|
||||
"color: var(--color-blue-100)",
|
||||
"color: var(--color-blue-500)",
|
||||
"background-color: var(--color-red-100)",
|
||||
"background-color: var(--color-blue-500)",
|
||||
} {
|
||||
if !strings.Contains(css, want) {
|
||||
t.Errorf("expected safelisted output to contain %q\n---\n%s", want, css)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// `not inline(...)` removes a candidate even if the scanner found it in source.
|
||||
func TestSourceNotInlineRemoves(t *testing.T) {
|
||||
css, _, err := twCompile(
|
||||
`@import "tailwindcss";
|
||||
@source not inline("bg-red-500");`,
|
||||
".", []string{"bg-red-500", "bg-blue-500"})
|
||||
if err != nil {
|
||||
t.Fatalf("twCompile error: %v", err)
|
||||
}
|
||||
if strings.Contains(css, "background-color: var(--color-red-500)") {
|
||||
t.Errorf("expected bg-red-500 to be excluded by `not inline`\n---\n%s", css)
|
||||
}
|
||||
if !strings.Contains(css, "background-color: var(--color-blue-500)") {
|
||||
t.Errorf("expected bg-blue-500 to remain\n---\n%s", css)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandBraces(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
want []string
|
||||
}{
|
||||
{"flex", []string{"flex"}},
|
||||
{"{a,b}", []string{"a", "b"}},
|
||||
{"{1..3}", []string{"1", "2", "3"}},
|
||||
{"{text,bg}-{red,blue}", []string{"text-red", "text-blue", "bg-red", "bg-blue"}},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := expandBraces(c.in)
|
||||
if len(got) != len(c.want) {
|
||||
t.Errorf("expandBraces(%q) = %v, want %v", c.in, got, c.want)
|
||||
continue
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != c.want[i] {
|
||||
t.Errorf("expandBraces(%q)[%d] = %q, want %q", c.in, i, got[i], c.want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSegmentTopLevel(t *testing.T) {
|
||||
cases := []struct {
|
||||
in string
|
||||
|
||||
Reference in New Issue
Block a user