From ba2ef3438705057431b36bf51594db80e1aa8655 Mon Sep 17 00:00:00 2001 From: Magnus Hallin <mhallin@fastmail.com> Date: Sun, 26 Feb 2017 11:42:58 +0100 Subject: [PATCH] Add tests for complex default arguments --- src/macros/tests/args.rs | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/macros/tests/args.rs b/src/macros/tests/args.rs index 91375fc4..61bcb53d 100644 --- a/src/macros/tests/args.rs +++ b/src/macros/tests/args.rs @@ -14,10 +14,19 @@ Syntax to validate: * Single arg vs. multi arg * Trailing comma vs. no trailing comma * Default value vs. no default value +* Complex default value * Description vs. no description */ +graphql_input_object!( + #[derive(Debug)] + struct Point { + x: i64, + y: i64, + } +); + graphql_object!(Root: () |&self| { field simple() -> i64 { 0 } field exec_arg(&executor) -> i64 { 0 } @@ -62,6 +71,11 @@ graphql_object!(Root: () |&self| { arg1 = 123: i64 as "The first arg", arg2 = 456: i64 as "The second arg", ) -> i64 { 0 } + + field args_with_complex_default( + arg1 = ("test".to_owned()): String as "A string default argument", + arg2 = (Point { x: 1, y: 2 }): Point as "An input object default argument", + ) -> i64 { 0 } }); fn run_args_info_query<F>(field_name: &str, f: F) @@ -461,3 +475,30 @@ fn introspect_field_multi_args_with_default_trailing_comma_descr() { ].into_iter().collect()))); }); } + +#[test] +fn introspect_field_args_with_complex_default() { + run_args_info_query("argsWithComplexDefault", |args| { + assert_eq!(args.len(), 2); + + assert!(args.contains(&Value::object(vec![ + ("name", Value::string("arg1")), + ("description", Value::string("A string default argument")), + ("defaultValue", Value::string(r#""test""#)), + ("type", Value::object(vec![ + ("name", Value::string("String")), + ("ofType", Value::null()), + ].into_iter().collect())), + ].into_iter().collect()))); + + assert!(args.contains(&Value::object(vec![ + ("name", Value::string("arg2")), + ("description", Value::string("An input object default argument")), + ("defaultValue", Value::string(r#"{y: 2, x: 1}"#)), + ("type", Value::object(vec![ + ("name", Value::string("Point")), + ("ofType", Value::null()), + ].into_iter().collect())), + ].into_iter().collect()))); + }); +}