-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathless_processor_test.go
More file actions
71 lines (55 loc) · 2.27 KB
/
Copy pathless_processor_test.go
File metadata and controls
71 lines (55 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package vuego_test
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/require"
"github.com/titpetric/vuego"
)
var _ vuego.NodeProcessor = &vuego.LessProcessor{}
// TestLessProcessor_LessCompilation tests LESS compilation in <style type="text/css+less"> tags.
func TestLessProcessor_LessCompilation(t *testing.T) {
// Create a test filesystem with a simple template
templateFS := os.DirFS("testdata/nodeprocessor")
// Create Vue instance and register the LESS processor
v := vuego.NewVue(templateFS)
v.RegisterNodeProcessor(vuego.NewLessProcessor())
// Render the template
var buf bytes.Buffer
err := v.Render(t.Context(), &buf, "less.html", map[string]any{})
require.NoError(t, err)
// Verify the output contains compiled CSS instead of LESS
output := buf.String()
t.Logf("Output:\n%s", output)
require.Contains(t, output, `<style type="text/css">`)
require.NotContains(t, output, `type="text/css+less"`)
require.Contains(t, output, "color: red;")
}
// TestLessProcessor_LessVariables tests LESS variable compilation.
func TestLessProcessor_LessVariables(t *testing.T) {
templateFS := os.DirFS("testdata/nodeprocessor")
v := vuego.NewVue(templateFS)
v.RegisterNodeProcessor(vuego.NewLessProcessor())
var buf bytes.Buffer
err := v.Render(t.Context(), &buf, "less_variables.html", map[string]any{})
require.NoError(t, err)
output := buf.String()
require.Contains(t, output, `<style type="text/css">`)
// LESS variables should be compiled to actual values
require.Contains(t, output, "#ff0000") // @primary-color: #ff0000 should be compiled
}
// TestLessProcessor_NoLessTag tests that normal style tags are unaffected.
func TestLessProcessor_NoLessTag(t *testing.T) {
templateFS := os.DirFS("testdata/nodeprocessor")
v := vuego.NewVue(templateFS)
v.RegisterNodeProcessor(vuego.NewLessProcessor())
var buf bytes.Buffer
err := v.Render(t.Context(), &buf, "mixed_styles.html", map[string]any{})
require.NoError(t, err)
output := buf.String()
// Normal style tags should remain unchanged, LESS tags should be compiled to type="text/css"
require.Contains(t, output, `<style type="text/css">`)
require.NotContains(t, output, `type="text/css+less"`)
// Verify LESS compilation worked (LESS variables should be compiled)
require.Contains(t, output, "color: #333;")
}