blob: f5f1a03a73c0dd72d58689a0b5195ea7ac9a561a [file] [log] [blame]
David Tolnayfa0edf22016-09-23 22:58:24 -07001#![cfg(feature = "full")]
2
3extern crate syn;
4use syn::*;
5
6#[test]
7fn test_box() {
8 let raw = "box 0";
9
10 let expected = Expr::Box(Box::new(
11 Expr::Lit(Lit::Int(0, IntTy::Unsuffixed))
12 ));
13
14 assert_eq!(expected, parse_expr(raw).unwrap());
15}
Gregory Katze5f35682016-09-27 14:20:55 -040016
17#[test]
David Tolnay210884d2016-10-01 08:18:42 -070018fn test_cooked_string() {
19 let raw = r#""a\nb""#;
20
21 let expected = Expr::Lit(Lit::Str("a\nb".into(), StrStyle::Cooked));
22
23 assert_eq!(expected, parse_expr(raw).unwrap());
24}
25
26#[test]
27fn test_raw_string() {
28 let raw = r#"r"a\nb""#;
29
30 let expected = Expr::Lit(Lit::Str(r"a\nb".into(), StrStyle::Raw(0)));
31
32 assert_eq!(expected, parse_expr(raw).unwrap());
33}
34#[test]
35fn test_raw_string_2() {
36 let raw = r###"r##"a\n"#b"##"###;
37
38 let expected = Expr::Lit(Lit::Str(r##"a\n"#b"##.into(), StrStyle::Raw(2)));
39
40 assert_eq!(expected, parse_expr(raw).unwrap());
41}
42
43#[test]
Gregory Katze5f35682016-09-27 14:20:55 -040044fn test_unnamed_loop() {
45 let block = match parse_expr("{ ( 1, 3, 8 ) }").unwrap() {
46 Expr::Block(b) => b,
47 _ => panic!("Could not run test_unnamed_loop: error in block parse."),
48 };
49
50 let raw = "loop {(1, 3, 8 )}";
51
52 let expected = Expr::Loop(block, None);
53
54 assert_eq!(expected, parse_expr(raw).unwrap());
55}
56
57#[test]
58fn test_named_loop() {
59 let block = match parse_expr("{ ( 1, 5, 9, 11) }").unwrap() {
60 Expr::Block(b) => b,
61 _ => panic!("Could not run named_loop: error in block parse."),
62 };
63
64 let raw = "' test : loop{(1, 5, 9, 11)}";
65
Gregory Katz1b69f682016-09-27 21:06:09 -040066 let expected = Expr::Loop(block, Some("'test".into()));
Gregory Katze5f35682016-09-27 14:20:55 -040067
68 assert_eq!(expected, parse_expr(raw).unwrap());
69}
Gregory Katz3e562cc2016-09-28 18:33:02 -040070
71#[test]
72// Ignore test until bool parsing is available
73#[ignore]
74fn test_unnamed_while() {
75 let block = match parse_expr("{ ( 1, 3, 8 ) }").unwrap() {
76 Expr::Block(b) => b,
77 _ => panic!("Could not run test_unnamed_while: error in block parse."),
78 };
79
80 let raw = "while true {(1, 3, 8 )}";
81
82 let expected = Expr::While(Box::new(Expr::Lit(Lit::Bool(true))), block, None);
83
84 assert_eq!(expected, parse_expr(raw).unwrap());
85}
86
87#[test]
88// Ignore test until bool parsing is available
89#[ignore]
90fn test_named_while() {
91 let block = match parse_expr("{ ( 1, 5, 9, 11) }").unwrap() {
92 Expr::Block(b) => b,
93 _ => panic!("Could not run named_while: error in block parse."),
94 };
95
96 let raw = "' test : while true {(1, 5, 9, 11)}";
97
98 let expected = Expr::While(Box::new(Expr::Lit(Lit::Bool(true))), block, Some("'test".into()));
99
100 assert_eq!(expected, parse_expr(raw).unwrap());
101}