-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathtest.lua
53 lines (49 loc) · 1.12 KB
/
test.lua
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
local parser = require("overseer.parser")
local Test = {
desc = "Returns SUCCESS when the line matches the pattern",
doc_args = {
{
name = "opts",
type = "object",
desc = "Configuration options",
position_optional = true,
fields = {
{
name = "regex",
type = "boolean",
desc = "Use vim regex instead of lua pattern (see :help pattern)",
default = true,
},
},
},
{
name = "pattern",
type = "string|fun(line: string): string",
desc = "The lua pattern to use for matching, or test function",
},
},
examples = {
{
desc = [[Fail until a line starts with "panic:"]],
code = [[{"test", "^panic:"}]],
},
},
}
function Test.new(opts, pattern)
if not pattern then
pattern = opts
opts = {}
end
return setmetatable({
test = parser.util.patterns_to_test(pattern, opts.regex),
}, { __index = Test })
end
function Test:reset() end
function Test:ingest(line)
if self.test(line) then
return parser.STATUS.SUCCESS
else
return parser.STATUS.FAILURE
end
end
return Test