// Standard Uses // Local Uses // External Uses use comline::{idl, ir}; use comline::idl::constants::SCHEMA_EXTENSION; use comline::ir::new_unit::Unit; use panik_handler; use pretty_assertions::{assert_eq, assert_ne}; use comline::ir::compiler; use comline::ir::primitive::TypeValue; #[test] fn from_raw_to_unit() { panik_handler::install(); let raw = std::fs::read_to_string( format!("tests/idl/simple.{}", SCHEMA_EXTENSION) ).unwrap(); let unit = idl::parser::parse_into_unit(raw.as_str()).unwrap(); assert_eq!( unit, vec![ Unit::Namespace("tests.idl.simple".to_string()), Unit::Import("std::validators::StringBounds".to_string()), Unit::Constant { docstring: None, name: "POWER".to_string(), kind: TypeValue::U8, default_value: Some("1".to_string()), }, Unit::Constant { docstring: None, name: "DEFAULT_NAME".to_string(), kind: TypeValue::String, default_value: Some("f\"flower power: {POWER}\"".to_string()), }, Unit::Settings { docstring: None, name: "Test".to_string(), parameters: vec![ Unit::Parameter { name: "forbid_indexing".to_string(), default_value: "True".to_string(), }, Unit::Parameter { name: "forbid_optional_indexing".to_string(), default_value: "True".to_string(), } ], }, Unit::Enum { docstring: None, name: "EncryptionMode".to_string(), variants: vec![ Unit::EnumVariant { name: "None".to_string(), kind: None }, Unit::EnumVariant { name: "Encrypt".to_string(), kind: None } ] } ] ) } #[test] fn compile_unit() { let unit = idl::parser::from_path( format!("tests/idl/simple.{}", SCHEMA_EXTENSION).as_str() ).unwrap(); let context = ir::context::Context::with_main(unit); let interpreted = compiler::interpret_unit(context); println!("{:?}", interpreted); }