use serde::{Serialize, Deserialize}; use shm_rs::lexer::lexer; use shm_rs::serializator::serializator; use shm_rs::static_scheme::init; use shm_rs::dynamic_scheme::environment; #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct ExtTest { pub var_name: String, pub entity: String, pub title: String, } pub fn main() { let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/scheme_extensions/test_exts.shm"); println!("{}", curdir.display()); let lex = lexer::Lexer::from_file(curdir).unwrap(); let schm = init::SchemeInit::new().unwrap(); let res = schm.run(&lex, None).unwrap(); let resser = res.get("test_exts").unwrap().clone(); println!("Static: \n{:?}\n", res); let mut curdir = std::env::current_dir().unwrap(); curdir.push("examples/scheme_extensions/test_exts_data.shm"); let lex = lexer::Lexer::from_file(curdir).unwrap(); let dynenv = environment::DynEnvironment::new_root(resser.clone()).unwrap(); let dynres = environment::DynEnvironment::run(&lex, dynenv).unwrap(); println!("Dynamic: \n{:?}\n", dynres); let ret = serializator::Serialization::serialize(resser, dynres.clone()).unwrap(); let serialized = serde_json::to_string(&ret).unwrap(); let tr = ExtTest{ var_name: "var1".to_string(), entity: "od".to_string(), title: "model123".to_string() }; let res = serde_json::to_string(&tr).unwrap(); println!("control: {}", res); let deser: ExtTest = serde_json::from_str(&serialized).unwrap(); println!("{:?}", deser); if deser != tr { panic!("did not match!"); } else { println!("matched!"); } }