mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 20:48:21 +00:00
Add tests for previously-untested strings BIFs
This commit is contained in:
parent
60df9582d3
commit
94e850397b
38 changed files with 388 additions and 25 deletions
1
testing/btest/Baseline/bifs.byte_len/out
Normal file
1
testing/btest/Baseline/bifs.byte_len/out
Normal file
|
@ -0,0 +1 @@
|
|||
11
|
3
testing/btest/Baseline/bifs.cat_string_array/out
Normal file
3
testing/btest/Baseline/bifs.cat_string_array/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
isatest
|
||||
thisisatest
|
||||
isa
|
1
testing/btest/Baseline/bifs.edit/out
Normal file
1
testing/btest/Baseline/bifs.edit/out
Normal file
|
@ -0,0 +1 @@
|
|||
llo t
|
10
testing/btest/Baseline/bifs.escape_string/out
Normal file
10
testing/btest/Baseline/bifs.escape_string/out
Normal file
|
@ -0,0 +1,10 @@
|
|||
12
|
||||
Test \0string
|
||||
13
|
||||
Test \0string
|
||||
15
|
||||
Test \x00string
|
||||
13
|
||||
Test \0string
|
||||
24
|
||||
546573742000737472696e67
|
4
testing/btest/Baseline/bifs.find_all/out
Normal file
4
testing/btest/Baseline/bifs.find_all/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
es
|
||||
hi
|
||||
-------------------
|
||||
0
|
3
testing/btest/Baseline/bifs.find_last/out
Normal file
3
testing/btest/Baseline/bifs.find_last/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
es
|
||||
-------------------
|
||||
0
|
1
testing/btest/Baseline/bifs.hexdump/out
Normal file
1
testing/btest/Baseline/bifs.hexdump/out
Normal file
|
@ -0,0 +1 @@
|
|||
0000 61 62 63 ff 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f abc.defg hijklmno^J0010 70 71 72 73 74 75 76 77 78 79 7a pqrstuvw xyz^J
|
1
testing/btest/Baseline/bifs.join_string/out
Normal file
1
testing/btest/Baseline/bifs.join_string/out
Normal file
|
@ -0,0 +1 @@
|
|||
this * is * a * test
|
2
testing/btest/Baseline/bifs.lowerupper/out
Normal file
2
testing/btest/Baseline/bifs.lowerupper/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
this is a test
|
||||
THIS IS A TEST
|
4
testing/btest/Baseline/bifs.sort_string_array/out
Normal file
4
testing/btest/Baseline/bifs.sort_string_array/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
a
|
||||
is
|
||||
test
|
||||
this
|
32
testing/btest/Baseline/bifs.split/out
Normal file
32
testing/btest/Baseline/bifs.split/out
Normal file
|
@ -0,0 +1,32 @@
|
|||
t
|
||||
s is a t
|
||||
t
|
||||
---------------------
|
||||
t
|
||||
s is a test
|
||||
---------------------
|
||||
t
|
||||
hi
|
||||
s is a t
|
||||
es
|
||||
t
|
||||
---------------------
|
||||
t
|
||||
s is a test
|
||||
---------------------
|
||||
t
|
||||
hi
|
||||
s is a test
|
||||
---------------------
|
||||
[, thi, s i, s a tes, t]
|
||||
---------------------
|
||||
X-Mailer
|
||||
Testing Test (http://www.example.com)
|
||||
---------------------
|
||||
A
|
||||
=
|
||||
B
|
||||
=
|
||||
C
|
||||
=
|
||||
D
|
4
testing/btest/Baseline/bifs.str_shell_escape/out
Normal file
4
testing/btest/Baseline/bifs.str_shell_escape/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
24
|
||||
echo ${TEST} > "my file"
|
||||
27
|
||||
echo \${TEST} > \"my file\"
|
3
testing/btest/Baseline/bifs.strcmp/out
Normal file
3
testing/btest/Baseline/bifs.strcmp/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
T
|
||||
T
|
||||
T
|
3
testing/btest/Baseline/bifs.string_fill/out
Normal file
3
testing/btest/Baseline/bifs.string_fill/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
*\0* 1
|
||||
*t\0* 2
|
||||
*test test\0* 10
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
[2] = Testing Test (http://www.example.com),
|
||||
[1] = X-Mailer
|
||||
}
|
||||
{
|
||||
[2] = =,
|
||||
[4] = =,
|
||||
[6] = =,
|
||||
[7] = D,
|
||||
[1] = A ,
|
||||
[5] = C ,
|
||||
[3] = B
|
||||
}
|
6
testing/btest/Baseline/bifs.strip/out
Normal file
6
testing/btest/Baseline/bifs.strip/out
Normal file
|
@ -0,0 +1,6 @@
|
|||
* this is a test *
|
||||
*this is a test*
|
||||
**
|
||||
**
|
||||
* *
|
||||
**
|
2
testing/btest/Baseline/bifs.strstr/out
Normal file
2
testing/btest/Baseline/bifs.strstr/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
2
|
||||
0
|
2
testing/btest/Baseline/bifs.sub/out
Normal file
2
testing/btest/Baseline/bifs.sub/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
that is a test
|
||||
that at a test
|
1
testing/btest/Baseline/bifs.subst_string/out
Normal file
1
testing/btest/Baseline/bifs.subst_string/out
Normal file
|
@ -0,0 +1 @@
|
|||
that at another test
|
10
testing/btest/bifs/byte_len.bro
Normal file
10
testing/btest/bifs/byte_len.bro
Normal file
|
@ -0,0 +1,10 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "hello\0there";
|
||||
|
||||
print byte_len(a);
|
||||
}
|
14
testing/btest/bifs/cat_string_array.bro
Normal file
14
testing/btest/bifs/cat_string_array.bro
Normal file
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a: string_array = {
|
||||
[0] = "this", [1] = "is", [2] = "a", [3] = "test"
|
||||
};
|
||||
|
||||
print cat_string_array(a);
|
||||
print cat_string_array_n(a, 0, |a|-1);
|
||||
print cat_string_array_n(a, 1, 2);
|
||||
}
|
10
testing/btest/bifs/edit.bro
Normal file
10
testing/btest/bifs/edit.bro
Normal file
|
@ -0,0 +1,10 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "hello there";
|
||||
|
||||
print edit(a, "e");
|
||||
}
|
27
testing/btest/bifs/escape_string.bro
Normal file
27
testing/btest/bifs/escape_string.bro
Normal file
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "Test \0string";
|
||||
|
||||
print |a|;
|
||||
print a;
|
||||
|
||||
local b = clean(a);
|
||||
print |b|;
|
||||
print b;
|
||||
|
||||
local c = to_string_literal(a);
|
||||
print |c|;
|
||||
print c;
|
||||
|
||||
local d = escape_string(a);
|
||||
print |d|;
|
||||
print d;
|
||||
|
||||
local e = string_to_ascii_hex(a);
|
||||
print |e|;
|
||||
print e;
|
||||
}
|
18
testing/btest/bifs/find_all.bro
Normal file
18
testing/btest/bifs/find_all.bro
Normal file
|
@ -0,0 +1,18 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this is a test";
|
||||
local pat = /hi|es/;
|
||||
local pat2 = /aa|bb/;
|
||||
|
||||
local b = find_all(a, pat);
|
||||
local b2 = find_all(a, pat2);
|
||||
|
||||
for (i in b)
|
||||
print i;
|
||||
print "-------------------";
|
||||
print |b2|;
|
||||
}
|
17
testing/btest/bifs/find_last.bro
Normal file
17
testing/btest/bifs/find_last.bro
Normal file
|
@ -0,0 +1,17 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this is a test";
|
||||
local pat = /hi|es/;
|
||||
local pat2 = /aa|bb/;
|
||||
|
||||
local b = find_last(a, pat);
|
||||
local b2 = find_last(a, pat2);
|
||||
|
||||
print b;
|
||||
print "-------------------";
|
||||
print |b2|;
|
||||
}
|
10
testing/btest/bifs/hexdump.bro
Normal file
10
testing/btest/bifs/hexdump.bro
Normal file
|
@ -0,0 +1,10 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "abc\xffdefghijklmnopqrstuvwxyz";
|
||||
|
||||
print hexdump(a);
|
||||
}
|
14
testing/btest/bifs/join_string.bro
Normal file
14
testing/btest/bifs/join_string.bro
Normal file
|
@ -0,0 +1,14 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a: string_array = {
|
||||
[1] = "this", [2] = "is", [3] = "a", [4] = "test"
|
||||
};
|
||||
local b: string_vec = vector( "this", "is", "another", "test" );
|
||||
|
||||
print join_string_array(" * ", a);
|
||||
print join_string_vec(b, "__");
|
||||
}
|
11
testing/btest/bifs/lowerupper.bro
Normal file
11
testing/btest/bifs/lowerupper.bro
Normal file
|
@ -0,0 +1,11 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this is a Test";
|
||||
|
||||
print to_lower(a);
|
||||
print to_upper(a);
|
||||
}
|
17
testing/btest/bifs/sort_string_array.bro
Normal file
17
testing/btest/bifs/sort_string_array.bro
Normal file
|
@ -0,0 +1,17 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a: string_array = {
|
||||
[1] = "this", [2] = "is", [3] = "a", [4] = "test"
|
||||
};
|
||||
|
||||
local b = sort_string_array(a);
|
||||
|
||||
print b[1];
|
||||
print b[2];
|
||||
print b[3];
|
||||
print b[4];
|
||||
}
|
59
testing/btest/bifs/split.bro
Normal file
59
testing/btest/bifs/split.bro
Normal file
|
@ -0,0 +1,59 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this is a test";
|
||||
local pat = /hi|es/;
|
||||
local idx = vector( 3, 6, 13);
|
||||
|
||||
local b = split(a, pat);
|
||||
local c = split1(a, pat);
|
||||
local d = split_all(a, pat);
|
||||
local e1 = split_n(a, pat, F, 1);
|
||||
local e2 = split_n(a, pat, T, 1);
|
||||
|
||||
print b[1];
|
||||
print b[2];
|
||||
print b[3];
|
||||
print b[4];
|
||||
print "---------------------";
|
||||
print c[1];
|
||||
print c[2];
|
||||
print "---------------------";
|
||||
print d[1];
|
||||
print d[2];
|
||||
print d[3];
|
||||
print d[4];
|
||||
print d[5];
|
||||
print "---------------------";
|
||||
print e1[1];
|
||||
print e1[2];
|
||||
print "---------------------";
|
||||
print e2[1];
|
||||
print e2[2];
|
||||
print e2[3];
|
||||
print "---------------------";
|
||||
print str_split(a, idx);
|
||||
print "---------------------";
|
||||
|
||||
a = "X-Mailer: Testing Test (http://www.example.com)";
|
||||
pat = /:[[:blank:]]*/;
|
||||
local f = split1(a, pat);
|
||||
|
||||
print f[1];
|
||||
print f[2];
|
||||
print "---------------------";
|
||||
|
||||
a = "A = B = C = D";
|
||||
pat = /=/;
|
||||
local g = split_all(a, pat);
|
||||
print g[1];
|
||||
print g[2];
|
||||
print g[3];
|
||||
print g[4];
|
||||
print g[5];
|
||||
print g[6];
|
||||
print g[7];
|
||||
}
|
15
testing/btest/bifs/str_shell_escape.bro
Normal file
15
testing/btest/bifs/str_shell_escape.bro
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "echo ${TEST} > \"my file\"";
|
||||
|
||||
print |a|;
|
||||
print a;
|
||||
|
||||
local b = str_shell_escape(a);
|
||||
print |b|;
|
||||
print b;
|
||||
}
|
13
testing/btest/bifs/strcmp.bro
Normal file
13
testing/btest/bifs/strcmp.bro
Normal file
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this";
|
||||
local b = "testing";
|
||||
|
||||
print strcmp(a, b) > 0;
|
||||
print strcmp(b, a) < 0;
|
||||
print strcmp(a, a) == 0;
|
||||
}
|
16
testing/btest/bifs/string_fill.bro
Normal file
16
testing/btest/bifs/string_fill.bro
Normal file
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "test ";
|
||||
|
||||
local b = string_fill(1, a);
|
||||
local c = string_fill(2, a);
|
||||
local d = string_fill(10, a);
|
||||
|
||||
print fmt("*%s* %d", b, |b|);
|
||||
print fmt("*%s* %d", c, |c|);
|
||||
print fmt("*%s* %d", d, |d|);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "X-Mailer: Testing Test (http://www.example.com)";
|
||||
print split1(a, /:[[:blank:]]*/);
|
||||
|
||||
a = "A = B = C = D";
|
||||
print split_all(a, /=/);
|
||||
}
|
17
testing/btest/bifs/strip.bro
Normal file
17
testing/btest/bifs/strip.bro
Normal file
|
@ -0,0 +1,17 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = " this is a test ";
|
||||
local b = "";
|
||||
local c = " ";
|
||||
|
||||
print fmt("*%s*", a);
|
||||
print fmt("*%s*", strip(a));
|
||||
print fmt("*%s*", b);
|
||||
print fmt("*%s*", strip(b));
|
||||
print fmt("*%s*", c);
|
||||
print fmt("*%s*", strip(c));
|
||||
}
|
13
testing/btest/bifs/strstr.bro
Normal file
13
testing/btest/bifs/strstr.bro
Normal file
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this is a test";
|
||||
local b = "his";
|
||||
local c = "are";
|
||||
|
||||
print strstr(a, b);
|
||||
print strstr(a, c);
|
||||
}
|
12
testing/btest/bifs/sub.bro
Normal file
12
testing/btest/bifs/sub.bro
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this is a test";
|
||||
local pat = /is|ss/;
|
||||
|
||||
print sub(a, pat, "at");
|
||||
print gsub(a, pat, "at");
|
||||
}
|
12
testing/btest/bifs/subst_string.bro
Normal file
12
testing/btest/bifs/subst_string.bro
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this is another test";
|
||||
local b = "is";
|
||||
local c = "at";
|
||||
|
||||
print subst_string(a, b, c);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue