-
-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathcontext_test.go
More file actions
70 lines (58 loc) · 1.57 KB
/
Copy pathcontext_test.go
File metadata and controls
70 lines (58 loc) · 1.57 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
package pongo2
import "testing"
func TestSetAutoescape(t *testing.T) {
original := DefaultSet.autoescape
SetAutoescape(false)
if DefaultSet.autoescape != false {
t.Error("SetAutoescape(false) did not set autoescape to false")
}
SetAutoescape(true)
if DefaultSet.autoescape != true {
t.Error("SetAutoescape(true) did not set autoescape to true")
}
SetAutoescape(original)
}
func TestExecutionContextLogf(t *testing.T) {
set := NewSet("test-logf", &DummyLoader{})
set.Debug = true
tpl, err := set.FromString("test")
if err != nil {
t.Fatalf("Failed to create template: %v", err)
}
ctx := newExecutionContext(tpl, Context{})
ctx.Logf("test message %s", "arg")
}
func TestIsValidIdentifier(t *testing.T) {
tests := []struct {
name string
input string
expected bool
}{
{"empty string", "", false},
{"valid identifier", "foo", true},
{"valid with underscore", "foo_bar", true},
{"valid with numbers", "foo123", true},
{"valid single char", "x", true},
{"invalid with hyphen", "foo-bar", false},
{"invalid with dot", "foo.bar", false},
{"invalid with space", "foo bar", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := isValidIdentifier(tt.input)
if result != tt.expected {
t.Errorf("isValidIdentifier(%q) = %v, want %v", tt.input, result, tt.expected)
}
})
}
}
func TestCheckForValidIdentifiersWithEmptyKey(t *testing.T) {
ctx := Context{
"": "some value",
"foo": "bar",
}
err := ctx.checkForValidIdentifiers()
if err == nil {
t.Error("expected error for empty key, got nil")
}
}