mirror of
https://github.com/icewind1991/ivory.git
synced 2026-06-03 10:44:09 +02:00
return type casting for arrays
This commit is contained in:
parent
1ec6938bfa
commit
f20c2b5fd3
6 changed files with 108 additions and 15 deletions
|
|
@ -2,8 +2,8 @@ use std::fmt::Debug;
|
|||
|
||||
use crate::imported::imported_fn;
|
||||
use ivory::externs::printf;
|
||||
use ivory::PhpVal;
|
||||
use ivory::{ivory_export, ivory_module};
|
||||
use ivory::{ArrayKey, PhpVal};
|
||||
|
||||
mod imported;
|
||||
|
||||
|
|
@ -66,6 +66,30 @@ fn return_string() -> String {
|
|||
"some string data".to_string()
|
||||
}
|
||||
|
||||
#[ivory_export]
|
||||
fn return_array_simple() -> Vec<i32> {
|
||||
vec![-10, 10, 0]
|
||||
}
|
||||
|
||||
#[ivory_export]
|
||||
fn return_array_gap() -> Vec<(u32, i32)> {
|
||||
vec![(0u32, -10), (1, 10), (10, 0)]
|
||||
}
|
||||
|
||||
#[ivory_export]
|
||||
fn return_array_mixed() -> Vec<(ArrayKey, PhpVal)> {
|
||||
vec![
|
||||
(0u32.into(), PhpVal::from(-10)),
|
||||
("foo".to_string().into(), PhpVal::from(10)),
|
||||
("bar".to_string().into(), PhpVal::from(0.5)),
|
||||
]
|
||||
}
|
||||
|
||||
#[ivory_export]
|
||||
fn return_array_nested() -> Vec<Vec<i32>> {
|
||||
vec![vec![1, 2], vec![3, 4]]
|
||||
}
|
||||
|
||||
ivory_module!({
|
||||
name: "tests",
|
||||
version: "0.0.1",
|
||||
|
|
|
|||
|
|
@ -105,6 +105,26 @@ test_return!(
|
|||
"return_string",
|
||||
"Command line code:1:\nstring(16) \"some string data\"\n"
|
||||
);
|
||||
test_return!(
|
||||
test_return_array_simple,
|
||||
"return_array_simple",
|
||||
"Command line code:1:\narray(3) {\n [0] =>\n int(-10)\n [1] =>\n int(10)\n [2] =>\n int(0)\n}\n"
|
||||
);
|
||||
test_return!(
|
||||
test_return_array_gap,
|
||||
"return_array_gap",
|
||||
"Command line code:1:\narray(3) {\n [0] =>\n int(-10)\n [1] =>\n int(10)\n [10] =>\n int(0)\n}\n"
|
||||
);
|
||||
test_return!(
|
||||
test_return_array_mixed,
|
||||
"return_array_mixed",
|
||||
"Command line code:1:\narray(3) {\n [0] =>\n int(-10)\n \'foo\' =>\n int(10)\n \'bar\' =>\n double(0.5)\n}\n"
|
||||
);
|
||||
test_return!(
|
||||
test_return_array_nested,
|
||||
"return_array_nested",
|
||||
"Command line code:1:\narray(2) {\n [0] =>\n array(2) {\n [0] =>\n int(1)\n [1] =>\n int(2)\n }\n [1] =>\n array(2) {\n [0] =>\n int(3)\n [1] =>\n int(4)\n }\n}\n"
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_imported() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue