diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 0f7a88d7..bebd33d1 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -42,7 +42,7 @@ mod test_utils; #[cfg(test)] use pretty_assertions::assert_eq; -use sqlparser::ast::Expr::Identifier; +use sqlparser::ast::Expr::{Identifier, UnaryOp}; use sqlparser::test_utils::all_dialects_except; #[test] @@ -4778,6 +4778,33 @@ fn parse_aggregate_with_group_by() { //TODO: assertions } +#[test] +fn parse_literal_integer() { + let sql = "SELECT 1, -10, +20"; + let select = verified_only_select(sql); + assert_eq!(3, select.projection.len()); + assert_eq!( + &Expr::Value(number("1")), + expr_from_projection(&select.projection[0]), + ); + // negative literal is parsed as a - and expr + assert_eq!( + &UnaryOp { + op: UnaryOperator::Minus, + expr: Box::new(Expr::Value(number("10"))) + }, + expr_from_projection(&select.projection[1]), + ); + // positive literal is parsed as a + and expr + assert_eq!( + &UnaryOp { + op: UnaryOperator::Plus, + expr: Box::new(Expr::Value(number("20"))) + }, + expr_from_projection(&select.projection[2]), + ) +} + #[test] fn parse_literal_decimal() { // These numbers were explicitly chosen to not roundtrip if represented as