Skip to content

Commit 64a1a89

Browse files
alambayman-sigma
authored andcommitted
Add a test showing how negative constants are parsed (apache#1421)
1 parent c7758b6 commit 64a1a89

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tests/sqlparser_common.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod test_utils;
4242

4343
#[cfg(test)]
4444
use pretty_assertions::assert_eq;
45-
use sqlparser::ast::Expr::Identifier;
45+
use sqlparser::ast::Expr::{Identifier, UnaryOp};
4646
use sqlparser::test_utils::all_dialects_except;
4747

4848
#[test]
@@ -4779,6 +4779,33 @@ fn parse_aggregate_with_group_by() {
47794779
//TODO: assertions
47804780
}
47814781

4782+
#[test]
4783+
fn parse_literal_integer() {
4784+
let sql = "SELECT 1, -10, +20";
4785+
let select = verified_only_select(sql);
4786+
assert_eq!(3, select.projection.len());
4787+
assert_eq!(
4788+
&Expr::Value(number("1")),
4789+
expr_from_projection(&select.projection[0]),
4790+
);
4791+
// negative literal is parsed as a - and expr
4792+
assert_eq!(
4793+
&UnaryOp {
4794+
op: UnaryOperator::Minus,
4795+
expr: Box::new(Expr::Value(number("10")))
4796+
},
4797+
expr_from_projection(&select.projection[1]),
4798+
);
4799+
// positive literal is parsed as a + and expr
4800+
assert_eq!(
4801+
&UnaryOp {
4802+
op: UnaryOperator::Plus,
4803+
expr: Box::new(Expr::Value(number("20")))
4804+
},
4805+
expr_from_projection(&select.projection[2]),
4806+
)
4807+
}
4808+
47824809
#[test]
47834810
fn parse_literal_decimal() {
47844811
// These numbers were explicitly chosen to not roundtrip if represented as

0 commit comments

Comments
 (0)