MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / TestScanner

Function TestScanner

pkg/filter/ql/lexer_test.go:26–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestScanner(t *testing.T) {
27 var tests = []struct {
28 s string
29 tok token
30 lit string
31 pos int
32 }{
33 // special tokens
34 {s: ``, tok: EOF},
35 {s: `#`, tok: Illegal, lit: `#`},
36 {s: ` `, tok: WS, lit: " "},
37 {s: "\t", tok: WS, lit: "\t"},
38
39 // logical operators
40 {s: `AND`, tok: And},
41 {s: `and`, tok: And},
42 {s: `OR`, tok: Or},
43 {s: `or`, tok: Or},
44
45 {s: `=`, tok: Eq},
46 {s: `~=`, tok: IEq},
47 {s: `<>`, tok: Neq},
48 {s: `! `, tok: Illegal, lit: "!"},
49 {s: `<`, tok: Lt},
50 {s: `<=`, tok: Lte},
51 {s: `>`, tok: Gt},
52 {s: `>=`, tok: Gte},
53 {s: `IN`, tok: In},
54 {s: `in`, tok: In},
55
56 // misc tokens
57 {s: `(`, tok: Lparen},
58 {s: `)`, tok: Rparen},
59 {s: `,`, tok: Comma},
60 {s: `|`, tok: Pipe},
61
62 // identifiers
63 {s: `foo`, tok: Ident, lit: `foo`},
64 {s: `_foo`, tok: Ident, lit: `_foo`},
65 {s: `Zx12_3U_-`, tok: Ident, lit: `Zx12_3U_`},
66 {s: `"foo\"bar\""`, tok: Ident, lit: `foo"bar"`},
67
68 // IP address
69 {s: "172.17.0.1", tok: IP, lit: "172.17.0.1"},
70 {s: "172.17.1", tok: BadIP, lit: "172.17.1"},
71 {s: "172.317.1.2", tok: BadIP, lit: "172.317.1.2"},
72 {s: "172.2.266.2", tok: BadIP, lit: "172.2.266.2"},
73
74 // strings
75 {s: `'testing 123!'`, tok: Str, lit: `testing 123!`},
76 {s: `'foo\nbar'`, tok: Str, lit: "foo\nbar"},
77 {s: `'foo\\bar'`, tok: Str, lit: "foo\\bar"},
78
79 // numbers
80 {s: "6.2323", tok: Decimal, lit: "6.2323"},
81 }
82
83 for i, tt := range tests {

Callers

nothing calls this directly

Calls 2

newScannerFunction · 0.85
scanMethod · 0.45

Tested by

no test coverage detected