Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading