testing
Variables
irb
Intermediate Representation Builder — a collection of test factory functions for constructing well-formed IR nodes with sensible defaults.
Use irb in unit tests to create IrSchema, TypeDef, EnumDef,
ConstantDef, Field, TypeRef, LiteralValue, Annotation, and other
IR structures without manually supplying every required property.
Type Declaration
annotation()
Creates an Annotation with the given name
and an optional literal argument.
Parameters
name
string
Annotation name without the @ prefix.
argument?
Optional literal argument attached to the annotation.
Returns
An Annotation with a default position.
Example
irb.annotation("minLength", irb.intLiteral(3));
// returns an annotation named "minLength" with an int literal argument
arrayLiteral()
Creates an array LiteralValue from a list of literal items.
Parameters
items
Literal items to include.
Returns
An array literal node.
Example
irb.arrayLiteral([irb.stringLiteral("a"), irb.stringLiteral("b")]);
// returns a LiteralValue with kind "array"
arrayType()
Creates an array TypeRef wrapping the given element type.
Parameters
type
Element type stored inside the array.
dims?
number = 1
Number of array dimensions (defaults to 1).
Returns
An array TypeRef.
Example
boolLiteral()
Creates a boolean LiteralValue.
Parameters
value
boolean
Boolean value to store.
Returns
A boolean literal node.
Example
constantDef()
Creates a ConstantDef with the given name, type, and literal value.
Pass overrides to set annotations or doc.
Parameters
name
string
Constant name.
typeRef
Constant type reference.
value
Constant literal value.
overrides?
Partial\<Omit\<ConstantDef, "position" | "annotations" | "typeRef" | "value" | "name">> & object = {}
Optional constant overrides.
Returns
A ConstantDef with defaults applied.
Example
irb.constantDef("ApiVersion", irb.primitiveType("string"), irb.stringLiteral("v1"));
// returns a constant definition named "ApiVersion"
enumDef()
Creates an EnumDef with the given name, value type, and members.
Pass overrides to set annotations or doc.
Parameters
name
string
Enum name.
enumValueType
Underlying enum storage type.
members
Enum members.
overrides?
Partial\<Omit\<EnumDef, "position" | "annotations" | "enumType" | "members" | "name">> & object = {}
Optional enum overrides.
Returns
An EnumDef with defaults applied.
Example
irb.enumDef("Role", "string", [
irb.enumMember("ADMIN", irb.stringLiteral("admin")),
]);
// returns an enum definition named "Role"
enumMember()
Creates an EnumMember with the given name and literal value.
Pass overrides to set annotations or doc.
Parameters
name
string
Enum member name.
value
Enum member literal value.
overrides?
Partial\<Omit\<EnumMember, "position" | "annotations" | "value" | "name">> & object = {}
Optional member overrides.
Returns
An EnumMember with defaults applied.
Example
enumType()
Creates a TypeRef that references a named enum type.
Parameters
name
string
Referenced enum name.
enumType
Underlying enum storage type.
Returns
An enum type reference.
Example
field()
Creates a Field with the given name and type.
Pass overrides to set optional, annotations, or doc.
Parameters
name
string
Field name.
typeRef
Field type reference.
overrides?
Partial\<Omit\<Field, "position" | "annotations" | "typeRef" | "name" | "optional">> & object = {}
Optional field overrides.
Returns
A Field with defaults applied.
Example
irb.field("id", irb.primitiveType("string"), { optional: true });
// returns a Field named "id" marked as optional
floatLiteral()
Creates a float LiteralValue.
Parameters
value
number
Floating-point value to store.
Returns
A float literal node.
Example
intLiteral()
Creates an integer LiteralValue.
Parameters
value
number
Integer value to store.
Returns
An integer literal node.
Example
mapType()
Creates a map TypeRef whose value type is type.
Parameters
type
Value type stored in the map.
Returns
A map TypeRef.
Example
namedType()
Creates a TypeRef that references a named user-defined type.
Parameters
name
string
Referenced type name.
Returns
A named type reference.
Example
objectLiteral()
Creates an object LiteralValue from a plain key/value record.
Parameters
entries
Record\<string, LiteralValue>
Object entries keyed by property name.
Returns
An object literal node.
Example
objectType()
Creates an inline object TypeRef with the given fields.
Parameters
fields
Field[]
Inline object fields.
Returns
An object TypeRef.
Example
irb.objectType([irb.field("id", irb.primitiveType("string"))]);
// returns a TypeRef with kind "object"
pluginInput()
Creates a PluginInput with a default version,
empty options, and an empty schema.
Pass overrides to customize any field.
Parameters
overrides?
Partial\<PluginInput> = {}
Plugin input fields to override.
Returns
A ready-to-use PluginInput for tests.
Example
irb.pluginInput({
options: { prefix: "Api" },
});
// returns a PluginInput with default version and schema
position()
Creates a Position with sensible defaults.
Pass overrides to customize specific fields.
Parameters
overrides?
Partial\<Position> = {}
Position fields to override.
Returns
A fully populated Position.
Example
primitiveType()
Creates a primitive TypeRef (e.g. string, int, bool).
Parameters
name
Primitive type name.
Returns
A primitive TypeRef.
Example
schema()
Creates an IrSchema with empty collections.
Pass overrides to populate constants, enums, types, or docs.
Parameters
overrides?
Partial\<IrSchema> = {}
Schema fields to override.
Returns
An IrSchema with sensible defaults.
Example
irb.schema({
types: [irb.typeDef("UserId", irb.primitiveType("string"))],
});
// returns a schema containing one typedef
stringLiteral()
Creates a string LiteralValue.
Parameters
value
string
String content to store.
Returns
A string literal node.
Example
typeDef()
Creates a TypeDef with the given name and underlying type.
Pass overrides to set annotations or doc.
Parameters
name
string
Type definition name.
typeRef
Underlying type reference.
overrides?
Partial\<Omit\<TypeDef, "position" | "annotations" | "typeRef" | "name">> & object = {}
Optional typedef overrides.
Returns
A TypeDef with defaults applied.