mirror of
https://github.com/icewind1991/ivory.git
synced 2026-06-03 10:44:09 +02:00
integration tests for return types
This commit is contained in:
parent
db1ce0dcd4
commit
bbc0c97025
2 changed files with 62 additions and 0 deletions
|
|
@ -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",
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue