Add test which calls function with NULL, to verify that this works.
@@ -61,6 +61,15 @@ impl InOutFuncs for CustomTextFormatSerializedType {
}
}
+#[pg_extern(immutable)]
+fn fn_takes_option(input: Option<CustomTextFormatSerializedType>) -> String {
+ input.map_or("nothing".to_string(), |c| {
+ let mut b = StringInfo::new();
+ c.output(&mut b);
+ b.to_string()
+ })
+}
+
#[derive(Serialize, Deserialize, PostgresType)]
pub struct JsonType {
a: f32,
@@ -88,6 +97,20 @@ mod tests {
assert_eq!(result.c, 3);
}
+ #[pg_test]
+ fn test_call_with_value() {
+ let result = Spi::get_one::<String>(
+ "SELECT fn_takes_option('1.0,2.0,3'::CustomTextFormatSerializedType);",
+ );
+ assert_eq!("1,2,3", result.unwrap());
+ }
+
+ #[pg_test]
+ fn test_call_with_null() {
+ let result = Spi::get_one::<String>("SELECT fn_takes_option(NULL);");
+ assert_eq!(Some(String::from("nothing")), result);
+ }
+
#[pg_test]
fn test_serializedtype() {
let result = Spi::get_one::<CustomTextFormatSerializedType>(
