Add more test cases

This commit is contained in:
AmazingPP 2022-07-13 22:08:21 +08:00
parent ccc9d0a002
commit 206e6d28a4
5 changed files with 41 additions and 20 deletions

View file

@ -1193,7 +1193,7 @@ function clear_table%(v: any%): any
## Returns: A ``vector of T`` of all the values in t. ## Returns: A ``vector of T`` of all the values in t.
## ##
## .. zeek:see:: table_keys ## .. zeek:see:: table_keys
function table_values%(t: any%): any function table_values%(t: any%): any_vec
%{ %{
if ( ! t->GetType()->IsTable() ) if ( ! t->GetType()->IsTable() )
{ {
@ -1227,7 +1227,7 @@ function table_keys%(t: any%): any
} }
auto tl = t->GetType()->AsTableType()->GetIndices(); auto tl = t->GetType()->AsTableType()->GetIndices();
auto st = make_intrusive<zeek::SetType>(std::move(tl), nullptr); auto st = zeek::make_intrusive<zeek::SetType>(std::move(tl), nullptr);
auto sv = zeek::make_intrusive<zeek::TableVal>(std::move(st)); auto sv = zeek::make_intrusive<zeek::TableVal>(std::move(st));
auto th = t->AsTableVal()->GetTableHash(); auto th = t->AsTableVal()->GetTableHash();
for ( const auto& iter : *t->AsTable() ) for ( const auto& iter : *t->AsTable() )

View file

@ -3,3 +3,11 @@
http, http,
https https
} }
{
[a=<uninitialized>, b=7],
[a=10, b=5]
}
{
[1/tcp, test, T] ,
[2/tcp, example, F]
}

View file

@ -1,3 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
80/tcp, http, 443/tcp, https [example, test]
21/tcp, ftp, 23/tcp, telnet [80/tcp, http, 443/tcp, https, 21/tcp, ftp, 23/tcp, telnet]

View file

@ -2,14 +2,28 @@
# @TEST-EXEC: zeek -b %INPUT > out # @TEST-EXEC: zeek -b %INPUT > out
# @TEST-EXEC: btest-diff out # @TEST-EXEC: btest-diff out
type MyRec: record {
a: count &optional;
b: count;
};
type MyTable: table[MyRec] of string;
event zeek_init() event zeek_init()
{ {
local t = table( local t1 = table(
["http"] = "http://www.google.com/", ["http"] = "http://www.google.com/",
["https"] = "https://www.google.com/" ["https"] = "https://www.google.com/");
); local t2 = MyTable([[$a=10, $b=5]] = "b5", [[$b=7]] = "b7");
local t3: table[port, string, bool] of string = table(
[1/tcp, "test", T] = "test1",
[2/tcp, "example", F] = "test2");
local v: set[string] = table_keys(t); local v1: set[string] = table_keys(t1);
local v2: set[MyRec] = table_keys(t2);
local v3: set[port, string, bool] = table_keys(t3);
print v; print v1;
print v2;
print v3;
} }

View file

@ -4,15 +4,14 @@
event zeek_init() event zeek_init()
{ {
local t = table( local t1: table[count] of string = table([5] = "test", [0] = "example");
local t2 = table(
["web"] = { [80/tcp, "http"], [443/tcp, "https"] }, ["web"] = { [80/tcp, "http"], [443/tcp, "https"] },
["login"] = { [21/tcp, "ftp"], [23/tcp, "telnet"] } ["login"] = { [21/tcp, "ftp"], [23/tcp, "telnet"] });
);
local v: vector of set[port, string] = table_values(t); local v1: vector of set[string] = table_values(t1);
local v2: vector of set[port, string] = table_values(t2);
for ( i in v ) print v1;
{ print v2;
print v[i];
}
} }