Add a test showing how negative constants are parsed (#1421)

This commit is contained in:
Andrew Lamb 2024-09-10 16:19:13 -04:00 committed by GitHub
parent 8dbcbb3c27
commit cb0c511b05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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