Add tests for previously-untested strings BIFs

This commit is contained in:
Daniel Thayer 2012-05-23 16:34:03 -05:00
parent 60df9582d3
commit 94e850397b
38 changed files with 388 additions and 25 deletions

View file

@ -0,0 +1 @@
11

View file

@ -0,0 +1,3 @@
isatest
thisisatest
isa

View file

@ -0,0 +1 @@
llo t

View file

@ -0,0 +1,10 @@
12
Test \0string
13
Test \0string
15
Test \x00string
13
Test \0string
24
546573742000737472696e67

View file

@ -0,0 +1,4 @@
es
hi
-------------------
0

View file

@ -0,0 +1,3 @@
es
-------------------
0

View 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

View file

@ -0,0 +1 @@
this * is * a * test

View file

@ -0,0 +1,2 @@
this is a test
THIS IS A TEST

View file

@ -0,0 +1,4 @@
a
is
test
this

View 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

View file

@ -0,0 +1,4 @@
24
echo ${TEST} > "my file"
27
echo \${TEST} > \"my file\"

View file

@ -0,0 +1,3 @@
T
T
T

View file

@ -0,0 +1,3 @@
*\0* 1
*t\0* 2
*test test\0* 10

View file

@ -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
}

View file

@ -0,0 +1,6 @@
* this is a test *
*this is a test*
**
**
* *
**

View file

@ -0,0 +1,2 @@
2
0

View file

@ -0,0 +1,2 @@
that is a test
that at a test

View file

@ -0,0 +1 @@
that at another test

View 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);
}

View 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);
}

View 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");
}

View 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;
}

View 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|;
}

View 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|;
}

View 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);
}

View 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, "__");
}

View 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);
}

View 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];
}

View 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];
}

View 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;
}

View 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;
}

View 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|);
}

View file

@ -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, /=/);
}

View 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));
}

View 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);
}

View 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");
}

View 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);
}