forked from markuskont/go-sigma-rule-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer_test.go
51 lines (47 loc) · 1.26 KB
/
lexer_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
51
package sigma
import "testing"
type LexTestCase struct {
Expr string
Tokens []Token
}
var LexPosCases = []LexTestCase{
{
Expr: "selection",
Tokens: []Token{TokIdentifier, TokLitEof},
},
{
Expr: "selection_1 and not filter_0",
Tokens: []Token{
TokIdentifier, TokKeywordAnd, TokKeywordNot, TokIdentifier, TokLitEof,
},
},
{
Expr: "((selection_1 and not filter_0) OR (keyword_0 and not filter1)) or idontcare",
Tokens: []Token{
TokSepLpar, TokSepLpar, TokIdentifier, TokKeywordAnd, TokKeywordNot, TokIdentifier,
TokSepRpar, TokKeywordOr, TokSepLpar, TokIdentifier, TokKeywordAnd, TokKeywordNot,
TokIdentifier, TokSepRpar, TokSepRpar, TokKeywordOr, TokIdentifier, TokLitEof,
},
},
{
Expr: "all of selection* and not 1 of filter* | count() > 10",
Tokens: []Token{
TokStAll, TokIdentifierWithWildcard, TokKeywordAnd, TokKeywordNot, TokStOne,
TokIdentifierWithWildcard, TokSepPipe, TokUnsupp, TokIdentifier, TokLitEof,
},
},
}
func TestLex(t *testing.T) {
for j, c := range LexPosCases {
l := lex(c.Expr)
var i int
for item := range l.items {
if item.T != c.Tokens[i] {
t.Fatalf(
"lex case %d expr %s failed on item %d expected %s got %s",
j, c.Expr, i, c.Tokens[i].String(), item.T.String())
}
i++
}
}
}