File tree 2 files changed +34
-0
lines changed
pgx-utils/src/sql_entity_graph/pg_extern
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 3
3
4
4
use pgx:: * ;
5
5
6
+ #[ pg_extern]
7
+ fn negative_default_argument ( i : default ! ( i32 , -1 ) ) -> i32 {
8
+ i
9
+ }
10
+
6
11
#[ pg_extern]
7
12
fn default_argument ( a : default ! ( i32 , 99 ) ) -> i32 {
8
13
a
@@ -27,6 +32,13 @@ mod tests {
27
32
#[ test]
28
33
fn make_idea_happy ( ) { }
29
34
35
+ #[ pg_test]
36
+ fn test_negative_default_argument ( ) {
37
+ let result = Spi :: get_one :: < i32 > ( "SELECT negative_default_argument();" )
38
+ . expect ( "didn't get SPI result" ) ;
39
+ assert_eq ! ( result, -1 ) ;
40
+ }
41
+
30
42
#[ pg_test]
31
43
fn test_default_argument ( ) {
32
44
let result =
Original file line number Diff line number Diff line change @@ -192,6 +192,28 @@ fn handle_default(
192
192
let value = def. value ( ) ;
193
193
Ok ( ( true_ty, Some ( value. to_string ( ) ) ) )
194
194
}
195
+ syn:: Expr :: Unary ( syn:: ExprUnary {
196
+ op : syn:: UnOp :: Neg ( _) ,
197
+ ref expr,
198
+ ..
199
+ } ) => match & * * expr {
200
+ syn:: Expr :: Lit ( syn:: ExprLit {
201
+ lit : syn:: Lit :: Int ( def) ,
202
+ ..
203
+ } ) => {
204
+ let value = def. base10_digits ( ) ;
205
+ Ok ( ( true_ty, Some ( "-" . to_owned ( ) + value) ) )
206
+ }
207
+ _ => {
208
+ return Err ( syn:: Error :: new (
209
+ Span :: call_site ( ) ,
210
+ format ! (
211
+ "Unrecognized UnaryExpr in `default!()` macro, got: {:?}" ,
212
+ out. expr
213
+ ) ,
214
+ ) )
215
+ }
216
+ } ,
195
217
syn:: Expr :: Type ( syn:: ExprType { ref ty, .. } ) => match ty. deref ( ) {
196
218
syn:: Type :: Path ( syn:: TypePath {
197
219
path : syn:: Path { segments, .. } ,
You can’t perform that action at this time.
0 commit comments