From bf1eaf7ea370bf8742f04783907051ebc1d588fc Mon Sep 17 00:00:00 2001 From: Branden J Brown Date: Tue, 15 Oct 2024 18:19:20 -0400 Subject: [PATCH] directive: does not type check; add test for parsing builtin directives --- src/directive.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/directive.rs b/src/directive.rs index ae0d634..8531742 100644 --- a/src/directive.rs +++ b/src/directive.rs @@ -3,6 +3,7 @@ use std::collections::BTreeMap; use snafu::{ResultExt, Snafu}; /// The types and directives in a VijiN project. +#[derive(Debug, PartialEq, Eq)] pub struct TypeSystem { pub types: BTreeMap, pub directives: BTreeMap, @@ -11,6 +12,7 @@ pub struct TypeSystem { /// The definition of a standard directive. /// /// Note that this type is an input to the parser, not an output. +#[derive(Debug, PartialEq, Eq)] pub struct Directive { /// The provider's name for the directive. name: String, @@ -37,6 +39,7 @@ pub struct Directive { } /// Directive parameter. +#[derive(Debug, PartialEq, Eq)] pub struct Param { /// Name to which the compiler maps the argument. name: String, @@ -49,7 +52,7 @@ pub struct Param { } /// Types expected by directive arguments. -#[derive(Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum Type { /// Arbitrary text. Text, @@ -264,4 +267,38 @@ impl TypeSystem { mod tests { use super::*; 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); + } }