-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathevaluations_test.go
43 lines (36 loc) · 995 Bytes
/
evaluations_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
package tagexpressions
import (
"fmt"
"gopkg.in/yaml.v3"
"io/ioutil"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
type Evaluation struct {
Expression string `yaml:"expression"`
Tests []Test `yaml:"tests"`
}
type Test struct {
Variables []string `yaml:"variables"`
Result bool `yaml:"result"`
}
func TestEvaluations(t *testing.T) {
contents, err := ioutil.ReadFile("../testdata/evaluations.yml")
require.NoError(t, err)
var evaluations []Evaluation
err = yaml.Unmarshal(contents, &evaluations)
require.NoError(t, err)
for _, evaluation := range evaluations {
for _, test := range evaluation.Tests {
variables := strings.Join(test.Variables, ", ")
name := fmt.Sprintf("evaluates [%s] to %t", variables, test.Result)
t.Run(name, func(t *testing.T) {
expression, err := Parse(evaluation.Expression)
require.NoError(t, err)
result := expression.Evaluate(test.Variables)
require.Equal(t, test.Result, result)
})
}
}
}