@@ -28,7 +28,7 @@ impl ops::Deref for ExprChain {
28
28
}
29
29
30
30
/// A rune expression.
31
- #[ derive( Debug , Clone , ToTokens , Spanned ) ]
31
+ #[ derive( Debug , Clone , ToTokens , Spanned , PartialEq , Eq ) ]
32
32
pub enum Expr {
33
33
/// The `self` keyword.
34
34
Self_ ( ast:: Self_ ) ,
@@ -584,45 +584,36 @@ impl Expr {
584
584
/// # Examples
585
585
///
586
586
/// ```rust
587
- /// use rune::{parse_all , ast};
587
+ /// use rune::{testing , ast};
588
588
///
589
- /// parse_all:: <ast::Expr>("foo[\"foo\"]").unwrap( );
590
- /// parse_all:: <ast::Expr>("foo.bar()").unwrap( );
591
- /// parse_all:: <ast::Expr>("var()").unwrap( );
592
- /// parse_all:: <ast::Expr>("var").unwrap( );
593
- /// parse_all:: <ast::Expr>("42").unwrap( );
594
- /// parse_all:: <ast::Expr>("1 + 2 / 3 - 4 * 1").unwrap( );
595
- /// parse_all:: <ast::Expr>("foo[\"bar\"]").unwrap( );
596
- /// parse_all:: <ast::Expr>("let var = 42").unwrap( );
597
- /// parse_all:: <ast::Expr>("let var = \"foo bar\"").unwrap( );
598
- /// parse_all:: <ast::Expr>("var[\"foo\"] = \"bar\"").unwrap( );
599
- /// parse_all:: <ast::Expr>("let var = objects[\"foo\"] + 1").unwrap( );
600
- /// parse_all:: <ast::Expr>("var = 42").unwrap( );
589
+ /// testing::roundtrip:: <ast::Expr>("foo[\"foo\"]");
590
+ /// testing::roundtrip:: <ast::Expr>("foo.bar()");
591
+ /// testing::roundtrip:: <ast::Expr>("var()");
592
+ /// testing::roundtrip:: <ast::Expr>("var");
593
+ /// testing::roundtrip:: <ast::Expr>("42");
594
+ /// testing::roundtrip:: <ast::Expr>("1 + 2 / 3 - 4 * 1");
595
+ /// testing::roundtrip:: <ast::Expr>("foo[\"bar\"]");
596
+ /// testing::roundtrip:: <ast::Expr>("let var = 42");
597
+ /// testing::roundtrip:: <ast::Expr>("let var = \"foo bar\"");
598
+ /// testing::roundtrip:: <ast::Expr>("var[\"foo\"] = \"bar\"");
599
+ /// testing::roundtrip:: <ast::Expr>("let var = objects[\"foo\"] + 1");
600
+ /// testing::roundtrip:: <ast::Expr>("var = 42");
601
601
///
602
- /// let expr = parse_all ::<ast::Expr>(r#"
602
+ /// let expr = testing::roundtrip ::<ast::Expr>(r#"
603
603
/// if 1 { } else { if 2 { } else { } }
604
- /// "#).unwrap();
605
- ///
606
- /// if let ast::Expr::ExprIf(..) = expr {
607
- /// } else {
608
- /// panic!("not an if statement");
609
- /// }
604
+ /// "#);
605
+ /// assert!(matches!(expr, ast::Expr::ExprIf(..)));
610
606
///
611
607
/// // Chained function calls.
612
- /// parse_all:: <ast::Expr>("foo.bar.baz()").unwrap( );
613
- /// parse_all:: <ast::Expr>("foo[0][1][2]").unwrap( );
614
- /// parse_all:: <ast::Expr>("foo.bar()[0].baz()[1]").unwrap( );
608
+ /// testing::roundtrip:: <ast::Expr>("foo.bar.baz()");
609
+ /// testing::roundtrip:: <ast::Expr>("foo[0][1][2]");
610
+ /// testing::roundtrip:: <ast::Expr>("foo.bar()[0].baz()[1]");
615
611
///
616
- /// parse_all:: <ast::Expr>("42 is int::int").unwrap( );
617
- /// parse_all:: <ast::Expr>("{ let x = 1; x }").unwrap( );
612
+ /// testing::roundtrip:: <ast::Expr>("42 is int::int");
613
+ /// testing::roundtrip:: <ast::Expr>("{ let x = 1; x }");
618
614
///
619
- /// let expr = parse_all::<ast::Expr>("#[cfg(debug_assertions)] { assert_eq(x, 32); }").unwrap();
620
- /// if let ast::Expr::ExprBlock(block_expr) = expr {
621
- /// assert_eq!(block_expr.attributes.len(), 1);
622
- /// assert_eq!(block_expr.block.statements.len(), 1);
623
- /// } else {
624
- /// panic!("not a block statement")
625
- /// }
615
+ /// let expr = testing::roundtrip::<ast::Expr>("#[cfg(debug_assertions)] { assert_eq(x, 32); }");
616
+ /// assert!(matches!(expr, ast::Expr::ExprBlock(b) if b.attributes.len() == 1 && b.block.statements.len() == 1));
626
617
/// ```
627
618
impl Parse for Expr {
628
619
fn parse ( parser : & mut Parser < ' _ > ) -> Result < Self , ParseError > {
0 commit comments