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"); } #[test] fn t018(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "__".into(), text: "{$arr = [0, 10, 20, 30]$}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {{ (x:y:z:z.arr[x]) 2 \"Lol\" __ }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), "20"); } #[test] fn t019(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "__".into(), text: "{$arr = [0, 10, 20, 30]$}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {{ (x:y:z:w:w x z) 2 \"Lol\" __ x:z:z.arr[x]}}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), "20"); } #[test] fn t020(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "__".into(), text: "{$arr = [0, 10, 20, 30]$}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {{ (x:y:z:w:w x z) __ \"Lol\" 2 x:z:x.arr[z]}}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), "20"); } #[test] fn t021(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "__".into(), text: "{$arr = [\" zero\", 10, 20,]$} {$dict$} {$lol = \"HELLO\"$} {@ cat a b @}{[a]}{[b]}{@} {$}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {{ __.dict.cat ((a:b:c:c[b][a]) \"lol\" \"dict\" __) __.arr[0] }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), "HELLO zero"); } #[test] fn t022(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "__".into(), text: "{$arr = [\" zero\", 10, 20,]$} {$dict$} {$lol = \"HELLO\"$} {@ cat a b @}{[a]}{[b]}{@} {$}".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {{ __.dict.cat ((a:b:c:c[a][b]) \"dict\" \"lol\" __) __.arr[0] }}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), "HELLO zero"); } #[test] fn t023(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "aaa".into(), text: "{@ el arr @} A B {@} ".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: " {[ aaa.el ([1, 2, 3]) ]}".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( Value::Int(0), "index", 50 ).unwrap(), "A\n\nB"); } macro_rules! valarr { ($($el:expr),* $(,)?) => { Value::Arr(std::rc::Rc::new( vec![$($el),*] )) }; } macro_rules! valdict { ($($el:literal => $val:expr),* $(,)?) => {{ let mut hashmap = std::collections::HashMap::new(); $(hashmap.insert($el.to_string(), $val);)* Value::Dict(Rc::new(hashmap)) }} } #[test] fn t024(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{% let x = $[2]%} \n {{x}} \n{%} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( valarr![Value::Int(10), Value::Int(11), Value::Int(12)], "index", 50 ).unwrap(), "12"); } #[test] fn t025(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{% let l1 = $[2]%} {%let l2 = l1 [ 0]%}\n\n {{ l2}} \n {%} \n{%} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( valarr![Value::Int(0), Value::Int(1), valarr![Value::Int(69), Value::Int(228)]], "index", 50 ).unwrap(), "69"); } #[test] fn t026(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{% for v: $ %}{{v}}{%nogap %} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( valarr![Value::Int(10), Value::Int(11), Value::Int(12)], "index", 50 ).unwrap(), "101112"); } #[test] fn t027(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{% for v: $ %}{{v}}{% gap %} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( valarr![Value::Int(10), Value::Int(11), Value::Int(12)], "index", 50 ).unwrap(), "10 11 12"); } #[test] fn t028(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{% for v: $ %} \n {{v}} \n {% lf %} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( valarr![Value::Int(10), Value::Int(11), Value::Int(12)], "index", 50 ).unwrap(), "10\n11\n12"); } #[test] fn t029(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{% for k, v: $ %} {{k }}->{{ v}} {% lf %} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( valarr![Value::Int(10), Value::Int(11), Value::Int(12)], "index", 50 ).unwrap(), "0->10\n1->11\n2->12"); } #[test] fn t030(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{% for k, v: $ %} {{k }}->{{ v}} {% lf %} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); assert_gave!(r.render( valarr![Value::Int(10), Value::Int(11), Value::Int(12)], "index", 50 ).unwrap(), "0->10\n1->11\n2->12"); } #[test] fn t031(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{% for k, v: $ %} {{k }}:{{ v}} {% gap %} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); let a = r.render( valdict!["a" => Value::Int(1), "b" => Value::Int(2)], "index", 50 ).unwrap(); assert!(["a:1 b:2".to_string(), "b:2 a:1".to_string()].contains(&a)); } #[test] fn t032(){ let i = MtgottDirContent{mtgott: vec![ FileWithPath{v_path: "A".into(), text: "".into()} ], imtgott: vec![ FileWithPath{v_path: "index".into(), text: "{%for v: $ %} ->{{v}} {%gap%} ".into()} ], plain: vec![]}; let r = get_root_html_from_dir_text_html(i).unwrap(); let a = r.render( valdict!["a" => Value::Int(1), "b" => Value::Int(2)], "index", 50 ).unwrap(); assert!(["->1 ->2".to_string(), "->2 ->1".to_string()].contains(&a)); }