CLEANUP: Formatting

cargo fmt
This commit is contained in:
Jeremy Wall 2018-05-29 20:48:57 -05:00
parent a821ff6313
commit e86186b709
5 changed files with 331 additions and 400 deletions

View File

@ -4,8 +4,7 @@ use super::*;
pub fn test_macro_validation_happy_path() { pub fn test_macro_validation_happy_path() {
let def = MacroDef { let def = MacroDef {
argdefs: vec![value_node!("foo".to_string(), 1, 0)], argdefs: vec![value_node!("foo".to_string(), 1, 0)],
fields: vec![ fields: vec![(
(
make_tok!("f1", 1, 1), make_tok!("f1", 1, 1),
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Add, kind: BinaryExprType::Add,
@ -17,8 +16,7 @@ pub fn test_macro_validation_happy_path() {
right: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 1)))), right: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 1)))),
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
), )],
],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}; };
assert!(def.validate_symbols().unwrap() == ()); assert!(def.validate_symbols().unwrap() == ());
@ -28,8 +26,7 @@ pub fn test_macro_validation_happy_path() {
pub fn test_macro_validation_fail() { pub fn test_macro_validation_fail() {
let def = MacroDef { let def = MacroDef {
argdefs: vec![value_node!("foo".to_string(), 1, 0)], argdefs: vec![value_node!("foo".to_string(), 1, 0)],
fields: vec![ fields: vec![(
(
make_tok!("f1", 1, 1), make_tok!("f1", 1, 1),
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Add, kind: BinaryExprType::Add,
@ -41,8 +38,7 @@ pub fn test_macro_validation_fail() {
right: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 1)))), right: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 1)))),
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
), )],
],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}; };
let mut expected = HashSet::new(); let mut expected = HashSet::new();
@ -54,8 +50,7 @@ pub fn test_macro_validation_fail() {
pub fn test_macro_validation_selector_happy_path() { pub fn test_macro_validation_selector_happy_path() {
let def = MacroDef { let def = MacroDef {
argdefs: vec![value_node!("foo".to_string(), 1, 0)], argdefs: vec![value_node!("foo".to_string(), 1, 0)],
fields: vec![ fields: vec![(
(
make_tok!("f1", 1, 1), make_tok!("f1", 1, 1),
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Add, kind: BinaryExprType::Add,
@ -66,8 +61,7 @@ pub fn test_macro_validation_selector_happy_path() {
right: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 1)))), right: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 1)))),
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
), )],
],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}; };
assert!(def.validate_symbols().unwrap() == ()); assert!(def.validate_symbols().unwrap() == ());
@ -77,8 +71,7 @@ pub fn test_macro_validation_selector_happy_path() {
pub fn test_macro_validation_selector_fail() { pub fn test_macro_validation_selector_fail() {
let def = MacroDef { let def = MacroDef {
argdefs: vec![value_node!("foo".to_string(), 1, 0)], argdefs: vec![value_node!("foo".to_string(), 1, 0)],
fields: vec![ fields: vec![(
(
make_tok!("f1", 1, 1), make_tok!("f1", 1, 1),
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Add, kind: BinaryExprType::Add,
@ -89,8 +82,7 @@ pub fn test_macro_validation_selector_fail() {
right: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 1)))), right: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 1)))),
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
), )],
],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}; };
let mut expected = HashSet::new(); let mut expected = HashSet::new();

View File

