Skip to content

Commit

Permalink
Add a test showing how negative constants are parsed (#1421)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Sep 10, 2024
1 parent 8dbcbb3 commit cb0c511
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cb0c511

Please sign in to comment.