use molt_argparse::molt_argparse; use molt_ng::Interp; struct Database { calls: Vec<(Vec, Option, bool)> } #[molt_argparse("{db} port_pin_list -period:clock_period -add")] fn cmd1( db: &mut Database, port_pin_list: Vec, clock_period: Option, add: bool ) { println!("cmd1: {:?} {:?} {}", port_pin_list, clock_period, add); db.calls.push((port_pin_list, clock_period, add)); } #[test] fn test_cmd1() { let mut interp = Interp::new(); let ctxid = interp.save_context(Database{ calls: Default::default() }); interp.add_context_command("cmd1", cmd1, ctxid); interp.eval("cmd1 {1 2 3} -period 3.5").unwrap(); interp.eval("cmd1 -period 2 -add {1}").unwrap(); assert_eq!(interp.context::(ctxid).calls, vec![(vec![1, 2, 3], Some(3.5), false), (vec![1], Some(2.), true)]) }