@ -43,8 +43,7 @@ fn test_eval_div_expr() {
fn test_eval_div_expr_fail() { fn test_eval_div_expr_fail() {
let b = Builder::new(std::env::current_dir().unwrap()); let b = Builder::new(std::env::current_dir().unwrap());
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Div, kind: BinaryExprType::Div,
left: Box::new(Expression::Simple(Value::Float(value_node!(2.0, 1, 1)))), left: Box::new(Expression::Simple(Value::Float(value_node!(2.0, 1, 1)))),
@ -52,8 +51,7 @@ fn test_eval_div_expr_fail() {
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Float(1.0), Val::Float(1.0),
), )],
],
b, b,
); );
} }
@ -91,8 +89,7 @@ fn test_eval_mul_expr() {
fn test_eval_mul_expr_fail() { fn test_eval_mul_expr_fail() {
let b = Builder::new(std::env::current_dir().unwrap()); let b = Builder::new(std::env::current_dir().unwrap());
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Mul, kind: BinaryExprType::Mul,
left: Box::new(Expression::Simple(Value::Float(value_node!(2.0, 1, 1)))), left: Box::new(Expression::Simple(Value::Float(value_node!(2.0, 1, 1)))),
@ -100,8 +97,7 @@ fn test_eval_mul_expr_fail() {
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Float(1.0), Val::Float(1.0),
), )],
],
b, b,
); );
} }
@ -139,8 +135,7 @@ fn test_eval_subtract_expr() {
fn test_eval_subtract_expr_fail() { fn test_eval_subtract_expr_fail() {
let b = Builder::new(std::env::current_dir().unwrap()); let b = Builder::new(std::env::current_dir().unwrap());
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Sub, kind: BinaryExprType::Sub,
left: Box::new(Expression::Simple(Value::Float(value_node!(2.0, 1, 1)))), left: Box::new(Expression::Simple(Value::Float(value_node!(2.0, 1, 1)))),
@ -148,8 +143,7 @@ fn test_eval_subtract_expr_fail() {
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Float(1.0), Val::Float(1.0),
), )],
],
b, b,
); );
} }
@ -198,15 +192,19 @@ fn test_eval_add_expr() {
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Add, kind: BinaryExprType::Add,
left: Box::new(Expression::Simple(Value::List(ListDef { left: Box::new(Expression::Simple(Value::List(ListDef {
elems: vec![ elems: vec![Expression::Simple(Value::String(value_node!(
Expression::Simple(Value::String(value_node!("foo".to_string(), 1, 1))), "foo".to_string(),
], 1,
1
)))],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}))), }))),
right: Box::new(Expression::Simple(Value::List(ListDef { right: Box::new(Expression::Simple(Value::List(ListDef {
elems: vec![ elems: vec![Expression::Simple(Value::String(value_node!(
Expression::Simple(Value::String(value_node!("bar".to_string(), 1, 1))), "bar".to_string(),
], 1,
1
)))],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}))), }))),
pos: Position::new(1, 0), pos: Position::new(1, 0),
@ -226,8 +224,7 @@ fn test_eval_add_expr() {
fn test_eval_add_expr_fail() { fn test_eval_add_expr_fail() {
let b = Builder::new(std::env::current_dir().unwrap()); let b = Builder::new(std::env::current_dir().unwrap());
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Binary(BinaryOpDef { Expression::Binary(BinaryOpDef {
kind: BinaryExprType::Add, kind: BinaryExprType::Add,
left: Box::new(Expression::Simple(Value::Float(value_node!(2.0, 1, 1)))), left: Box::new(Expression::Simple(Value::Float(value_node!(2.0, 1, 1)))),
@ -235,8 +232,7 @@ fn test_eval_add_expr_fail() {
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Float(1.0), Val::Float(1.0),
), )],
],
b, b,
); );
} }
@ -259,18 +255,17 @@ fn test_eval_simple_expr() {
), ),
( (
Expression::Simple(Value::Tuple(value_node!( Expression::Simple(Value::Tuple(value_node!(
vec![ vec![(
(
make_tok!("bar", 1, 1), make_tok!("bar", 1, 1),
Expression::Simple(Value::Int(value_node!(1, 1, 1))), Expression::Simple(Value::Int(value_node!(1, 1, 1))),
), )],
],
1, 1,
1 1
))), ))),
Val::Tuple(vec![ Val::Tuple(vec![(
(value_node!("bar".to_string(), 1, 1), Rc::new(Val::Int(1))), value_node!("bar".to_string(), 1, 1),
]), Rc::new(Val::Int(1)),
)]),
), ),
], ],
Builder::new(std::env::current_dir().unwrap()), Builder::new(std::env::current_dir().unwrap()),
@ -284,12 +279,10 @@ fn test_eval_simple_lookup_expr() {
.entry(value_node!("var1".to_string(), 1, 0)) .entry(value_node!("var1".to_string(), 1, 0))
.or_insert(Rc::new(Val::Int(1))); .or_insert(Rc::new(Val::Int(1)));
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Simple(Value::Symbol(value_node!("var1".to_string(), 1, 1))), Expression::Simple(Value::Symbol(value_node!("var1".to_string(), 1, 1))),
Val::Int(1), Val::Int(1),
), )],
],
b, b,
); );
} }
@ -309,43 +302,43 @@ fn test_eval_selector_expr() {
let mut b = Builder::new(std::env::current_dir().unwrap()); let mut b = Builder::new(std::env::current_dir().unwrap());
b.out b.out
.entry(value_node!("var1".to_string(), 1, 0)) .entry(value_node!("var1".to_string(), 1, 0))
.or_insert(Rc::new(Val::Tuple(vec![ .or_insert(Rc::new(Val::Tuple(vec![(
(
value_node!("lvl1".to_string(), 1, 0), value_node!("lvl1".to_string(), 1, 0),
Rc::new(Val::Tuple(vec![ Rc::new(Val::Tuple(vec![(
(value_node!("lvl2".to_string(), 1, 0), Rc::new(Val::Int(3))), value_node!("lvl2".to_string(), 1, 0),
])), Rc::new(Val::Int(3)),
), )])),
]))); )])));
b.out b.out
.entry(value_node!("var2".to_string(), 1, 0)) .entry(value_node!("var2".to_string(), 1, 0))
.or_insert(Rc::new(Val::Int(2))); .or_insert(Rc::new(Val::Int(2)));
b.out b.out
.entry(value_node!("var3".to_string(), 1, 0)) .entry(value_node!("var3".to_string(), 1, 0))
.or_insert(Rc::new(Val::Tuple(vec![ .or_insert(Rc::new(Val::Tuple(vec![(
(value_node!("lvl1".to_string(), 1, 0), Rc::new(Val::Int(4))), value_node!("lvl1".to_string(), 1, 0),
]))); Rc::new(Val::Int(4)),
)])));
test_expr_to_val( test_expr_to_val(
vec![ vec![
( (
Expression::Simple(Value::Selector(make_selector!(make_expr!("var1")))), Expression::Simple(Value::Selector(make_selector!(make_expr!("var1")))),
Val::Tuple(vec![ Val::Tuple(vec![(
(
value_node!("lvl1".to_string(), 1, 0), value_node!("lvl1".to_string(), 1, 0),
Rc::new(Val::Tuple(vec![ Rc::new(Val::Tuple(vec![(
(value_node!("lvl2".to_string(), 1, 0), Rc::new(Val::Int(3))), value_node!("lvl2".to_string(), 1, 0),
])), Rc::new(Val::Int(3)),
), )])),
]), )]),
), ),
( (
Expression::Simple(Value::Selector( Expression::Simple(Value::Selector(
make_selector!(make_expr!("var1") => "lvl1"), make_selector!(make_expr!("var1") => "lvl1"),
)), )),
Val::Tuple(vec![ Val::Tuple(vec![(
(value_node!("lvl2".to_string(), 1, 0), Rc::new(Val::Int(3))), value_node!("lvl2".to_string(), 1, 0),
]), Rc::new(Val::Int(3)),
)]),
), ),
( (
Expression::Simple(Value::Selector( Expression::Simple(Value::Selector(
@ -375,20 +368,19 @@ fn test_eval_selector_list_expr() {
.entry(value_node!("var1".to_string(), 1, 1)) .entry(value_node!("var1".to_string(), 1, 1))
.or_insert(Rc::new(Val::List(vec![ .or_insert(Rc::new(Val::List(vec![
Rc::new(Val::String("val1".to_string())), Rc::new(Val::String("val1".to_string())),
Rc::new(Val::Tuple(vec![ Rc::new(Val::Tuple(vec![(
(value_node!("var2".to_string(), 1, 1), Rc::new(Val::Int(1))), value_node!("var2".to_string(), 1, 1),
])), Rc::new(Val::Int(1)),
)])),
]))); ])));
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Simple(Value::Selector( Expression::Simple(Value::Selector(
make_selector!(make_expr!("var1") => "0" => 1, 1), make_selector!(make_expr!("var1") => "0" => 1, 1),
)), )),
Val::String("val1".to_string()), Val::String("val1".to_string()),
), )],
],
b, b,
); );
} }
@ -398,16 +390,14 @@ fn test_eval_selector_list_expr() {
fn test_expr_copy_no_such_tuple() { fn test_expr_copy_no_such_tuple() {
let b = Builder::new(std::env::current_dir().unwrap()); let b = Builder::new(std::env::current_dir().unwrap());
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Copy(CopyDef { Expression::Copy(CopyDef {
selector: make_selector!(make_expr!("tpl1")), selector: make_selector!(make_expr!("tpl1")),
fields: Vec::new(), fields: Vec::new(),
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Tuple(Vec::new()), Val::Tuple(Vec::new()),
), )],
],
b, b,
); );
} }
@ -420,16 +410,14 @@ fn test_expr_copy_not_a_tuple() {
.entry(value_node!("tpl1".to_string(), 1, 0)) .entry(value_node!("tpl1".to_string(), 1, 0))
.or_insert(Rc::new(Val::Int(1))); .or_insert(Rc::new(Val::Int(1)));
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Copy(CopyDef { Expression::Copy(CopyDef {
selector: make_selector!(make_expr!("tpl1")), selector: make_selector!(make_expr!("tpl1")),
fields: Vec::new(), fields: Vec::new(),
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Tuple(Vec::new()), Val::Tuple(Vec::new()),
), )],
],
b, b,
); );
} }
@ -440,30 +428,25 @@ fn test_expr_copy_field_type_error() {
let mut b = Builder::new(std::env::current_dir().unwrap()); let mut b = Builder::new(std::env::current_dir().unwrap());
b.out b.out
.entry(value_node!("tpl1".to_string(), 1, 0)) .entry(value_node!("tpl1".to_string(), 1, 0))
.or_insert(Rc::new(Val::Tuple(vec![ .or_insert(Rc::new(Val::Tuple(vec![(
(value_node!("fld1".to_string(), 1, 0), Rc::new(Val::Int(1))), value_node!("fld1".to_string(), 1, 0),
]))); Rc::new(Val::Int(1)),
)])));
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Copy(CopyDef { Expression::Copy(CopyDef {
selector: make_selector!(make_expr!("tpl1")), selector: make_selector!(make_expr!("tpl1")),
fields: vec![ fields: vec![(
(
make_tok!("fld1", 1, 1), make_tok!("fld1", 1, 1),
Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))), Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))),
), )],
],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Tuple(vec![ Val::Tuple(vec![(
(
value_node!("fld1".to_string(), 1, 1), value_node!("fld1".to_string(), 1, 1),
Rc::new(Val::String("2".to_string())), Rc::new(Val::String("2".to_string())),
), )]),
]), )],
),
],
b, b,
); );
} }
@ -473,20 +456,19 @@ fn test_expr_copy() {
let mut b = Builder::new(std::env::current_dir().unwrap()); let mut b = Builder::new(std::env::current_dir().unwrap());
b.out b.out
.entry(value_node!("tpl1".to_string(), 1, 0)) .entry(value_node!("tpl1".to_string(), 1, 0))
.or_insert(Rc::new(Val::Tuple(vec![ .or_insert(Rc::new(Val::Tuple(vec![(
(value_node!("fld1".to_string(), 1, 0), Rc::new(Val::Int(1))), value_node!("fld1".to_string(), 1, 0),
]))); Rc::new(Val::Int(1)),
)])));
test_expr_to_val( test_expr_to_val(
vec![ vec![
( (
Expression::Copy(CopyDef { Expression::Copy(CopyDef {
selector: make_selector!(make_expr!("tpl1")), selector: make_selector!(make_expr!("tpl1")),
fields: vec![ fields: vec![(
(
make_tok!("fld2", 1, 1), make_tok!("fld2", 1, 1),
Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))), Expression::Simple(Value::String(value_node!("2".to_string(), 1, 1))),
), )],
],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
// Add a new field to the copy // Add a new field to the copy
@ -530,9 +512,10 @@ fn test_expr_copy() {
// The source tuple is still unmodified. // The source tuple is still unmodified.
( (
Expression::Simple(Value::Selector(make_selector!(make_expr!["tpl1"]))), Expression::Simple(Value::Selector(make_selector!(make_expr!["tpl1"]))),
Val::Tuple(vec![ Val::Tuple(vec![(
(value_node!("fld1".to_string(), 1, 0), Rc::new(Val::Int(1))), value_node!("fld1".to_string(), 1, 0),
]), Rc::new(Val::Int(1)),
)]),
), ),
], ],
b, b,
@ -546,32 +529,28 @@ fn test_macro_call() {
.entry(value_node!("tstmac".to_string(), 1, 0)) .entry(value_node!("tstmac".to_string(), 1, 0))
.or_insert(Rc::new(Val::Macro(MacroDef { .or_insert(Rc::new(Val::Macro(MacroDef {
argdefs: vec![value_node!("arg1".to_string(), 1, 0)], argdefs: vec![value_node!("arg1".to_string(), 1, 0)],
fields: vec![ fields: vec![(
(
make_tok!("foo", 1, 1), make_tok!("foo", 1, 1),
Expression::Simple(Value::Symbol(value_node!("arg1".to_string(), 1, 1))), Expression::Simple(Value::Symbol(value_node!("arg1".to_string(), 1, 1))),
), )],
],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}))); })));
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Call(CallDef { Expression::Call(CallDef {
macroref: make_selector!(make_expr!("tstmac")), macroref: make_selector!(make_expr!("tstmac")),
arglist: vec![ arglist: vec![Expression::Simple(Value::String(value_node!(
Expression::Simple(Value::String(value_node!("bar".to_string(), 1, 1))), "bar".to_string(),
], 1,
1
)))],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Tuple(vec![ Val::Tuple(vec![(
(
value_node!("foo".to_string(), 1, 1), value_node!("foo".to_string(), 1, 1),
Rc::new(Val::String("bar".to_string())), Rc::new(Val::String("bar".to_string())),
), )]),
]), )],
),
],
b, b,
); );
} }
@ -587,32 +566,28 @@ fn test_macro_hermetic() {
.entry(value_node!("tstmac".to_string(), 1, 0)) .entry(value_node!("tstmac".to_string(), 1, 0))
.or_insert(Rc::new(Val::Macro(MacroDef { .or_insert(Rc::new(Val::Macro(MacroDef {
argdefs: vec![value_node!("arg2".to_string(), 1, 0)], argdefs: vec![value_node!("arg2".to_string(), 1, 0)],
fields: vec![ fields: vec![(
(
make_tok!("foo", 1, 1), make_tok!("foo", 1, 1),
Expression::Simple(Value::Symbol(value_node!("arg1".to_string(), 1, 1))), Expression::Simple(Value::Symbol(value_node!("arg1".to_string(), 1, 1))),
), )],
],
pos: Position::new(1, 0), pos: Position::new(1, 0),
}))); })));
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Call(CallDef { Expression::Call(CallDef {
macroref: make_selector!(make_expr!("tstmac")), macroref: make_selector!(make_expr!("tstmac")),
arglist: vec![ arglist: vec![Expression::Simple(Value::String(value_node!(
Expression::Simple(Value::String(value_node!("bar".to_string(), 1, 1))), "bar".to_string(),
], 1,
1
)))],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}), }),
Val::Tuple(vec![ Val::Tuple(vec![(
(
value_node!("foo".to_string(), 1, 0), value_node!("foo".to_string(), 1, 0),
Rc::new(Val::String("bar".to_string())), Rc::new(Val::String("bar".to_string())),
), )]),
]), )],
),
],
b, b,
); );
} }
@ -686,8 +661,7 @@ fn test_select_expr_not_a_string() {
.entry(value_node!("foo".to_string(), 1, 0)) .entry(value_node!("foo".to_string(), 1, 0))
.or_insert(Rc::new(Val::Int(4))); .or_insert(Rc::new(Val::Int(4)));
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Select(SelectDef { Expression::Select(SelectDef {
val: Box::new(Expression::Simple(Value::Symbol(value_node!( val: Box::new(Expression::Simple(Value::Symbol(value_node!(
"foo".to_string(), "foo".to_string(),
@ -708,8 +682,7 @@ fn test_select_expr_not_a_string() {
pos: Position::new(1, 0), pos: Position::new(1, 0),
}), }),
Val::Int(2), Val::Int(2),
), )],
],
b, b,
); );
} }
@ -723,12 +696,10 @@ fn test_let_statement() {
}); });
b.build_stmt(&stmt).unwrap(); b.build_stmt(&stmt).unwrap();
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Simple(Value::Symbol(value_node!("foo".to_string(), 1, 1))), Expression::Simple(Value::Symbol(value_node!("foo".to_string(), 1, 1))),
Val::String("bar".to_string()), Val::String("bar".to_string()),
), )],
],
b, b,
); );
} }
@ -746,28 +717,24 @@ fn test_asset_symbol_lookups() {
let mut b = Builder::new(std::env::current_dir().unwrap()); let mut b = Builder::new(std::env::current_dir().unwrap());
b.assets b.assets
.entry(value_node!("foo".to_string(), 1, 0)) .entry(value_node!("foo".to_string(), 1, 0))
.or_insert(Rc::new(Val::Tuple(vec![ .or_insert(Rc::new(Val::Tuple(vec![(
(
value_node!("bar".to_string(), 1, 0), value_node!("bar".to_string(), 1, 0),
Rc::new(Val::Tuple(vec![ Rc::new(Val::Tuple(vec![(
(value_node!("quux".to_string(), 1, 0), Rc::new(Val::Int(1))), value_node!("quux".to_string(), 1, 0),
])), Rc::new(Val::Int(1)),
), )])),
]))); )])));
test_expr_to_val( test_expr_to_val(
vec![ vec![(
(
Expression::Simple(Value::Symbol(value_node!("foo".to_string(), 1, 1))), Expression::Simple(Value::Symbol(value_node!("foo".to_string(), 1, 1))),
Val::Tuple(vec![ Val::Tuple(vec![(
(
value_node!("bar".to_string(), 1, 0), value_node!("bar".to_string(), 1, 0),
Rc::new(Val::Tuple(vec![ Rc::new(Val::Tuple(vec![(
(value_node!("quux".to_string(), 1, 0), Rc::new(Val::Int(1))), value_node!("quux".to_string(), 1, 0),
])), Rc::new(Val::Int(1)),
), )])),
]), )]),
), )],
],
b, b,
); );
} }

