directive: does not type check; add test for parsing builtin directives

This commit is contained in:
Branden J Brown 2024-10-15 18:19:20 -04:00
parent fa257d7db2
commit bf1eaf7ea3
1 changed files with 38 additions and 1 deletions

View File

@ -3,6 +3,7 @@ use std::collections::BTreeMap;
use snafu::{ResultExt, Snafu}; use snafu::{ResultExt, Snafu};
/// The types and directives in a VijiN project. /// The types and directives in a VijiN project.
#[derive(Debug, PartialEq, Eq)]
pub struct TypeSystem { pub struct TypeSystem {
pub types: BTreeMap<String, Type>, pub types: BTreeMap<String, Type>,
pub directives: BTreeMap<String, Directive>, pub directives: BTreeMap<String, Directive>,
@ -11,6 +12,7 @@ pub struct TypeSystem {
/// The definition of a standard directive. /// The definition of a standard directive.
/// ///
/// Note that this type is an input to the parser, not an output. /// Note that this type is an input to the parser, not an output.
#[derive(Debug, PartialEq, Eq)]
pub struct Directive { pub struct Directive {
/// The provider's name for the directive. /// The provider's name for the directive.
name: String, name: String,
@ -37,6 +39,7 @@ pub struct Directive {
} }
/// Directive parameter. /// Directive parameter.
#[derive(Debug, PartialEq, Eq)]
pub struct Param { pub struct Param {
/// Name to which the compiler maps the argument. /// Name to which the compiler maps the argument.
name: String, name: String,
@ -49,7 +52,7 @@ pub struct Param {
} }
/// Types expected by directive arguments. /// Types expected by directive arguments.
#[derive(Clone)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum Type { pub enum Type {
/// Arbitrary text. /// Arbitrary text.
Text, Text,
@ -264,4 +267,38 @@ impl TypeSystem {
mod tests { mod tests {
use super::*; use super::*;
use rstest::rstest; use rstest::rstest;
#[rstest]
fn builtin() {
let mut s = TypeSystem {
types: BTreeMap::new(),
directives: BTreeMap::new(),
};
s.parse(DIRECTIVE_PREDECLARED).unwrap();
let expected = TypeSystem{
types: BTreeMap::from([
("text", Type::Text),
("speech", Type::Speech),
("character", Type::Character),
("duration", Type::Duration),
("scene", Type::Asset { tags: ["scene"] }),
("background", Type::Asset { tags: ["background"] }),
("stage position", Type::Enum(["close", "left third", "right third", "left", "center", "right", "far left", "mid left", "mid right", "far right", "far"])),
].map(|(k, v)| (k.into(), v))),
directives: BTreeMap::from([
("page", Directive {
name: "page".into(),
doc: "Start showing the current static speaker, text, &c.\nNormally not used directly; script speech lines call this directive implicitly.".into(),
prefix: "page".into(),
prefix_param: None,
infix: None,
infix_param: None,
suffix: None,
suffix_param: None,
list_param: None,
}),
].map(|(k, v)| (k.into(), v))),
};
assert_eq!(s, expected);
}
} }