mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-09 12:17:13 +00:00
Compare commits
3
Commits
v0.9.6-RC2
...
commonjs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4080fd91b2 | ||
|
|
82c71617d1 | ||
|
|
c6b3db44da |
+100
-1
@@ -35,7 +35,11 @@ function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String
|
||||
this._function = aFunction || NULL;
|
||||
this._URL = makeAbsoluteURL(aURL || new CFURL("(Anonymous" + (AnonymousExecutableCount++) + ")"));
|
||||
|
||||
this._fileDependencies = fileDependencies;
|
||||
this._fileDependencies = fileDependencies || [];
|
||||
|
||||
#ifndef COMMONJS
|
||||
this._fileDependencies.push.apply(this._fileDependencies, parseRequireFileDependencies(aCode));
|
||||
#endif
|
||||
|
||||
if (fileDependencies.length)
|
||||
{
|
||||
@@ -53,6 +57,23 @@ function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String
|
||||
|
||||
exports.Executable = Executable;
|
||||
|
||||
function parseRequireFileDependencies(aCode)
|
||||
{
|
||||
var dependencies = [];
|
||||
if (aCode)
|
||||
{
|
||||
var pattern = /(?:^|[^\w.])require\s*\(\s*["']([^"']+)["']\s*\)/g;
|
||||
while (match = pattern.exec(aCode))
|
||||
{
|
||||
var id = match[1];
|
||||
if (!(/\.[^\/]+$/).test(id))
|
||||
id += ".js";
|
||||
dependencies.push(new FileDependency(new CFURL(id), (/^[.\/]/).test(id)));
|
||||
}
|
||||
}
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
Executable.prototype.path = function()
|
||||
{
|
||||
return this.URL().path();
|
||||
@@ -73,6 +94,8 @@ Executable.prototype.functionParameters = function()
|
||||
|
||||
#ifdef COMMONJS
|
||||
functionParameters = functionParameters.concat("require", "exports", "module", "system", "print", "window");
|
||||
#else
|
||||
functionParameters = functionParameters.concat("require", "exports", "module");
|
||||
#endif
|
||||
|
||||
return functionParameters;
|
||||
@@ -86,11 +109,65 @@ Executable.prototype.functionArguments = function()
|
||||
|
||||
#ifdef COMMONJS
|
||||
functionArguments = functionArguments.concat(Executable.commonJSArguments());
|
||||
#else
|
||||
functionArguments = functionArguments.concat(this.getCommonJSRequire(), this.getCommonJSExports(), this.getCommonJSModule());
|
||||
#endif
|
||||
|
||||
return functionArguments;
|
||||
}
|
||||
|
||||
Executable.prototype.getCommonJSRequire = function()
|
||||
{
|
||||
if (!this._commonJSRequire)
|
||||
{
|
||||
var executor = this.fileExecuter();
|
||||
var importer = this.fileImporter();
|
||||
|
||||
var req = function(id)
|
||||
{
|
||||
if (!(/\.[^\/]+$/).test(id))
|
||||
id += ".js";
|
||||
|
||||
return executor(id, (id.charAt(0) === "." || id.charAt(0) === "/"), NO);
|
||||
}
|
||||
req.async = function(id, callback) {
|
||||
if (!(/\.[^\/]+$/).test(id))
|
||||
id += ".js";
|
||||
|
||||
importer(id, (id.charAt(0) === "." || id.charAt(0) === "/"), function() {
|
||||
callback(req(id));
|
||||
});
|
||||
};
|
||||
req.paths = OBJJ_INCLUDE_PATHS;
|
||||
this._commonJSRequire = req;
|
||||
}
|
||||
return this._commonJSRequire;
|
||||
}
|
||||
|
||||
Executable.prototype.getCommonJSExports = function()
|
||||
{
|
||||
if (!this._commonJSExports)
|
||||
this._commonJSExports = {};
|
||||
return this._commonJSExports;
|
||||
}
|
||||
|
||||
Executable.prototype.setCommonJSExports = function(commonJSExports)
|
||||
{
|
||||
if (this._commonJSExports)
|
||||
throw "CommonJS exports for " + this.URL() + " already set.";
|
||||
this._commonJSExports = commonJSExports;
|
||||
}
|
||||
|
||||
Executable.prototype.getCommonJSModule = function()
|
||||
{
|
||||
if (!this._commonJSModule)
|
||||
this._commonJSModule = {
|
||||
path : this.path(),
|
||||
url : this.URL().toString()
|
||||
};
|
||||
return this._commonJSModule;
|
||||
}
|
||||
|
||||
DISPLAY_NAME(Executable.prototype.functionArguments);
|
||||
|
||||
#ifdef COMMONJS
|
||||
@@ -350,14 +427,36 @@ Executable.fileExecuterForURL = function(/*CFURL|String*/ aURL)
|
||||
{
|
||||
cachedFileExecuter = function(/*CFURL*/ aURL, /*BOOL*/ isQuoted, /*BOOL*/ shouldForce)
|
||||
{
|
||||
// CommonJS "exports" support:
|
||||
// this is a little hacky. we use the internaly created "exports" if it executes synchronously,
|
||||
// otherwise we have to create our own exports object that we can return immediately
|
||||
// then set it on the executable right before it is eventually executed.
|
||||
var commonJSExports = {},
|
||||
hasSetExports = false,
|
||||
hasReturnedExports = false;
|
||||
|
||||
Executable.fileExecutableSearcherForURL(referenceURL)(aURL, isQuoted,
|
||||
function(/*FileExecutable*/ aFileExecutable)
|
||||
{
|
||||
if (!aFileExecutable.hasLoadedFileDependencies())
|
||||
throw "No executable loaded for file at URL " + aURL;
|
||||
|
||||
if (hasReturnedExports && !hasSetExports)
|
||||
{
|
||||
aFileExecutable.setCommonJSExports(commonJSExports);
|
||||
hasSetExports = true;
|
||||
}
|
||||
|
||||
aFileExecutable.execute(shouldForce);
|
||||
|
||||
if (!hasReturnedExports)
|
||||
{
|
||||
commonJSExports = aFileExecutable.getCommonJSExports();
|
||||
}
|
||||
});
|
||||
|
||||
hasReturnedExports = true;
|
||||
return commonJSExports;
|
||||
}
|
||||
|
||||
cachedFileExecuters[referenceURLString] = cachedFileExecuter;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CPApplicationDelegateClass</key>
|
||||
<string>AppController</string>
|
||||
<key>CPBundleName</key>
|
||||
<string>TestApp</string>
|
||||
<key>CPPrincipalClass</key>
|
||||
<string>CPApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,101 @@
|
||||
<!DOCTYPE html
|
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<!--
|
||||
index-debug.html
|
||||
TestApp
|
||||
|
||||
Created by You on May 11, 2010.
|
||||
Copyright 2010, Your Company All rights reserved.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
|
||||
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||
|
||||
<link rel="apple-touch-icon" href="Resources/icon.png" />
|
||||
<link rel="apple-touch-startup-image" href="Resources/default.png" />
|
||||
|
||||
<title>TestApp</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
OBJJ_MAIN_FILE = "main.j";
|
||||
OBJJ_INCLUDE_PATHS = ["Frameworks/Debug", "Frameworks", "SomethingElse"];
|
||||
</script>
|
||||
|
||||
<script src="Frameworks/Debug/Objective-J/Objective-J.js" type="text/javascript" charset="UTF-8"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
objj_msgSend_reset();
|
||||
|
||||
// DEBUG OPTIONS:
|
||||
|
||||
// Uncomment to enable printing of backtraces on exceptions:
|
||||
//objj_msgSend_decorate(objj_backtrace_decorator);
|
||||
|
||||
// Uncomment to enable runtime type checking:
|
||||
//objj_msgSend_decorate(objj_typecheck_decorator);
|
||||
|
||||
// Uncomment (along with both above) to print backtraces on type check errors:
|
||||
//objj_typecheck_prints_backtrace = true;
|
||||
|
||||
// Uncomment to disable the default logger (CPLogConsole if window.console exists, CPLogPopup otherwise):
|
||||
//CPLogUnregister(CPLogDefault);
|
||||
|
||||
// Uncomment to enable a specific logger:
|
||||
CPLogRegister(CPLogConsole);
|
||||
//CPLogRegister(CPLogPopup);
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
body{margin:0; padding:0;}
|
||||
#container {position: absolute; top:50%; left:50%;}
|
||||
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
|
||||
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
|
||||
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
|
||||
</style>
|
||||
|
||||
<!--[if lt IE 7]>
|
||||
<STYLE type="text/css">
|
||||
#container { position: relative; top: 50%; }
|
||||
#content { position: relative;}
|
||||
</STYLE>
|
||||
<![endif]-->
|
||||
|
||||
</head>
|
||||
|
||||
<body style="">
|
||||
<div id="cappuccino-body">
|
||||
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
|
||||
<script type="text/javascript">
|
||||
document.write("<div id='container'><p id='content'>" +
|
||||
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
|
||||
"Loading TestApp...</p></div>");
|
||||
</script>
|
||||
|
||||
<noscript>
|
||||
<div id="container">
|
||||
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
|
||||
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
|
||||
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino.org/noscript">Show me how to enable JavaScript</a></p>
|
||||
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
|
||||
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
|
||||
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
|
||||
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
|
||||
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
|
||||
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
|
||||
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,79 @@
|
||||
<!DOCTYPE html
|
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<!--
|
||||
index.html
|
||||
TestApp
|
||||
|
||||
Created by You on May 11, 2010.
|
||||
Copyright 2010, Your Company All rights reserved.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
|
||||
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||
|
||||
<link rel="apple-touch-icon" href="Resources/icon.png" />
|
||||
<link rel="apple-touch-startup-image" href="Resources/default.png" />
|
||||
|
||||
<title>TestApp</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
OBJJ_MAIN_FILE = "main.j";
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="Frameworks/Objective-J/Objective-J.js" charset="UTF-8"></script>
|
||||
|
||||
<style type="text/css">
|
||||
body{margin:0; padding:0;}
|
||||
#container {position: absolute; top:50%; left:50%;}
|
||||
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
|
||||
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
|
||||
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
|
||||
</style>
|
||||
|
||||
<!--[if lt IE 7]>
|
||||
<STYLE type="text/css">
|
||||
#container { position: relative; top: 50%; }
|
||||
#content { position: relative;}
|
||||
</STYLE>
|
||||
<![endif]-->
|
||||
|
||||
</head>
|
||||
|
||||
<body style="">
|
||||
<div id="cappuccino-body">
|
||||
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
|
||||
<script type="text/javascript">
|
||||
document.write("<div id='container'><p id='content'>" +
|
||||
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
|
||||
"Loading TestApp...</p></div>");
|
||||
</script>
|
||||
|
||||
<noscript>
|
||||
<div id="container">
|
||||
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
|
||||
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
|
||||
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino.org/noscript">Show me how to enable JavaScript</a></p>
|
||||
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
|
||||
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
|
||||
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
|
||||
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
|
||||
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
|
||||
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
|
||||
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
exports.stdio = {
|
||||
print : function() {
|
||||
throw "shouldn't be using system.stdio.print"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* AppController.j
|
||||
* TestApp
|
||||
*
|
||||
* Created by You on May 11, 2010.
|
||||
* Copyright 2010, Your Company All rights reserved.
|
||||
*/
|
||||
|
||||
// @import <Foundation/Foundation.j>
|
||||
|
||||
var url = window.location.toString();
|
||||
var dir = url.substring(0, url.lastIndexOf("/"));
|
||||
|
||||
var testNames = [
|
||||
"absolute",
|
||||
"cyclic",
|
||||
"determinism", // failing
|
||||
"exactExports",
|
||||
"hasOwnProperty", // failing
|
||||
"method",
|
||||
"missing", // failing
|
||||
"monkeys",
|
||||
"nested",
|
||||
"relative",
|
||||
"transitive"
|
||||
];
|
||||
|
||||
// ObjectiveJ.asyncLoader = false;
|
||||
|
||||
print = function() {
|
||||
test.logs.push(Array.prototype.join.apply(arguments, [","]));
|
||||
console.warn.apply(console, arguments);
|
||||
}
|
||||
|
||||
var tests = [];
|
||||
var test = { pass : true, logs : [] };
|
||||
var pause = false;
|
||||
|
||||
function main(args, namedArgs)
|
||||
{
|
||||
var hash = window.location.hash.substring(1);
|
||||
if (hash) {
|
||||
tests = JSON.parse(decodeURIComponent(hash))
|
||||
}
|
||||
|
||||
var index = tests.length;
|
||||
|
||||
test.name = testNames[index];
|
||||
|
||||
function next() {
|
||||
window.clearNativeTimeout(timeout);
|
||||
|
||||
tests.push(test);
|
||||
if (index < testNames.length - 1) {
|
||||
window.location.hash = "#" + encodeURIComponent(JSON.stringify(tests));
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert(tests.map(function(test) {
|
||||
return test.logs.map(function(log) {
|
||||
return test.name + ": " + log;
|
||||
}).join("\n") + "\n" +
|
||||
"== " + (test.pass ? "PASS" : "FAIL") + " ==\n";
|
||||
}).join("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
var timeout = window.setNativeTimeout(function() {
|
||||
test.pass = false;
|
||||
if (pause) alert(test.name + ": timed out")
|
||||
next();
|
||||
}, 1000);
|
||||
|
||||
try {
|
||||
console.log("running: " + test.name);
|
||||
|
||||
var testDir = dir + "/tests/" + test.name;
|
||||
require.paths.unshift(dir + "/lib", testDir);
|
||||
require.async(testDir + "/program", function() {
|
||||
if (pause) alert(test.name + ": completed");
|
||||
next();
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
test.pass = false;
|
||||
print(test.name+ ": exception=" + e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
exports.foo = function() {};
|
||||
@@ -0,0 +1,5 @@
|
||||
var test = require('test');
|
||||
var a = require('submodule/a');
|
||||
var b = require('b');
|
||||
test.assert(a.foo().foo === b.foo, 'require works with absolute identifiers');
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,3 @@
|
||||
exports.foo = function () {
|
||||
return require('b');
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
exports.a = function () {
|
||||
return b;
|
||||
};
|
||||
var b = require('b');
|
||||
@@ -0,0 +1,4 @@
|
||||
var a = require('a');
|
||||
exports.b = function () {
|
||||
return a;
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
var test = require('test');
|
||||
var a = require('a');
|
||||
var b = require('b');
|
||||
|
||||
test.assert(a.a, 'a exists');
|
||||
test.assert(b.b, 'b exists')
|
||||
test.assert(a.a().b === b.b, 'a gets b');
|
||||
test.assert(b.b().a === a.a, 'b gets a');
|
||||
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
var test = require('test');
|
||||
require('submodule/a');
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,9 @@
|
||||
var test = require('test');
|
||||
var pass = false;
|
||||
var test = require('test');
|
||||
try {
|
||||
require('a');
|
||||
} catch (exception) {
|
||||
pass = true;
|
||||
}
|
||||
test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.')
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
exports.program = function () {
|
||||
return require('program');
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
var test = require('test');
|
||||
var a = require('a');
|
||||
test.assert(a.program() === exports, 'exact exports');
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
var hasOwnProperty = require('hasOwnProperty');
|
||||
var toString = require('toString');
|
||||
var test = require('test');
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
exports.foo = function () {
|
||||
return this;
|
||||
};
|
||||
exports.set = function (x) {
|
||||
this.x = x;
|
||||
};
|
||||
exports.get = function () {
|
||||
return this.x;
|
||||
};
|
||||
exports.getClosed = function () {
|
||||
return exports.x;
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
var test = require('test');
|
||||
var a = require('a');
|
||||
var foo = a.foo;
|
||||
test.assert(a.foo() == a, 'calling a module member');
|
||||
test.assert(foo() == (function (){return this})(), 'members not implicitly bound');
|
||||
a.set(10);
|
||||
test.assert(a.get() == 10, 'get and set')
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
var test = require('test');
|
||||
try {
|
||||
require('bogus');
|
||||
test.print('FAIL require throws error when module missing', 'fail');
|
||||
} catch (exception) {
|
||||
test.print('PASS require throws error when module missing', 'pass');
|
||||
}
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
require('program').monkey = 10;
|
||||
@@ -0,0 +1,4 @@
|
||||
var a = require('a');
|
||||
var test = require('test');
|
||||
test.assert(exports.monkey == 10, 'monkeys permitted');
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
exports.foo = function () {
|
||||
return 1;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
var test = require('test');
|
||||
test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier');
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
var test = require('test');
|
||||
var a = require('submodule/a');
|
||||
var b = require('submodule/b');
|
||||
test.assert(a.foo == b.foo, 'a and b share foo through a relative require');
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1 @@
|
||||
exports.foo = require('./b').foo;
|
||||
@@ -0,0 +1,2 @@
|
||||
exports.foo = function () {
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
exports.foo = require('b').foo;
|
||||
@@ -0,0 +1 @@
|
||||
exports.foo = require('c').foo;
|
||||
@@ -0,0 +1,3 @@
|
||||
exports.foo = function () {
|
||||
return 1;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
var test = require('test');
|
||||
test.assert(require('a').foo() == 1, 'transitive');
|
||||
test.print('DONE', 'info');
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
exports.print = typeof print !== "undefined" ? print : function () {
|
||||
var system = require("system");
|
||||
var stdio = system.stdio;
|
||||
stdio.print.apply(stdio, arguments);
|
||||
};
|
||||
|
||||
exports.assert = function (guard, message) {
|
||||
if (guard) {
|
||||
exports.print('PASS ' + message, 'pass');
|
||||
} else {
|
||||
exports.print('FAIL ' + message, 'fail');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user