extern crate mtgott; use mtgott::dirsearch::*; use mtgott::runtime::*; use std::rc::Rc; macro_rules! assert_gave { ($a:expr, $str:literal) => { assert_eq!($a, String::from($str)) }; } #[test] fn t001(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "boba".into(), text: "{$ aboba = \"xdds\" $}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{{ boba.aboba }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index", 50).unwrap(), "xdds"); } #[test] fn t002(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "boba/biba/aaa/bbb".into(), text: "{$ aboba = \"xdds\" $}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{{ boba. biba .aaa.bbb.aboba }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index", 50).unwrap(), "xdds"); } #[test] fn t003(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "boba/biba/aaa/bbb".into(), text: "{$ aboba = \"xdds\" $}".into()} ], imtgott: vec![ FileWithPath{v_path: "index/yyy/eee".into(), text: "{{ boba. biba .aaa.bbb.aboba }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index.yyy.eee", 50).unwrap(), "xdds"); } #[test] fn t004(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "boba/biba/aaa/bbb".into(), text: "{$ pack $} {$ AAA = \"xdds\" $} {$}".into()} ], imtgott: vec![ FileWithPath{v_path: "index/yyy/eee".into(), text: "{{ boba. biba .aaa.bbb.pack.AAA }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index.yyy.eee", 50).unwrap(), "xdds"); } #[test] fn t005(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "file".into(), text: "{$ pack $} {$ const = 12345 $} {$}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{{ file.pack.const }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index", 50).unwrap(), "12345"); } #[test] fn t006(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "file".into(), text: "{$ pack $} {$ const = file.pack.pack2.chislo $} {$ pack2 $} {$ chislo = 123 $} {$} {$}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{{ file.pack.const }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index", 50).unwrap(), "123"); } #[test] fn t007(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "file".into(), text: "{$ pack $}{$c=45$}{$} {@ el @}---{{this.pack.c}}---{@} ".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{[file.el]}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index", 50).unwrap(), "---45---"); } #[test] fn t008(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "file".into(), text: "{@ el a@}---{{a}}---{@} ".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{[file.el \"45\"]}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index", 50).unwrap(), "---45---"); } #[test] fn t009(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "file".into(), text: "{@ el a b c d e f g @}---{{a}}---{{c}}---{{e}}---{{g}}---{@} ".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{[file.el 1 2 3 4 5 6 7]}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index", 50).unwrap(), "---1---3---5---7---"); } #[test] fn t010(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "file".into(), text: "{@el a b @} {{a}}{{b}} {@} ".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{[file.el 1 2]}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render(Value::Int(0), "index", 50).unwrap(), "12"); } #[test] fn t011(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "file".into(), text: "{@el a @} {{a[1]}} {@} ".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{[file.el $]}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Arr(Rc::new(vec![Value::Int(10), Value::Int(20), Value::Int(30)])), "index", 50 ).unwrap(), "20"); } #[test] fn t012(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "file".into(), text: "{@el a @} {{a[1]}} {@} ".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{[file[\"el\"] $]}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Arr(Rc::new(vec![Value::Int(10), Value::Int(20), Value::Int(30)])), "index", 50 ).unwrap(), "20"); } #[test] fn t013(){ let i = MtgottDirContent{mtgott: vec![ ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{{}} {{}}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), " "); } #[test] fn t014(){ let i = MtgottDirContent{mtgott: vec![ ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {{ $[0 ]}} {{$ [1]}} {{$[ 2]}} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Arr(Rc::new(vec![Value::Int(10), Value::Int(20), Value::Int(30)])), "index", 50 ).unwrap(), "10 20 30"); } #[test] fn t015(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "help".into(), text: " {@www $ a b@} {{$[a]}} {{$[b]}} {@}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {[help.www $ 2 1 ]}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Arr(Rc::new(vec![Value::Int(10), Value::Int(11), Value::Int(12)])), "index", 50 ).unwrap(), "12 11"); } #[test] fn t016(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "__".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {{ (x:x) 10 }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), "10"); } #[test] fn t017(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "__".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {{ (x:y:x) 0 1 }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), "0"); }