mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-23 15:34:09 +00:00
Add a test showing how negative constants are parsed (#1421)
This commit is contained in:
parent
8dbcbb3c27
commit
cb0c511b05
1 changed files with 28 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue