@@ -42,7 +42,7 @@ mod test_utils;
4242
4343#[ cfg( test) ]
4444use pretty_assertions:: assert_eq;
45- use sqlparser:: ast:: Expr :: Identifier ;
45+ use sqlparser:: ast:: Expr :: { Identifier , UnaryOp } ;
4646use sqlparser:: test_utils:: all_dialects_except;
4747
4848#[ test]
@@ -4778,6 +4778,33 @@ fn parse_aggregate_with_group_by() {
47784778 //TODO: assertions
47794779}
47804780
4781+ #[ test]
4782+ fn parse_literal_integer ( ) {
4783+ let sql = "SELECT 1, -10, +20" ;
4784+ let select = verified_only_select ( sql) ;
4785+ assert_eq ! ( 3 , select. projection. len( ) ) ;
4786+ assert_eq ! (
4787+ & Expr :: Value ( number( "1" ) ) ,
4788+ expr_from_projection( & select. projection[ 0 ] ) ,
4789+ ) ;
4790+ // negative literal is parsed as a - and expr
4791+ assert_eq ! (
4792+ & UnaryOp {
4793+ op: UnaryOperator :: Minus ,
4794+ expr: Box :: new( Expr :: Value ( number( "10" ) ) )
4795+ } ,
4796+ expr_from_projection( & select. projection[ 1 ] ) ,
4797+ ) ;
4798+ // positive literal is parsed as a + and expr
4799+ assert_eq ! (
4800+ & UnaryOp {
4801+ op: UnaryOperator :: Plus ,
4802+ expr: Box :: new( Expr :: Value ( number( "20" ) ) )
4803+ } ,
4804+ expr_from_projection( & select. projection[ 2 ] ) ,
4805+ )
4806+ }
4807+
47814808#[ test]
47824809fn parse_literal_decimal ( ) {
47834810 // These numbers were explicitly chosen to not roundtrip if represented as
0 commit comments