From 08bbce8992b2f5a86880ede500c580476c0ce0bd Mon Sep 17 00:00:00 2001 From: Nickolay Ponomarev Date: Sun, 21 Apr 2019 03:06:36 +0300 Subject: [PATCH] Use assert_matches! instead of matching manually To fix clippy warnings about assert!(true / false) --- Cargo.toml | 1 + tests/sqlparser_generic.rs | 37 +++++++++++++++---------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68fe0f7f..53463a9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,4 @@ uuid = "0.7.1" [dev-dependencies] simple_logger = "1.0.1" +matches = "0.1" diff --git a/tests/sqlparser_generic.rs b/tests/sqlparser_generic.rs index 29bcdc73..3a4019fd 100644 --- a/tests/sqlparser_generic.rs +++ b/tests/sqlparser_generic.rs @@ -1,3 +1,5 @@ +use matches::assert_matches; + use sqlparser::dialect::*; use sqlparser::sqlast::*; use sqlparser::sqlparser::*; @@ -227,23 +229,17 @@ fn parse_not_precedence() { use self::ASTNode::*; // NOT has higher precedence than OR/AND, so the following must parse as (NOT true) OR true let sql = "NOT true OR true"; - match verified_expr(sql) { - SQLBinaryExpr { - op: SQLOperator::Or, - .. - } => assert!(true), - _ => assert!(false), - }; + assert_matches!(verified_expr(sql), SQLBinaryExpr { + op: SQLOperator::Or, + .. + }); // But NOT has lower precedence than comparison operators, so the following parses as NOT (a IS NULL) let sql = "NOT a IS NULL"; - match verified_expr(sql) { - SQLUnary { - operator: SQLOperator::Not, - .. - } => assert!(true), - _ => assert!(false), - }; + assert_matches!(verified_expr(sql), SQLUnary { + operator: SQLOperator::Not, + .. + }); } #[test] @@ -950,14 +946,11 @@ fn parse_multiple_statements() { fn parse_scalar_subqueries() { use self::ASTNode::*; let sql = "(SELECT 1) + (SELECT 2)"; - match verified_expr(sql) { - SQLBinaryExpr { - op: SQLOperator::Plus, .. - //left: box SQLSubquery { .. }, - //right: box SQLSubquery { .. }, - } => assert!(true), - _ => assert!(false), - }; + assert_matches!(verified_expr(sql), SQLBinaryExpr { + op: SQLOperator::Plus, .. + //left: box SQLSubquery { .. }, + //right: box SQLSubquery { .. }, + }); } #[test]