Daily update. Fixing some bugs in mtgott
This commit is contained in:
parent
7f30675aab
commit
0d24c782e3
@ -428,9 +428,9 @@ fn fix_whitespaces_in_element(subels: &mut Vec<SubElement>) {
|
||||
should_ignore_gap = false;
|
||||
/* We handle trailing whitespaces case here */
|
||||
while let Some(&ch) = res.last() {
|
||||
if is_lnspace(ch as char) { res. pop(); } else { break }
|
||||
if is_lnspace(ch as char) { res.pop(); } else { break }
|
||||
}
|
||||
} else if p - line_bg < min_offset {
|
||||
} else if p - line_bg < min_offset && !should_ignore_gap{
|
||||
continue
|
||||
}
|
||||
res.push(ch);
|
||||
@ -453,9 +453,7 @@ impl<'a> Parser<'a> {
|
||||
let mut tp1 = self.p;
|
||||
|
||||
let fin_static = |p: &Parser, tp1: usize, res: &mut Vec<SubElement>| {
|
||||
if tp1 < p.p {
|
||||
res.push(SubElement::Static(String::from(&p.text[tp1..p.p])))
|
||||
}
|
||||
};
|
||||
|
||||
/* Fixes whitespaces in static sub-elements */
|
||||
@ -802,7 +800,7 @@ impl<'a> Parser<'a> {
|
||||
Ok(Some(Expression::Lambda(NewLambdaExpression{
|
||||
local_var_array: used_by_lambda.iter().map( |iig| -> usize {
|
||||
if *iig == argument_iig {
|
||||
usize::MAX
|
||||
usize::MAX // We assume usize::MAX never appears as an actual index in used_local_consts
|
||||
} else {
|
||||
used_local_consts.iter().position(|iig_of_this| iig_of_this == iig).unwrap()
|
||||
}
|
||||
|
||||
@ -306,11 +306,13 @@ impl<'m> RuntimeEnv<'m> {
|
||||
let local_var_array: Vec<Value> = captured.iter().map(|oid| {
|
||||
if *oid == usize::MAX { Value::Int(0) } else { local[*oid].clone() }
|
||||
}).collect();
|
||||
let where_arg_goes = captured.iter().position(|oid| *oid == usize::MAX).unwrap();
|
||||
let where_arg_goes = captured.iter().position(|oid| *oid == usize::MAX);
|
||||
let body_expr_id: usize = *body_expr_id;
|
||||
Ok(Value::Fn(Rc::new(move |re, x: Value, counter| -> Result<Value, String> {
|
||||
let mut local_var_array: Vec<Value> = local_var_array.clone();
|
||||
local_var_array[where_arg_goes] = x;
|
||||
if let Some(arg_local_ind) = where_arg_goes {
|
||||
local_var_array[arg_local_ind] = x;
|
||||
}
|
||||
re.execute_expression(&re.mtgott.source_expressions[body_expr_id], &local_var_array, counter - 1)
|
||||
})))
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
extern crate mtgott;
|
||||
use mtgott::dirsearch::*;
|
||||
use mtgott::runtime::*;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
macro_rules! assert_gave {
|
||||
($a:expr, $str:literal) => {
|
||||
@ -123,3 +123,102 @@ fn t010(){
|
||||
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");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user