Permalink
Browse files

html file for futures unit tests + less browser globals

  • Loading branch information...
1 parent 4aba940 commit 003a9bbbdf68af59423bcd3893edf6ad263a2a1a @bjouhier bjouhier committed Jun 14, 2012
View
@@ -9,10 +9,12 @@
<p><a href="test/common/callbacks/eval-test.html">evaluation unit test</a></p>
<p><a href="test/common/callbacks/flows-test.html">flows unit test</a></p>
<p><a href="test/common/callbacks/stack-test.html">stack unit test</a></p>
+ <p><a href="test/common/callbacks/futures-test.html">futures unit test</a></p>
<h2>Generators Mode (Firefox only)</h2>
<p><a href="examples/streamlineMe/yieldMe.html">interactive demo</a></p>
<p><a href="test/common/generators/eval-test.html">evaluation unit test</a></p>
<p><a href="test/common/generators/flows-test.html">flows unit test</a></p>
<p><a href="test/common/generators/stack-test.html">stack unit test</a></p>
+ <p><a href="test/common/generators/futures-test.html">futures unit test</a></p>
</body>
</html>
@@ -1,11 +1,15 @@
if (!Object.create || !Object.defineProperty || !Object.defineProperties) alert("Example will fail because your browser does not support ECMAScript 5. Try with another browser!");
var __filename = "" + window.location;
+window.Streamline = { globals: {} };
+
function require(str) {
if (str == "streamline/lib/util/flows") return StreamlineFlows;
- else if (str == "streamline/lib/callbacks/runtime") return StreamlineRuntime;
+ else if (str == "streamline/lib/globals") return Streamline.globals;
+ else if (str == "streamline/lib/callbacks/runtime") return Streamline.runtime;
else if (str == "streamline/lib/callbacks/transform") return Streamline;
else if (str == "streamline/lib/callbacks/builtins") return StreamlineBuiltins;
- else if (str == "streamline/lib/globals") return StreamlineRuntime.globals;
+ else if (str == "streamline/lib/globals") return Streamline.globals;
+ else if (str == "streamline/lib/util/future") return Streamline.future;
else alert("cannot require " + str)
}
View
@@ -3,8 +3,8 @@
* MIT License
*/
(function(exports) {
- var __g = exports.globals || require("../globals");
- var __future = require("../util/future").future;
+ var __g = require("streamline/lib/globals");
+ var __future = require("streamline/lib/util/future").future;
__g.context = __g.context || {};
__g.depth = __g.depth || 0;
@@ -75,6 +75,7 @@
var oldFrame = __g.frame;
__g.frame = frame;
__g.context = ctx;
+ var oldFut = __g.future;
__g.future = fut;
__g.depth++;
try {
@@ -97,6 +98,7 @@
frame.active = false;
__g.frame = oldFrame;
if (--__g.depth === 0 && __g.trampoline) __g.trampoline.flush();
+ __g.future = oldFut;
}
}
}
@@ -213,7 +215,5 @@
/// The default is true, but you must require the flows module
/// at least once to enable sync stack traces.
exports.stackTraceEnabled = true;
-})(typeof exports !== 'undefined' ? exports : (window.StreamlineRuntime = window.StreamlineRuntime || {
- globals: {}
-}));
+})(typeof exports !== 'undefined' ? exports : (Streamline.runtime = Streamline.runtime || {}));
require && require("streamline/lib/callbacks/builtins");
View
@@ -15,7 +15,7 @@ _node -lp -v -f -c ../streams/client/streams._js
# compile test files for client too
pushd ../../test/common > /dev/null
_node -lp -v -f -c .
-mv eval-test.js flows-test.js stack-test.js callbacks
+mv eval-test.js flows-test.js stack-test.js futures-test.js callbacks
_node --generators -v -f -c .
-mv eval-test.js flows-test.js stack-test.js generators
+mv eval-test.js flows-test.js stack-test.js futures-test.js generators
popd > /dev/null
View
@@ -10,7 +10,7 @@ require('../util/require')('fibers', module.parent.filename);
* container for the context that the runtime maintains across async calls
*/
var globals = require('../globals');
-var future = require("../util/future").future;
+var future = require("streamline/lib/util/future").future;
/**
* Creates a function that builds a fiber when called and automatically returns a future.
@@ -1,10 +1,6 @@
if (!Object.create || !Object.defineProperty || !Object.defineProperties) alert("Example will fail because your browser does not support ECMAScript 5. Try with another browser!");
var __filename = "" + window.location;
-window.StreamlineRuntime = {
- globals: {}
-};
-
function require(str) {
if (str == "streamline/lib/util/flows") return StreamlineFlows;
else if (str == "streamline/lib/fibers/walker") return StreamlineWalker;
@@ -13,6 +9,7 @@ function require(str) {
else if (str == "streamline/lib/generators/transform") return Streamline;
else if (str == "streamline/lib/generators/builtins") return StreamlineBuiltins;
else if (str == "streamline/lib/globals") return StreamlineRuntime.globals;
+ else if (str == "streamline/lib/util/future") return StreamlineFuture;
else if (str == "streamline/lib/callbacks/transform") return Streamline; // hack for eval test
else alert("cannot require " + str)
}
View
@@ -3,7 +3,7 @@
* MIT License
*/
(function(exports) {
- var globals = exports.globals || require("../globals");
+ var globals = require("streamline/lib/globals");
// unfortunately callee is gone. So we need to pass a function
exports.future = function(fn, args, i) {
@@ -75,5 +75,5 @@
}
return future;
}
-})(typeof exports !== 'undefined' ? exports : (window.StreamlineFuture = window.StreamlineFuture || {}));
+})(typeof exports !== 'undefined' ? exports : (Streamline.future = Streamline.future || {}));
@@ -6,6 +6,7 @@
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="../../qunit/qunit.js"></script>
<script src="../../../lib/callbacks/require-stub.js" type="application/javascript"></script>
+ <script src="../../../lib/util/future.js" type="application/javascript"></script>
<script src="../../../lib/callbacks/runtime.js" type="application/javascript"></script>
<script src="../../../lib/callbacks/builtins.js" type="application/javascript"></script>
<script src="eval-test.js" type="application/javascript" ></script>
@@ -6,6 +6,7 @@
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="../../qunit/qunit.js"></script>
<script src="../../../lib/callbacks/require-stub.js" type="application/javascript"></script>
+ <script src="../../../lib/util/future.js" type="application/javascript"></script>
<script src="../../../lib/callbacks/runtime.js" type="application/javascript"></script>
<script src="../../../lib/callbacks/builtins.js" type="application/javascript"></script>
<script src="../../../lib/util/flows.js" type="application/javascript"></script>
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <script src="../../qunit/jquery.js"></script>
+ <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../../qunit/qunit.js"></script>
+ <script src="../../../lib/callbacks/require-stub.js" type="application/javascript"></script>
+ <script src="../../../lib/util/future.js" type="application/javascript"></script>
+ <script src="../../../lib/callbacks/runtime.js" type="application/javascript"></script>
+ <script src="../../../lib/callbacks/builtins.js" type="application/javascript"></script>
+ <script src="../../../lib/util/flows.js" type="application/javascript"></script>
+ <script src="futures-test.js" type="application/javascript"></script>
+</head>
+<body>
+ <h1 id="qunit-header">streamline futures tests (callbacks)</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
+
@@ -0,0 +1,123 @@
+/*** Generated by streamline 0.4.0b (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__tryCatch=__rt.__tryCatch; var module = QUnit.module;
+var flows = require("streamline/lib/util/flows");
+
+function delay(millis, val, _) { var __frame = { name: "delay", line: 4 }; return __func(_, this, arguments, delay, 2, __frame, function __$delay() {
+ return setTimeout(__cb(_, __frame, 1, 1, function __$delay() {
+ return _(null, val); }, true), millis); });};
+
+
+module("futures");
+
+asyncTest("no timeout", 1, function __1(_) { var f; var __frame = { name: "__1", line: 11 }; return __func(_, this, arguments, __1, 0, __frame, function __$__1() {
+ f = delay(1, "a");
+ return f(__cb(_, __frame, 2, 8, function ___(__0, __1) { equals(__1, "a", "no timeout");
+ start(); _(); }, true)); });});
+
+asyncTest("result before timeout", 1, function __2(_) { var f; var __frame = { name: "__2", line: 16 }; return __func(_, this, arguments, __2, 0, __frame, function __$__2() {
+ f = delay(1, "a");
+ return f(__cb(_, __frame, 2, 8, function ___(__0, __1) { equals(__1, "a", "got result");
+ start(); _(); }, true), 10, "b"); });});
+
+asyncTest("timeout returns before result", 3, function __3(_) { var f; var __frame = { name: "__3", line: 21 }; return __func(_, this, arguments, __3, 0, __frame, function __$__3() {
+ f = delay(10, "a");
+ return f(__cb(_, __frame, 2, 8, function ___(__0, __1) { equals(__1, "b", "got timeout");
+ ok(f.cancelled, "future got cancelled"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__3() {
+
+ return f(__cb(_, __frame, 5, 8, function ___(__0, __2) { equal(__2, "c"); __then(); }, true), { timeout: 10, return: "b" }); }); })(function ___(ex, __result) { __tryCatch(_, function __$__3() { if (ex) {
+
+ equals(ex.message, "future cancelled", "cannot reuse cancelled future"); __then(); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, function __$__3() {
+
+ start(); _(); }); }); }, true), { timeout: 1, return: "b" }); });});
+
+asyncTest("timeout throws before result", 1, function __4(_) { var f; var __frame = { name: "__4", line: 32 }; return __func(_, this, arguments, __4, 0, __frame, function __$__4() {
+ f = delay(10, "a"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() {
+
+ return f(__cb(_, __frame, 3, 8, function ___(__0, __1) { equal(__1, "c"); __then(); }, true), { timeout: 1, throw: "b" }); }); })(function ___(ex, __result) { __tryCatch(_, function __$__4() { if (ex) {
+
+ equals(ex.message, "b", "throws before result"); __then(); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, function __$__4() {
+
+ start(); _(); }); }); });});
+
+asyncTest("probe with return", 2, function __5(_) { var f; var __frame = { name: "__5", line: 41 }; return __func(_, this, arguments, __5, 0, __frame, function __$__5() {
+ f = delay(10, "a");
+ return f(__cb(_, __frame, 2, 7, function ___(__0, __1) { equal(__1, "b", "probe before result");
+ return f(__cb(_, __frame, 3, 7, function ___(__0, __2) { equal(__2, "a", "probe after result");
+ start(); _(); }, true), { timeout: 10, return: "b", probe: true }); }, true), { timeout: 1, return: "b", probe: true }); });});
+
+asyncTest("probe with throw", 2, function __6(_) { var f; var __frame = { name: "__6", line: 47 }; return __func(_, this, arguments, __6, 0, __frame, function __$__6() {
+ f = delay(10, "a"); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {
+
+ return f(__cb(_, __frame, 3, 8, function ___(__0, __1) { equal(__1, "c"); __then(); }, true), { timeout: 1, throw: "b", probe: true }); }); })(function ___(ex, __result) { __tryCatch(_, function __$__6() { if (ex) {
+
+ equals(ex.message, "b", "probe before result"); __then(); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, function __$__6() {
+
+ return f(__cb(_, __frame, 7, 7, function ___(__0, __2) { equal(__2, "a", "probe after result");
+ start(); _(); }, true), { timeout: 10, throw: "b", probe: true }); }); }); });});
+
+
+function delay2(ms1, ms2, val, step, _) { var __frame = { name: "delay2", line: 58 }; return __func(_, this, arguments, delay2, 4, __frame, function __$delay2() {
+ step.i = 1;
+ return setTimeout(__cb(_, __frame, 2, 1, function __$delay2() {
+ step.i++;
+ return setTimeout(__cb(_, __frame, 4, 1, function __$delay2() {
+ step.i++;
+ return _(null, val); }, true), ms2); }, true), ms1); });};
+
+
+
+asyncTest("cancel before first timeout", 4, function __7(_) { var step, f; var __frame = { name: "__7", line: 68 }; return __func(_, this, arguments, __7, 0, __frame, function __$__7() {
+ step = { };
+ f = delay2(5, 5, "a", step);
+ equals(step.i, 1, "step ok");
+ return f(__cb(_, __frame, 4, 8, function ___(__0, __1) { equals(__1, "b", "timed out ok");
+ equals(step.i, 1, "step ok after timeout");
+ return setTimeout(__cb(_, __frame, 6, 1, function __$__7() {
+ equals(step.i, 1, "cancelled ok");
+ start(); _(); }, true), 5); }, true), { timeout: 1, return: "b" }); });});
+
+asyncTest("cancel between first and second timeouts", 4, function __8(_) { var step, f; var __frame = { name: "__8", line: 78 }; return __func(_, this, arguments, __8, 0, __frame, function __$__8() {
+ step = { };
+ f = delay2(5, 5, "a", step);
+ equals(step.i, 1, "step ok");
+ return f(__cb(_, __frame, 4, 8, function ___(__0, __1) { equals(__1, "b", "timed out ok");
+ equals(step.i, 2, "step ok after intermediate timeout");
+ return setTimeout(__cb(_, __frame, 6, 1, function __$__8() {
+ equals(step.i, 2, "cancelled ok");
+ start(); _(); }, true), 5); }, true), { timeout: 8, return: "b" }); });});
+
+
+function join(ms1, ms2, val1, step1, ms3, ms4, val2, step2, _) { var f1, f2; var __frame = { name: "join", line: 89 }; return __func(_, this, arguments, join, 8, __frame, function __$join() {
+ f1 = delay2(ms1, ms2, val1, step1);
+ f2 = delay2(ms3, ms4, val2, step2);
+ return f1(__cb(_, __frame, 3, 8, function ___(__0, __2) { return f2(__cb(_, __frame, 3, 16, function ___(__0, __3) { var __1 = (__2 + __3); return _(null, __1); }, true)); }, true)); });};
+
+
+asyncTest("join returns before timeout", 3, function __9(_) { var step1, step2, f; var __frame = { name: "__9", line: 95 }; return __func(_, this, arguments, __9, 0, __frame, function __$__9() {
+ step1 = { }; step2 = { };
+ f = join(5, 10, "a", step1, 10, 10, "b", step2);
+ return f(__cb(_, __frame, 3, 8, function ___(__0, __1) { equals(__1, "ab", "no timeout ok");
+ equals(step1.i, 3, "step1 ok");
+ equals(step2.i, 3, "step2 ok");
+ start(); _(); }, true), { timeout: 25, return: "c" }); });});
+
+asyncTest("join with short timeout", 5, function __10(_) { var step1, step2, f; var __frame = { name: "__10", line: 103 }; return __func(_, this, arguments, __10, 0, __frame, function __$__10() {
+ step1 = { }; step2 = { };
+ f = join(5, 10, "a", step1, 10, 10, "b", step2);
+ return f(__cb(_, __frame, 3, 8, function ___(__0, __1) { equals(__1, "c", "result ok");
+ equals(step1.i, 2, "step1 ok");
+ equals(step2.i, 1, "step2 ok");
+ return setTimeout(__cb(_, __frame, 6, 1, function __$__10() {
+ equals(step1.i, 2, "step1 cancelled ok");
+ equals(step2.i, 1, "step2 cancelled ok");
+ start(); _(); }, true), 20); }, true), { timeout: 8, return: "c" }); });});
+
+asyncTest("join with intermediate timeout", 5, function __11(_) { var step1, step2, f; var __frame = { name: "__11", line: 114 }; return __func(_, this, arguments, __11, 0, __frame, function __$__11() {
+ step1 = { }; step2 = { };
+ f = join(5, 10, "a", step1, 10, 10, "b", step2);
+ return f(__cb(_, __frame, 3, 8, function ___(__0, __1) { equals(__1, "c", "result ok");
+ equals(step1.i, 3, "step1 ok");
+ equals(step2.i, 2, "step2 ok");
+ return setTimeout(__cb(_, __frame, 6, 1, function __$__11() {
+ equals(step1.i, 3, "step1 cancelled ok");
+ equals(step2.i, 2, "step2 cancelled ok");
+ start(); _(); }, true), 20); }, true), { timeout: 18, return: "c" }); });});
@@ -6,6 +6,7 @@
<link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="../../qunit/qunit.js"></script>
<script src="../../../lib/callbacks/require-stub.js" type="application/javascript"></script>
+ <script src="../../../lib/util/future.js" type="application/javascript"></script>
<script src="../../../lib/callbacks/runtime.js" type="application/javascript"></script>
<script src="../../../lib/callbacks/builtins.js" type="application/javascript"></script>
<script src="../../../lib/util/flows.js" type="application/javascript"></script>
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <script src="../../qunit/jquery.js"></script>
+ <link rel="stylesheet" href="../../qunit/qunit.css" type="text/css" media="screen" />
+ <script type="text/javascript" src="../../qunit/qunit.js"></script>
+ <script src="../../../lib/generators/require-stub.js" type="application/javascript"></script>
+ <script src="../../../lib/util/future.js" type="application/javascript"></script>
+ <script src="../../../lib/generators/runtime.js" type="application/javascript;version=1.7"></script>
+ <script src="../../../lib/generators/builtins.js" type="application/javascript;version=1.7"></script>
+ <script src="../../../lib/util/flows.js" type="application/javascript"></script>
+ <script src="futures-test.js" type="application/javascript;version=1.7"></script>
+</head>
+<body>
+ <h1 id="qunit-header">streamline futures tests (generators)</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
+
Oops, something went wrong.

0 comments on commit 003a9bb

Please sign in to comment.