1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use rune_testing::*;
#[test]
fn test_external_function() -> Result<()> {
// NB: here we test passing the function from one virtual machine instance
// into another, making sure that the function holds everything it needs to
// be called.
let function: Function = run(
&["main"],
(),
r#"
fn test() { 42 }
fn main() { test }
"#,
)?;
let output: i64 = run(
&["main"],
(function,),
r#"
fn main(f) { f() }
"#,
)?;
assert_eq!(42, output);
Ok(())
}
#[test]
fn test_external_generator() -> Result<()> {
// NB: here we test passing the generator from one virtual machine instance
// into another, making sure that the function holds everything it needs to
// be called.
let function: Function = run(
&["main"],
(),
r#"
fn test() { yield 42; }
fn main() { test }
"#,
)?;
let output: (Option<i64>, Option<i64>) = run(
&["main"],
(function,),
r#"
fn main(f) { let gen = f(); (gen.next(), gen.next()) }
"#,
)?;
assert_eq!((Some(42), None), output);
Ok(())
}