zeek/testing/btest/bifs/records_fields.zeek
Arne Welzel 699949cd40 bifs/record_fields: Include actual enum name in type_name
One more from @stevesmoot. The record_fields() BIF produced "enum" as
type_name for fields of type enum.

Extend container_type_name() to append the actual name of the enum.

This is changing the format and may break consumers, but those are
likely in a category that are happy to adapt. Not having the actual
enum name available wasn't very helpful.

We could alternatively render only the actual type_name without the
prefixed "enum", but that isn't how it's done for record types currently
and it would make it more difficult to decide which subsequent BIFs to
use for further introspection, like enum_names().
2022-10-26 20:21:20 +02:00

73 lines
1.3 KiB
Text

#
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
module Monochrome;
export {
type color: enum { BLACK, WHITE };
}
module GLOBAL;
type color: enum { RED, BLUE };
type myrec: record {
myfield: bool;
};
type tt: record {
a: bool;
b: string &default="Bar";
c: double &optional;
d: string &log;
e: color &default=BLUE;
f: Monochrome::color &log;
m: myrec;
};
type r: record {
a: count;
b: string &default="Foo";
c: double &optional;
d: string &log;
e: any;
};
type mystring: string;
type cr: record {
a: set[double];
b: set[double, string];
c: set[double, tt];
d: table[double, string] of table[string] of vector of string;
e: vector of vector of string;
f: vector of color;
g: table[string] of color;
};
event zeek_init()
{
local x: r = [$a=42, $d="Bar", $e=tt];
print x;
local t: record_field_table;
t = record_fields(x);
print t;
print t["c"]?$value;
t = record_fields(x$e);
print t;
t = record_fields(tt);
print t;
x = [$a=42, $d="Bar", $e=mystring];
t = record_fields(x);
print t;
t = record_fields(x$e);
print t;
print record_fields("myrec");
print record_fields("tt");
print record_fields("r");
print record_fields("cr");
}