-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomparison_test.go
More file actions
103 lines (95 loc) · 2.13 KB
/
Copy pathcomparison_test.go
File metadata and controls
103 lines (95 loc) · 2.13 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package jinja
import (
"testing"
)
func TestComparisons(t *testing.T) {
tests := []struct {
name string
expr string
context map[string]interface{}
expected interface{}
}{
// Integer comparisons
{
name: "int greater than",
expr: "a > b",
context: map[string]interface{}{"a": 40, "b": 0},
expected: true,
},
{
name: "int equal",
expr: "a == b",
context: map[string]interface{}{"a": 42, "b": 42},
expected: true,
},
{
name: "int not equal",
expr: "a != b",
context: map[string]interface{}{"a": 40, "b": 0},
expected: true,
},
// String comparisons
{
name: "string less than",
expr: "a < b",
context: map[string]interface{}{"a": "apple", "b": "banana"},
expected: true,
},
{
name: "string equal",
expr: "a == b",
context: map[string]interface{}{"a": "hello", "b": "hello"},
expected: true,
},
// Mixed type comparisons
{
name: "int vs float",
expr: "a == b",
context: map[string]interface{}{"a": 42, "b": 42.0},
expected: true,
},
{
name: "int vs float greater",
expr: "a > b",
context: map[string]interface{}{"a": 43, "b": 42.5},
expected: true,
},
// Boolean comparisons
{
name: "bool equal",
expr: "a == b",
context: map[string]interface{}{"a": true, "b": true},
expected: true,
},
{
name: "bool less than",
expr: "a < b",
context: map[string]interface{}{"a": false, "b": true},
expected: true,
},
// Nested attribute comparison (like the original bug)
{
name: "nested attribute comparison",
expr: "stat_result.stat.size > 0",
context: map[string]interface{}{
"stat_result": map[string]interface{}{
"stat": map[string]interface{}{
"size": 40,
},
},
},
expected: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := EvaluateExpression(tt.expr, tt.context)
if err != nil {
t.Fatalf("EvaluateExpression failed: %v", err)
}
if result != tt.expected {
t.Errorf("Expected %v, got %v", tt.expected, result)
}
})
}
}