Skip to content

Commit

Permalink
Add type alias to parse_block test
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniosarosi committed Jan 19, 2025
1 parent 726ea22 commit dde691a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion engine/baml-lib/schema-ast/src/ast/type_builder_block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Assignment, TypeExpressionBlock};

#[derive(Debug, Clone)]
/// Blocks allowed in `type_builder` blocks.
#[derive(Debug, Clone)]
pub enum TypeBuilderEntry {
/// An enum declaration.
Enum(TypeExpressionBlock),
Expand Down
14 changes: 12 additions & 2 deletions engine/baml-lib/schema-ast/src/parser/parse_type_builder_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(crate) fn parse_type_builder_block(
entries.push(TypeBuilderEntry::TypeAlias(assignment));
}

_ => parsing_catch_all(nested, "type_builder_block"),
_ => parsing_catch_all(nested, "type_builder_contents"),
}
}
}
Expand Down Expand Up @@ -107,6 +107,8 @@ mod tests {
C
D
}
type Alias = Example
}"#;

let source = SourceFile::new_static(root_path.into(), input);
Expand All @@ -121,7 +123,7 @@ mod tests {

let type_buider_block = parse_type_builder_block(parsed, &mut diagnostics).unwrap();

assert_eq!(type_buider_block.entries.len(), 4);
assert_eq!(type_buider_block.entries.len(), 5);

let TypeBuilderEntry::Class(example) = &type_buider_block.entries[0] else {
panic!(
Expand All @@ -148,10 +150,18 @@ mod tests {
);
};

let TypeBuilderEntry::TypeAlias(alias) = &type_buider_block.entries[4] else {
panic!(
"Expected type Alias, got {:?}",
type_buider_block.entries[4]
);
};

assert_eq!(example.name(), "Example");
assert_eq!(bar.name(), "Bar");
assert_eq!(cls.name(), "Cls");
assert_eq!(cls.documentation(), Some("Some doc\ncomment"));
assert_eq!(enm.name(), "Enm");
assert_eq!(alias.name(), "Alias");
}
}

0 comments on commit dde691a

Please sign in to comment.