-
Notifications
You must be signed in to change notification settings - Fork 0
/
expression_test.go
50 lines (47 loc) · 990 Bytes
/
expression_test.go
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
package semver
import "testing"
var exprTestBattery = map[string]map[string]bool{
"1.x || >=2.5.0 || 5.0.0 - 7.2.3": {
"1.2.3": true,
"3.0": true,
"5.45.23": true,
"2.5.0": true,
"7.2.3": true,
"5.0.0": true,
"1.0.0": true,
"0.9.3": false,
"2.4.99": false,
},
">=1.2.7 <1.3.0": {
"1.2.7": true,
"1.2.8": true,
"1.2.99": true,
"1.1.0": false,
"1.3.0": false,
"1.2.6": false,
},
"1.2.7 || >=1.2.9 <2.0.0": {
"1.2.7": true,
"1.2.9": true,
"1.4.6": true,
"1.2.8": false,
"2.0.0": false,
},
}
func TestPerseExpr(t *testing.T) {
for _, battery := range []map[string]map[string]bool{
// Ranges are still expressions
rangeTestBattery,
exprTestBattery,
} {
for exprStr, data := range battery {
e := MustParseExpr(exprStr)
for vStr, result := range data {
v := MustParseVersion(vStr)
if e.Matches(v) != result {
t.Errorf("Expected %q of %v to evaluate to %v", exprStr, v, result)
}
}
}
}
}