integration tests for return types

This commit is contained in:
Robin Appelman 2019-04-05 21:22:14 +02:00
commit bbc0c97025
2 changed files with 62 additions and 0 deletions

View file

@ -40,6 +40,32 @@ fn expect_bool(arg: bool) {
fn expect_option_bool(arg: Option<bool>) { fn expect_option_bool(arg: Option<bool>) {
dump(arg); dump(arg);
} }
#[ivory_export]
fn return_long() -> i64 {
1
}
#[ivory_export]
fn return_double() -> f64 {
0.5
}
#[ivory_export]
fn return_true() -> bool {
true
}
#[ivory_export]
fn return_false() -> bool {
false
}
#[ivory_export]
fn return_string() -> String {
"some string data".to_string()
}
ivory_module!({ ivory_module!({
name: "tests", name: "tests",
version: "0.0.1", version: "0.0.1",

View file

@ -70,6 +70,42 @@ fn test_cast_option() {
assert_debug_eq::<Option<bool>>(None, &result); assert_debug_eq::<Option<bool>>(None, &result);
} }
macro_rules! test_return {
($name:ident, $method:expr, $expected:literal) => {
#[test]
fn $name() {
let result = run_php(&format!("var_dump({}())", $method)).unwrap();
assert_eq!($expected, &result);
}
};
}
test_return!(
test_return_long,
"return_long",
"Command line code:1:\nint(1)\n"
);
test_return!(
test_return_double,
"return_double",
"Command line code:1:\ndouble(0.5)\n"
);
test_return!(
test_return_true,
"return_true",
"Command line code:1:\nbool(true)\n"
);
test_return!(
test_return_false,
"return_false",
"Command line code:1:\nbool(false)\n"
);
test_return!(
test_return_string,
"return_string",
"Command line code:1:\nstring(16) \"some string data\"\n"
);
#[test] #[test]
fn test_imported() { fn test_imported() {
assert_eq!("imported".to_string(), run_php("imported_fn()").unwrap()); assert_eq!("imported".to_string(), run_php("imported_fn()").unwrap());