View File

@ -547,16 +547,14 @@ fn test_expression_parse() {
value_node!("arg1".to_string(), 1, 8), value_node!("arg1".to_string(), 1, 8),
value_node!("arg2".to_string(), 1, 14), value_node!("arg2".to_string(), 1, 14),
], ],
fields: vec![ fields: vec![(
(
make_tok!("foo", 1, 25), make_tok!("foo", 1, 25),
Expression::Simple(Value::Selector(make_selector!( Expression::Simple(Value::Selector(make_selector!(
make_expr!("arg1", 1, 31), make_expr!("arg1", 1, 31),
1, 1,
31 31
))), ))),
), )],
],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}) })
); );
@ -569,12 +567,10 @@ fn test_expression_parse() {
8 8
)))), )))),
default: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 13)))), default: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 13)))),
tuple: vec![ tuple: vec![(
(
make_tok!("foo", 1, 18), make_tok!("foo", 1, 18),
Expression::Simple(Value::Int(value_node!(2, 1, 24))), Expression::Simple(Value::Int(value_node!(2, 1, 24))),
), )],
],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}) })
); );
@ -693,12 +689,10 @@ fn test_select_parse() {
8 8
)))), )))),
default: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 13)))), default: Box::new(Expression::Simple(Value::Int(value_node!(1, 1, 13)))),
tuple: vec![ tuple: vec![(
(
make_tok!("foo", 1, 18), make_tok!("foo", 1, 18),
Expression::Simple(Value::Int(value_node!(2, 1, 24))), Expression::Simple(Value::Int(value_node!(2, 1, 24))),
), )],
],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}) })
); );
@ -759,12 +753,10 @@ fn test_copy_parse() {
copy_expression("foo{bar=1}"), copy_expression("foo{bar=1}"),
Expression::Copy(CopyDef { Expression::Copy(CopyDef {
selector: make_selector!(make_expr!("foo", 1, 1), 1, 1), selector: make_selector!(make_expr!("foo", 1, 1), 1, 1),
fields: vec![ fields: vec![(
(
make_tok!("bar", 1, 5), make_tok!("bar", 1, 5),
Expression::Simple(Value::Int(value_node!(1, 1, 9))), Expression::Simple(Value::Int(value_node!(1, 1, 9))),
), )],
],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}) })
); );
@ -772,12 +764,10 @@ fn test_copy_parse() {
copy_expression("foo{bar=1,}"), copy_expression("foo{bar=1,}"),
Expression::Copy(CopyDef { Expression::Copy(CopyDef {
selector: make_selector!(make_expr!("foo", 1, 1), 1, 1), selector: make_selector!(make_expr!("foo", 1, 1), 1, 1),
fields: vec![ fields: vec![(
(
make_tok!("bar", 1, 5), make_tok!("bar", 1, 5),
Expression::Simple(Value::Int(value_node!(1, 1, 9))), Expression::Simple(Value::Int(value_node!(1, 1, 9))),
), )],
],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}) })
); );
@ -813,13 +803,11 @@ fn test_list_value_parse() {
assert_parse!( assert_parse!(
list_value("[foo]"), list_value("[foo]"),
Value::List(ListDef { Value::List(ListDef {
elems: vec![ elems: vec![Expression::Simple(Value::Selector(make_selector!(
Expression::Simple(Value::Selector(make_selector!(
make_expr!("foo", 1, 2), make_expr!("foo", 1, 2),
1, 1,
2 2
))), )))],
],
pos: Position::new(1, 1), pos: Position::new(1, 1),
}) })
); );
@ -906,12 +894,10 @@ fn test_tuple_parse() {
assert_parse!( assert_parse!(
tuple("{ foo = 1 }"), tuple("{ foo = 1 }"),
Value::Tuple(value_node!( Value::Tuple(value_node!(
vec![ vec![(
(
make_tok!("foo", 1, 3), make_tok!("foo", 1, 3),
Expression::Simple(Value::Int(value_node!(1, 1, 9))), Expression::Simple(Value::Int(value_node!(1, 1, 9))),
), )],
],
1, 1,
1 1
)) ))
@ -920,12 +906,10 @@ fn test_tuple_parse() {
assert_parse!( assert_parse!(
tuple("// comment\n{ foo = 1 }"), tuple("// comment\n{ foo = 1 }"),
Value::Tuple(value_node!( Value::Tuple(value_node!(
vec![ vec![(
(
make_tok!("foo", 2, 3), make_tok!("foo", 2, 3),
Expression::Simple(Value::Int(value_node!(1, 2, 9))), Expression::Simple(Value::Int(value_node!(1, 2, 9))),
), )],
],
1, 1,
1 1
)) ))
@ -934,12 +918,10 @@ fn test_tuple_parse() {
assert_parse!( assert_parse!(
tuple("{// comment\n foo = 1 }"), tuple("{// comment\n foo = 1 }"),
Value::Tuple(value_node!( Value::Tuple(value_node!(
vec![ vec![(
(
make_tok!("foo", 2, 2), make_tok!("foo", 2, 2),
Expression::Simple(Value::Int(value_node!(1, 2, 8))), Expression::Simple(Value::Int(value_node!(1, 2, 8))),
), )],
],
1, 1,
1 1
)) ))
@ -948,12 +930,10 @@ fn test_tuple_parse() {
assert_parse!( assert_parse!(
tuple("{ foo = 1// comment\n }"), tuple("{ foo = 1// comment\n }"),
Value::Tuple(value_node!( Value::Tuple(value_node!(
vec![ vec![(
(
make_tok!("foo", 1, 3), make_tok!("foo", 1, 3),
Expression::Simple(Value::Int(value_node!(1, 1, 9))), Expression::Simple(Value::Int(value_node!(1, 1, 9))),
), )],
],
1, 1,
1 1
)) ))

View File

@ -16,8 +16,8 @@
use ast::*; use ast::*;
use error; use error;
use nom; use nom;
use nom::{InputIter, InputLength, Slice};
use nom::{alpha, digit, is_alphanumeric, multispace}; use nom::{alpha, digit, is_alphanumeric, multispace};
use nom::{InputIter, InputLength, Slice};
use nom_locate::LocatedSpan; use nom_locate::LocatedSpan;
use std; use std;
use std::result::Result; use std::result::Result;

View File

@ -170,13 +170,11 @@ fn test_parse_comment() {
#[test] #[test]
fn test_match_word() { fn test_match_word() {
let input = vec![ let input = vec![Token {
Token {
fragment: "foo".to_string(), fragment: "foo".to_string(),
typ: TokenType::BAREWORD, typ: TokenType::BAREWORD,
pos: Position { line: 1, column: 1 }, pos: Position { line: 1, column: 1 },
}, }];
];
let result = word!( let result = word!(
TokenIter { TokenIter {
source: input.as_slice(), source: input.as_slice(),
@ -191,13 +189,11 @@ fn test_match_word() {
#[test] #[test]
fn test_match_word_empty_input() { fn test_match_word_empty_input() {
let input = vec![ let input = vec![Token {
Token {
fragment: "".to_string(), fragment: "".to_string(),
typ: TokenType::END, typ: TokenType::END,
pos: Position { line: 1, column: 1 }, pos: Position { line: 1, column: 1 },
}, }];
];
let result = word!( let result = word!(
TokenIter { TokenIter {
source: input.as_slice(), source: input.as_slice(),
@ -217,13 +213,11 @@ fn test_match_word_empty_input() {
#[test] #[test]
fn test_match_punct() { fn test_match_punct() {
let input = vec![ let input = vec![Token {
Token {
fragment: "!".to_string(), fragment: "!".to_string(),
typ: TokenType::PUNCT, typ: TokenType::PUNCT,
pos: Position { line: 1, column: 1 }, pos: Position { line: 1, column: 1 },
}, }];
];
let result = punct!( let result = punct!(
TokenIter { TokenIter {
source: input.as_slice(), source: input.as_slice(),
@ -238,13 +232,11 @@ fn test_match_punct() {
#[test] #[test]
fn test_match_type() { fn test_match_type() {
let input = vec![ let input = vec![Token {
Token {
fragment: "foo".to_string(), fragment: "foo".to_string(),
typ: TokenType::BAREWORD, typ: TokenType::BAREWORD,
pos: Position { line: 1, column: 1 }, pos: Position { line: 1, column: 1 },
}, }];
];
let result = match_type!( let result = match_type!(
TokenIter { TokenIter {
source: input.as_slice(), source: input.as_slice(),