4 // normal run-until-success hook tests
7 define_hook("test_hook", RUN_HOOK_UNTIL_SUCCESS);
9 teardown: function () {
10 test_hook = undefined;
12 test_run_until_success_1: function () {
13 add_hook("test_hook", function () { return null; });
14 add_hook("test_hook", function () { return 2; });
15 add_hook("test_hook", function () { return 3; });
16 assert_equals(test_hook.run(), 2);
20 // coroutine hook tests
22 suite_setup: function () {},
23 suite_teardown: function () {},
25 define_coroutine_hook("test_hook");
27 teardown: function () {
28 test_hook = undefined;
30 test_synchronous_coroutine_hook: function () {
32 function inc_a () { a += 1; }
33 add_hook("test_hook", inc_a);
34 co_call(test_hook.run());
37 test_asynchronous_coroutine_hook: function () {
43 cont = yield CONTINUATION;
44 str += (yield SUSPEND);
47 function () str += "b");
48 co_call(test_hook.run());
50 assert_equals(str, "acb");
54 //coroutine run-until-success hook tests
57 define_coroutine_hook("test_hook", RUN_HOOK_UNTIL_SUCCESS);
59 teardown: function () {
60 test_hook = undefined;
62 test_coroutine_run_until_success_1: function () {
63 add_hook("test_hook", function () { return null; });
64 add_hook("test_hook", function () { return 2; });
65 add_hook("test_hook", function () { return 3; });
68 x = yield test_hook.run();
73 test_coroutine_run_until_success_2: function () {
77 add_hook("test_hook", function () {
78 cont = yield CONTINUATION;
82 add_hook("test_hook", function () { yield co_return(2); });
83 add_hook("test_hook", function () { yield co_return(3); });
85 x = yield test_hook.run();
89 assert_equals(q, false);