mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
BTests for indexing "table[pattern] of T" with strings
This commit is contained in:
parent
699549eb45
commit
fd1094a184
3 changed files with 75 additions and 0 deletions
1
testing/btest/Baseline/language.pattern-tables/.stderr
Normal file
1
testing/btest/Baseline/language.pattern-tables/.stderr
Normal file
|
@ -0,0 +1 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
18
testing/btest/Baseline/language.pattern-tables/out
Normal file
18
testing/btest/Baseline/language.pattern-tables/out
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
indexing empty, 0
|
||||||
|
single insert, match, [1]
|
||||||
|
single insert, non-match, []
|
||||||
|
multiple inserts, non-match, []
|
||||||
|
multiple inserts, single match, [3]
|
||||||
|
multiple inserts, double match, [1, 3]
|
||||||
|
triple match, [1, 3, 4]
|
||||||
|
embedded newline, /s operator, [6]
|
||||||
|
no embedded newline, /s vs. no /s operator, [5, 6, 7]
|
||||||
|
no embedded newline, case sensitive, /i vs. no /i operator, [7]
|
||||||
|
single delete, no more triple match, [1, 4]
|
||||||
|
double delete, no more double match, [4]
|
||||||
|
delete of non-existing pattern, [4]
|
||||||
|
shallow copy matches multi, [5, 6, 7]
|
||||||
|
deep copy matches multi, [5, 6, 7]
|
||||||
|
delete of entire table, []
|
||||||
|
reassignment of table, []
|
56
testing/btest/language/pattern-tables.zeek
Normal file
56
testing/btest/language/pattern-tables.zeek
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# @TEST-EXEC: zeek -b %INPUT >out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
# @TEST-EXEC: btest-diff .stderr
|
||||||
|
|
||||||
|
global pt: table[pattern] of count;
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
# test_case("indexing empty", |pt["foo"] == 0|);
|
||||||
|
print "indexing empty", |pt["foo"]|;
|
||||||
|
|
||||||
|
pt[/foo/] = 1;
|
||||||
|
|
||||||
|
print "single insert, match", pt["foo"];
|
||||||
|
print "single insert, non-match", pt["foox"];
|
||||||
|
|
||||||
|
pt[/bar/] = 2;
|
||||||
|
pt[/(foo|bletch)/] = 3;
|
||||||
|
|
||||||
|
print "multiple inserts, non-match", pt["x"];
|
||||||
|
print "multiple inserts, single match", pt["bletch"];
|
||||||
|
print "multiple inserts, double match", sort(pt["foo"]);
|
||||||
|
|
||||||
|
pt[/(foo|bletch|xyz)/] = 4;
|
||||||
|
print "triple match", sort(pt["foo"]);
|
||||||
|
|
||||||
|
pt[/dog.*cat/] = 5;
|
||||||
|
pt[/dog.*cat/s] = 6;
|
||||||
|
pt[/dog.*cat/i] = 7;
|
||||||
|
print "embedded newline, /s operator", pt["dog\ncat"];
|
||||||
|
print "no embedded newline, /s vs. no /s operator", sort(pt["dogmousecat"]);
|
||||||
|
print "no embedded newline, case sensitive, /i vs. no /i operator", sort(pt["dogmouseCat"]);
|
||||||
|
|
||||||
|
delete pt[/(foo|bletch)/];
|
||||||
|
print "single delete, no more triple match", pt["foo"];
|
||||||
|
|
||||||
|
delete pt[/bar/];
|
||||||
|
delete pt[/foo/];
|
||||||
|
print "double delete, no more double match", pt["foo"];
|
||||||
|
|
||||||
|
delete pt[/nosuchpattern/];
|
||||||
|
print "delete of non-existing pattern", pt["foo"];
|
||||||
|
|
||||||
|
local copy_pt = pt;
|
||||||
|
print "shallow copy matches multi", sort(pt["dogmousecat"]);
|
||||||
|
|
||||||
|
local deep_copy_pt = copy(pt);
|
||||||
|
print "deep copy matches multi", sort(pt["dogmousecat"]);
|
||||||
|
|
||||||
|
clear_table(pt);
|
||||||
|
print "delete of entire table", pt["foo"];
|
||||||
|
|
||||||
|
local replacement_pt: table[pattern] of count;
|
||||||
|
deep_copy_pt = replacement_pt;
|
||||||
|
print "reassignment of table", deep_copy_pt["dogmousecat"];
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue