Closure parsing
diff --git a/tests/cases/function.rs b/tests/cases/function.rs
index 340804a..39775a6 100644
--- a/tests/cases/function.rs
+++ b/tests/cases/function.rs
@@ -1,3 +1,12 @@
fn f() {
- return 1
+ (
+ || (),
+ |_| (),
+ || -> () { () },
+ |a| a,
+ |a, b| a + b,
+ |a: u8, b: u8| a + b,
+ |a, b| -> u8 { a + b },
+ move |a, b| a + b,
+ )
}
diff --git a/tests/test_expr.rs b/tests/test_expr.rs
deleted file mode 100644
index f5f1a03..0000000
--- a/tests/test_expr.rs
+++ /dev/null
@@ -1,101 +0,0 @@
-#![cfg(feature = "full")]
-
-extern crate syn;
-use syn::*;
-
-#[test]
-fn test_box() {
- let raw = "box 0";
-
- let expected = Expr::Box(Box::new(
- Expr::Lit(Lit::Int(0, IntTy::Unsuffixed))
- ));
-
- assert_eq!(expected, parse_expr(raw).unwrap());
-}
-
-#[test]
-fn test_cooked_string() {
- let raw = r#""a\nb""#;
-
- let expected = Expr::Lit(Lit::Str("a\nb".into(), StrStyle::Cooked));
-
- assert_eq!(expected, parse_expr(raw).unwrap());
-}
-
-#[test]
-fn test_raw_string() {
- let raw = r#"r"a\nb""#;
-
- let expected = Expr::Lit(Lit::Str(r"a\nb".into(), StrStyle::Raw(0)));
-
- assert_eq!(expected, parse_expr(raw).unwrap());
-}
-#[test]
-fn test_raw_string_2() {
- let raw = r###"r##"a\n"#b"##"###;
-
- let expected = Expr::Lit(Lit::Str(r##"a\n"#b"##.into(), StrStyle::Raw(2)));
-
- assert_eq!(expected, parse_expr(raw).unwrap());
-}
-
-#[test]
-fn test_unnamed_loop() {
- let block = match parse_expr("{ ( 1, 3, 8 ) }").unwrap() {
- Expr::Block(b) => b,
- _ => panic!("Could not run test_unnamed_loop: error in block parse."),
- };
-
- let raw = "loop {(1, 3, 8 )}";
-
- let expected = Expr::Loop(block, None);
-
- assert_eq!(expected, parse_expr(raw).unwrap());
-}
-
-#[test]
-fn test_named_loop() {
- let block = match parse_expr("{ ( 1, 5, 9, 11) }").unwrap() {
- Expr::Block(b) => b,
- _ => panic!("Could not run named_loop: error in block parse."),
- };
-
- let raw = "' test : loop{(1, 5, 9, 11)}";
-
- let expected = Expr::Loop(block, Some("'test".into()));
-
- assert_eq!(expected, parse_expr(raw).unwrap());
-}
-
-#[test]
-// Ignore test until bool parsing is available
-#[ignore]
-fn test_unnamed_while() {
- let block = match parse_expr("{ ( 1, 3, 8 ) }").unwrap() {
- Expr::Block(b) => b,
- _ => panic!("Could not run test_unnamed_while: error in block parse."),
- };
-
- let raw = "while true {(1, 3, 8 )}";
-
- let expected = Expr::While(Box::new(Expr::Lit(Lit::Bool(true))), block, None);
-
- assert_eq!(expected, parse_expr(raw).unwrap());
-}
-
-#[test]
-// Ignore test until bool parsing is available
-#[ignore]
-fn test_named_while() {
- let block = match parse_expr("{ ( 1, 5, 9, 11) }").unwrap() {
- Expr::Block(b) => b,
- _ => panic!("Could not run named_while: error in block parse."),
- };
-
- let raw = "' test : while true {(1, 5, 9, 11)}";
-
- let expected = Expr::While(Box::new(Expr::Lit(Lit::Bool(true))), block, Some("'test".into()));
-
- assert_eq!(expected, parse_expr(raw).unwrap());
-}
diff --git a/tests/test_round_trip.rs b/tests/test_round_trip.rs
index 65ee39d..eccd2cb 100644
--- a/tests/test_round_trip.rs
+++ b/tests/test_round_trip.rs
@@ -22,7 +22,7 @@
#[test]
fn test_round_trip() {
- let mut success = true;
+ let mut failed = 0;
for entry in walkdir::WalkDir::new("tests/cases").into_iter() {
let entry = entry.unwrap();
@@ -41,7 +41,7 @@
Ok(krate) => krate,
Err(msg) => {
errorf!("syn failed to parse\n{}\n", msg);
- success = false;
+ failed += 1;
continue;
}
};
@@ -54,7 +54,7 @@
Err(mut diagnostic) => {
errorf!("syntex failed to parse");
diagnostic.emit();
- success = false;
+ failed += 1;
continue;
}
};
@@ -63,11 +63,13 @@
errorf!("pass\n");
} else {
errorf!("FAIL\nbefore: {:?}\nafter: {:?}\n", before, after);
- success = false;
+ failed += 1;
}
}
- assert!(success);
+ if failed > 0 {
+ panic!("{} failures", failed);
+ }
}
fn syntex_parse<'a>(content: String, sess: &'a ParseSess) -> PResult<'a, ast::Crate> {
@@ -115,7 +117,12 @@
let folded = fold::noop_fold_expr(e, self);
Expr {
node: match folded.node {
- ExprKind::Lit(l) => ExprKind::Lit(l.map(|l| self.fold_spanned(l))),
+ ExprKind::Lit(l) => {
+ ExprKind::Lit(l.map(|l| self.fold_spanned(l)))
+ }
+ ExprKind::Binary(op, lhs, rhs) => {
+ ExprKind::Binary(self.fold_spanned(op), self.fold_expr(lhs), self.fold_expr(rhs))
+ }
other => other,
},
.. folded