Repository navigation
Expand file tree
/
Copy pathcorpus_diff_test.go
More file actions
54 lines (50 loc) · 1.76 KB
/
Copy pathcorpus_diff_test.go
File metadata and controls
54 lines (50 loc) · 1.76 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
package eql
import (
"fmt"
"strings"
)
// diffConditions compares expected conditions against extracted ones and
// returns a human-readable difference ("" when they match on the compared
// fields).
func diffConditions(want []ExpectedCondition, got []Condition) string {
if len(want) != len(got) {
return fmt.Sprintf("count: want %d, got %d\n want: %s\n got: %s",
len(want), len(got), fmtExpected(want), fmtGot(got))
}
for i := range want {
w, g := want[i], got[i]
if w.Field != g.Field {
return fmt.Sprintf("condition %d field: want %q, got %q", i, w.Field, g.Field)
}
if w.Operator != g.Operator {
return fmt.Sprintf("condition %d operator (field %s): want %q, got %q", i, w.Field, w.Operator, g.Operator)
}
if w.Value != g.Value {
return fmt.Sprintf("condition %d value (field %s): want %q, got %q", i, w.Field, w.Value, g.Value)
}
if w.Negated != g.Negated {
return fmt.Sprintf("condition %d negated (field %s): want %v, got %v", i, w.Field, w.Negated, g.Negated)
}
if w.SequenceStep != g.SequenceStep {
return fmt.Sprintf("condition %d step (field %s): want %d, got %d", i, w.Field, w.SequenceStep, g.SequenceStep)
}
if strings.Join(w.Alternatives, "|") != strings.Join(g.Alternatives, "|") {
return fmt.Sprintf("condition %d alternatives (field %s): want %v, got %v", i, w.Field, w.Alternatives, g.Alternatives)
}
}
return ""
}
func fmtExpected(cs []ExpectedCondition) string {
var parts []string
for _, c := range cs {
parts = append(parts, fmt.Sprintf("%s%s%s", c.Field, c.Operator, c.Value))
}
return strings.Join(parts, ", ")
}
func fmtGot(cs []Condition) string {
var parts []string
for _, c := range cs {
parts = append(parts, fmt.Sprintf("%s%s%s", c.Field, c.Operator, c.Value))
}
return strings.Join(parts, ", ")
}