zeek/testing/btest/bifs/enum_names.zeek
Arne Welzel a00cef9920 enum_names: Support naming types with a string
In his ZeekWeek 2022 presentation, @stevesmoot mentioned that he had a
difficult time looking up enum names when all he had was a string
naming the type.

Add support to enum_names() to transparently lookup the type if a string
is provided. This is similar in how record_fields() behaves when being
passed a string.
2022-10-21 20:09:48 +02:00

22 lines
451 B
Text

# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
type Color: enum { RED, GREEN, BLUE };
type ColorAlias: Color;
redef enum Color += { PURPLE };
module Monochrome;
type Color: enum { WHITE, BLACK };
print "with types";
print enum_names(Color);
print enum_names(ColorAlias);
print enum_names(Monochrome::Color);
print "with strings";
print enum_names("Color");
print enum_names("ColorAlias");
print enum_names("Monochrome::Color");