-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtest_coroutine.dao
91 lines (62 loc) · 1.34 KB
/
test_coroutine.dao
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
routine Foo( a = 0, b = "" )=>[?]
{
io.writeln( "Foo():", a );
return yield( 2 * a, "by Foo()" );
}
routine Bar( a = 0, b = "" )=>[?]
{
io.writeln( "Bar():", a, b );
( r, s ) = Foo( a + 1, b );
io.writeln( "Bar():", r, s );
( r, s ) = yield( a + 100, b );
io.writeln( "Bar():", r, s );
return a, "ended";
}
global co = Bar::( 100, "AA" );
@[test(code_01)]
io.writeln( "Main: ", co() );
@[test(code_01)]
@[test(code_01)]
Bar(): 100 AA
Foo(): 101
Main: ( 202, "by Foo()" )
@[test(code_01)]
@[test(code_01)]
io.writeln( "Main: ", co( 200, "XX" ) );
@[test(code_01)]
@[test(code_01)]
Bar(): 200 XX
Main: ( 200, "AA" )
@[test(code_01)]
@[test(code_01)]
io.writeln( "Main: ", co( 300, "YY" ) );
@[test(code_01)]
@[test(code_01)]
Bar(): 300 YY
Main: ( 100, "ended" )
@[test(code_01)]
@[test(code_01)]
# coroutine has been finished, the following will rise an exception.
io.writeln( "Main: ", co( 400, "ZZ" ) );
@[test(code_01)]
@[test(code_01)]
{{Exception.Warning}} .* {{coroutine execution is finished}}
@[test(code_01)]
@[test(code_01)]
routine Test()
{
yield( 1 ) # Error: cannot yield;
}
@[test(code_01)]
@[test(code_01)]
{{Cannot yield from normal function}} .* {{ERROR}} .* {{At line}}
@[test(code_01)]
@[test(code_01)]
routine Test()
{
return 1
}
co2 = Test::() # Error???
@[test(code_01)]
@[test(code_01)]
@[test(code_01)]