├── LICENSE ├── README ├── jars └── js.jar ├── lib ├── yabble.js └── yabbler.js ├── package.json └── test ├── asyncA ├── index.html ├── tests │ ├── absolute │ │ ├── b.js │ │ ├── program.js │ │ ├── submodule │ │ │ └── a.js │ │ └── test.js │ ├── cyclic │ │ ├── a.js │ │ ├── b.js │ │ ├── program.js │ │ └── test.js │ └── relative │ │ ├── program.js │ │ ├── submodule │ │ ├── a.js │ │ └── b.js │ │ └── test.js ├── wrappedIndex.html ├── wrappedTests │ ├── absolute │ │ ├── b.js │ │ ├── program.js │ │ ├── submodule │ │ │ └── a.js │ │ └── test.js │ ├── cyclic │ │ ├── a.js │ │ ├── b.js │ │ ├── program.js │ │ └── test.js │ └── relative │ │ ├── program.js │ │ ├── submodule │ │ ├── a.js │ │ └── b.js │ │ └── test.js └── yabbler.bat ├── determineShallowDependencies ├── index.html └── modules │ ├── ensuredouble.js │ ├── ensuresimple.js │ ├── ensurestrings.js │ ├── ensureterms.js │ ├── knownfailure.js │ ├── simple.js │ ├── string.js │ └── terms.js ├── index.html ├── modules1.0 ├── index.html ├── tests │ ├── absolute │ │ ├── b.js │ │ ├── program.js │ │ ├── submodule │ │ │ └── a.js │ │ └── test.js │ ├── cyclic │ │ ├── a.js │ │ ├── b.js │ │ ├── program.js │ │ └── test.js │ ├── determinism │ │ ├── program.js │ │ ├── submodule │ │ │ ├── a.js │ │ │ └── b.js │ │ └── test.js │ ├── exactExports │ │ ├── a.js │ │ ├── program.js │ │ └── test.js │ ├── hasOwnProperty │ ├── method │ │ ├── a.js │ │ ├── program.js │ │ └── test.js │ ├── missing │ │ ├── program.js │ │ └── test.js │ ├── monkeys │ │ ├── a.js │ │ ├── program.js │ │ └── test.js │ ├── nested │ │ ├── a │ │ │ └── b │ │ │ │ └── c │ │ │ │ └── d.js │ │ ├── program.js │ │ └── test.js │ ├── relative │ │ ├── program.js │ │ ├── submodule │ │ │ ├── a.js │ │ │ └── b.js │ │ └── test.js │ └── transitive │ │ ├── a.js │ │ ├── b.js │ │ ├── c.js │ │ ├── program.js │ │ └── test.js ├── wrappedIndex.html ├── wrappedTests │ ├── absolute │ │ ├── b.js │ │ ├── program.js │ │ ├── submodule │ │ │ └── a.js │ │ └── test.js │ ├── cyclic │ │ ├── a.js │ │ ├── b.js │ │ ├── program.js │ │ └── test.js │ ├── determinism │ │ ├── program.js │ │ ├── submodule │ │ │ ├── a.js │ │ │ └── b.js │ │ └── test.js │ ├── exactExports │ │ ├── a.js │ │ ├── program.js │ │ └── test.js │ ├── hasOwnProperty │ ├── method │ │ ├── a.js │ │ ├── program.js │ │ └── test.js │ ├── missing │ │ ├── program.js │ │ └── test.js │ ├── monkeys │ │ ├── a.js │ │ ├── program.js │ │ └── test.js │ ├── nested │ │ ├── a │ │ │ └── b │ │ │ │ └── c │ │ │ │ └── d.js │ │ ├── program.js │ │ └── test.js │ ├── relative │ │ ├── program.js │ │ ├── submodule │ │ │ ├── a.js │ │ │ └── b.js │ │ └── test.js │ └── transitive │ │ ├── a.js │ │ ├── b.js │ │ ├── c.js │ │ ├── program.js │ │ └── test.js └── yabbler.bat ├── modules1.1.1 ├── index.html ├── tests │ ├── main │ │ ├── a.js │ │ ├── b.js │ │ ├── program.js │ │ └── test.js │ └── module │ │ ├── a.js │ │ ├── program.js │ │ ├── submodule │ │ └── b.js │ │ └── test.js ├── wrappedIndex.html ├── wrappedTests │ ├── main │ │ ├── a.js │ │ ├── b.js │ │ ├── program.js │ │ └── test.js │ └── module │ │ ├── a.js │ │ ├── program.js │ │ ├── submodule │ │ └── b.js │ │ └── test.js └── yabbler.bat ├── print.js ├── qunit.css ├── qunit.js ├── resolveModuleId └── index.html ├── transportC ├── index.html └── tests │ ├── injects │ ├── program.js │ └── test.js │ ├── multipleDefines │ ├── program.js │ └── test.js │ └── simple │ ├── program.js │ └── test.js └── transportD ├── index.html └── tests ├── injects ├── program.js └── test.js ├── mixedDescriptors ├── program.js └── test.js ├── multipleDefines ├── program.js └── test.js ├── multipleModules ├── program.js └── test.js └── simple ├── program.js └── test.js /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 James Brantly 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | A general purpose browser-side CommonJS module loader 2 | 3 | Yabble is a general purpose browser-side CommonJS module loader. Other similar module loaders are available, but Yabble strives to be a flexible loader in a small package. 4 | 5 | To see live unit tests, visit: 6 | http://jbrantly.github.com/yabble/test/index.html 7 | 8 | To see an overview of the goals, visit: 9 | http://blog.jbrantly.com/2010/04/introducing-yabble.html 10 | 11 | Features: 12 | * Compliant with Modules 1.1.1 13 | * Supports async XHR/eval() 14 | - Allows the use of non-transport-wrapped module code for quick development 15 | * Supports script tags with a Transport format 16 | - Easier debugging, potential for file concatenation 17 | - Supports Transport/D and Transport/C 18 | * Supports require.ensure() for lazy-loading modules 19 | * Passes unit tests on YUI's A-grade browsers 20 | * Includes a tool for automatically wrapping modules in a Transport format 21 | * Small size (<600 lines, ~15kb raw, ~5kb minified, and ~2kb when minified/gzipped) 22 | 23 | Roadmap: 24 | * Stability 25 | - Even more cross-browser testing 26 | - More unit tests for Async/A 27 | * Features 28 | - Async/A error handling once its decided (maybe before) 29 | - Tested support for loading from another domain (it may work now..) 30 | * Documentation 31 | * Tooling 32 | - Currently under-developed. Not recommended to use. 33 | - Use loader code in tooling (no copy/paste code) 34 | - Explicit support for concatenated Transport files tooling (loader should already support) 35 | - Expand supported engines for tooling (node.js) 36 | - Better consideration for platform (line endings, encoding, etc) 37 | 38 | Usage: 39 | 40 | require.setModuleRoot(path) 41 | 42 | Use this to configure the root path to find modules. Think of this as a 43 | single entry in require.paths. 44 | 45 | require.useScriptTags() 46 | 47 | The default behavior is to use XHR+eval() and expects unwrapped modules. Call this method 48 | to configure Yabble to use script tags and expect wrapped modules. 49 | 50 | require.run(programId) 51 | 52 | This kicks off an application using the specified module ID. 53 | 54 | require.ensure(dependencies, callback) 55 | 56 | See Async/A for more details. Can be used to retrieve modules and run code without using 57 | require.run(). 58 | 59 | See unit tests for example usage. 60 | 61 | Changelog: 62 | 63 | v0.3.0 (2010-04-18) 64 | - Restructured to use Packages/1.0 65 | 66 | v0.2.0 (2010-04-14) 67 | - Now using QUnit for unit tests 68 | - Added support for Modules 1.1.1 plus unit tests 69 | - Finished support for Transport/D plus unit tests 70 | - Added support for Transport/C plus unit tests 71 | - Added unit tests for Async/A and fixed bugs 72 | - Added unit tests for resolveModuleId and determineShallowDependencies 73 | 74 | v0.1.0 (2010-04-12) 75 | - Initial commit 76 | 77 | -------------------------------------------------------------------------------- /jars/js.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbrantly/yabble/cca641e7d9b6dd46f0711aec5bae1d09b78b43d5/jars/js.jar -------------------------------------------------------------------------------- /lib/yabble.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 James Brantly 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | (function(globalEval) { 27 | 28 | var Yabble = function() { 29 | throw "Synchronous require() is not supported."; 30 | }; 31 | 32 | Yabble.unit = {}; 33 | 34 | var _moduleRoot = '', 35 | _modules, 36 | _callbacks, 37 | _fetchFunc, 38 | _timeoutLength = 20000, 39 | _mainProgram; 40 | 41 | 42 | var head = document.getElementsByTagName('head')[0]; 43 | 44 | // Shortcut to native hasOwnProperty 45 | var hasOwnProperty = Object.prototype.hasOwnProperty; 46 | 47 | // A for..in implementation which uses hasOwnProperty and fixes IE non-enumerable issues 48 | if ((function() {for (var prop in {hasOwnProperty: true}) { return prop; }})() == 'hasOwnProperty') { 49 | var forIn = function(obj, func, ctx) { 50 | for (var prop in obj) { 51 | if (hasOwnProperty.call(obj, prop)) { 52 | func.call(ctx, prop); 53 | } 54 | } 55 | }; 56 | } 57 | else { 58 | var ieBadProps = [ 59 | 'isPrototypeOf', 60 | 'hasOwnProperty', 61 | 'toLocaleString', 62 | 'toString', 63 | 'valueOf' 64 | ]; 65 | 66 | var forIn = function(obj, func, ctx) { 67 | for (var prop in obj) { 68 | if (hasOwnProperty.call(obj, prop)) { 69 | func.call(ctx, prop); 70 | } 71 | } 72 | 73 | for (var i = ieBadProps.length; i--;) { 74 | var prop = ieBadProps[i]; 75 | if (hasOwnProperty.call(obj, prop)) { 76 | func.call(ctx, prop); 77 | } 78 | } 79 | }; 80 | } 81 | 82 | // Array convenience functions 83 | var indexOf = function(arr, val) { 84 | for (var i = arr.length; i--;) { 85 | if (arr[i] == val) { return i; } 86 | } 87 | return -1; 88 | }; 89 | 90 | var removeWhere = function(arr, func) { 91 | var i = 0; 92 | while (i < arr.length) { 93 | if (func.call(null, arr[i], i) === true) { 94 | arr.splice(i, 1); 95 | } 96 | else { 97 | i++; 98 | } 99 | } 100 | }; 101 | 102 | var combinePaths = function(relPath, refPath) { 103 | var relPathParts = relPath.split('/'); 104 | refPath = refPath || ''; 105 | if (refPath.length && refPath.charAt(refPath.length-1) != '/') { 106 | refPath += '/'; 107 | } 108 | var refPathParts = refPath.split('/'); 109 | refPathParts.pop(); 110 | var part; 111 | while (part = relPathParts.shift()) { 112 | if (part == '.') { continue; } 113 | else if (part == '..' 114 | && refPathParts.length 115 | && refPathParts[refPathParts.length-1] != '..') { refPathParts.pop(); } 116 | else { refPathParts.push(part); } 117 | } 118 | return refPathParts.join('/'); 119 | }; 120 | 121 | // Takes a relative path to a module and resolves it according to the reference path 122 | var resolveModuleId = Yabble.unit.resolveModuleId = function(relModuleId, refPath) { 123 | if (relModuleId.charAt(0) != '.') { 124 | return relModuleId; 125 | } 126 | else { 127 | return combinePaths(relModuleId, refPath); 128 | } 129 | }; 130 | 131 | // Takes a module's ID and resolves a URI according to the module root path 132 | var resolveModuleUri = function(moduleId) { 133 | if (moduleId.charAt(0) != '.') { 134 | return _moduleRoot+moduleId+'.js'; 135 | } 136 | else { 137 | return this._resolveModuleId(moduleId, _moduleRoot)+'.js'; 138 | } 139 | }; 140 | 141 | // Returns a module object from the module ID 142 | var getModule = function(moduleId) { 143 | if (!hasOwnProperty.call(_modules, moduleId)) { 144 | return null; 145 | } 146 | return _modules[moduleId]; 147 | }; 148 | 149 | // Adds a callback which is executed when all deep dependencies are loaded 150 | var addCallback = function(deps, cb) { 151 | _callbacks.push([deps.slice(0), cb]); 152 | }; 153 | 154 | // Generic implementation of require.ensure() which takes a reference path to 155 | // use when resolving relative module IDs 156 | var ensureImpl = function(deps, cb, refPath) { 157 | var unreadyModules = []; 158 | 159 | for (var i = deps.length; i--;) { 160 | var moduleId = resolveModuleId(deps[i], refPath), 161 | module = getModule(moduleId); 162 | 163 | if (!areDeepDepsDefined(moduleId)) { 164 | unreadyModules.push(moduleId); 165 | } 166 | } 167 | 168 | if (unreadyModules.length) { 169 | addCallback(unreadyModules, function() { 170 | cb(createRequireFunc(refPath)); 171 | }); 172 | queueModules(unreadyModules); 173 | } 174 | else { 175 | setTimeout(function() { 176 | cb(createRequireFunc(refPath)); 177 | }, 0); 178 | } 179 | }; 180 | 181 | // Creates a require function that is passed into module factory functions 182 | // and require.ensure() callbacks. It is bound to a reference path for 183 | // relative require()s 184 | var createRequireFunc = function(refPath) { 185 | var require = function(relModuleId) { 186 | var moduleId = resolveModuleId(relModuleId, refPath), 187 | module = getModule(moduleId); 188 | 189 | if (!module) { 190 | throw "Module not loaded"; 191 | } 192 | else if (module.error) { 193 | throw "Error loading module"; 194 | } 195 | 196 | if (!module.exports) { 197 | module.exports = {}; 198 | var moduleDir = moduleId.substring(0, moduleId.lastIndexOf('/')+1), 199 | injects = module.injects, 200 | args = []; 201 | 202 | for (var i = 0, n = injects.length; i= 0; 442 | }); 443 | 444 | transport.modules.push({ 445 | id: arguments[0], 446 | factory: arguments[2], 447 | injects: arguments[1] 448 | }); 449 | } 450 | return transport; 451 | }; 452 | 453 | // Set the uri which forms the conceptual module namespace root 454 | Yabble.setModuleRoot = function(path) { 455 | if (!(/^http(s?):\/\//.test(path))) { 456 | var href = window.location.href; 457 | href = href.substr(0, href.lastIndexOf('/')+1); 458 | path = combinePaths(path, href); 459 | } 460 | 461 | if (path.length && path.charAt(path.length-1) != '/') { 462 | path += '/'; 463 | } 464 | 465 | _moduleRoot = path; 466 | }; 467 | 468 | // Set a timeout period for async module loading 469 | Yabble.setTimeoutLength = function(milliseconds) { 470 | _timeoutLength = milliseconds; 471 | }; 472 | 473 | // Use script tags with wrapped code instead of XHR+eval() 474 | Yabble.useScriptTags = function() { 475 | _fetchFunc = loadModuleByScript; 476 | }; 477 | 478 | // Define a module per various transport specifications 479 | Yabble.def = Yabble.define = function() { 480 | var transport = normalizeTransport.apply(null, arguments); 481 | 482 | var unreadyModules = [], 483 | definedModules = []; 484 | 485 | var deps = transport.deps; 486 | 487 | for (var i = transport.modules.length; i--;) { 488 | var moduleDef = transport.modules[i], 489 | moduleId = moduleDef.id, 490 | module = getModule(moduleId); 491 | 492 | if (!module) { 493 | module = _modules[moduleId] = {}; 494 | } 495 | module.module = { 496 | id: moduleId, 497 | uri: resolveModuleUri(moduleId) 498 | }; 499 | 500 | module.defined = true; 501 | module.deps = deps.slice(0); 502 | module.injects = moduleDef.injects; 503 | module.factory = moduleDef.factory; 504 | definedModules.push(module); 505 | } 506 | 507 | for (var i = deps.length; i--;) { 508 | var moduleId = deps[i], 509 | module = getModule(moduleId); 510 | 511 | if (!module || !areDeepDepsDefined(moduleId)) { 512 | unreadyModules.push(moduleId); 513 | } 514 | } 515 | 516 | if (unreadyModules.length) { 517 | setTimeout(function() { 518 | queueModules(unreadyModules); 519 | }, 0); 520 | } 521 | 522 | fireCallbacks(); 523 | }; 524 | 525 | Yabble.isKnown = function(moduleId) { 526 | return getModule(moduleId) != null; 527 | }; 528 | 529 | Yabble.isDefined = function(moduleId) { 530 | var module = getModule(moduleId); 531 | return !!(module && module.defined); 532 | }; 533 | 534 | // Do an async lazy-load of modules 535 | Yabble.ensure = function(deps, cb) { 536 | ensureImpl(deps, cb, ''); 537 | }; 538 | 539 | // Start an application via a main program module 540 | Yabble.run = function(program, cb) { 541 | program = _mainProgram = resolveModuleId(program, ''); 542 | Yabble.ensure([program], function(require) { 543 | require(program); 544 | if (cb != null) { cb(); } 545 | }); 546 | }; 547 | 548 | // Reset internal state. Used mostly for unit tests. 549 | Yabble.reset = function() { 550 | _mainProgram = null; 551 | _modules = {}; 552 | _callbacks = []; 553 | 554 | // Built-in system module 555 | Yabble.define({ 556 | 'system': function(require, exports, module) {} 557 | }); 558 | }; 559 | 560 | Yabble.reset(); 561 | 562 | // Export to the require global 563 | window.require = Yabble; 564 | })(function(code) { 565 | return (window.eval || eval)(code, null); 566 | }); -------------------------------------------------------------------------------- /lib/yabbler.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 James Brantly 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | function createWrappedFile(inFileObj, outFileObj, referencePath) { 27 | var moduleName = new String(inFileObj.getName()); 28 | moduleName = moduleName.substring(0, moduleName.length-3); 29 | 30 | var moduleId = resolveModuleId('./'+moduleName, referencePath) 31 | var moduleCode = readFile(inFileObj); 32 | var deps = determineShallowDependencies(moduleCode); 33 | deps = deps.map(function(dep) { 34 | return '"' + resolveModuleId(dep, referencePath) +'"'; 35 | }); 36 | 37 | var newModuleCode = '/* This file has been generated by yabbler.js */'; 38 | newModuleCode += '\r\nrequire.define({'; 39 | newModuleCode += '\r\n"' + moduleId + '": function(require, exports, module) {'; 40 | newModuleCode += '\r\n'+moduleCode; 41 | newModuleCode += '\r\n}}, [' + deps.join(', ') + ']);'; 42 | 43 | writeFile(outFileObj, newModuleCode); 44 | }; 45 | 46 | function determineShallowDependencies(moduleCode) { 47 | // need to account for comments 48 | var deps = {}, match, unique = {}; 49 | 50 | var requireRegex = /(?:^|[^\w\$_.])require\s*\(\s*("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*')\s*\)/g; 51 | while (match = requireRegex.exec(moduleCode)) { 52 | var module = eval(match[1]); 53 | if (!Object.prototype.hasOwnProperty.call(deps, module)) { 54 | deps[module] = true; 55 | } 56 | } 57 | 58 | var ensureRegex = /(?:^|[^\w\$_.])require.ensure\s*\(\s*(\[("[^"\\]*(?:\\.[^"\\]*)*"|'[^'\\]*(?:\\.[^'\\]*)*'|\s*|,)*\])/g; 59 | while (match = ensureRegex.exec(moduleCode)) { 60 | var moduleArray = eval(match[1]); 61 | for (var i = moduleArray.length; i--;) { 62 | var module = moduleArray[i]; 63 | delete deps[module]; 64 | } 65 | } 66 | 67 | var depsArray = []; 68 | for (var module in deps) { 69 | if (Object.prototype.hasOwnProperty.call(deps, module)) { 70 | depsArray.push(module); 71 | } 72 | } 73 | 74 | return depsArray; 75 | }; 76 | 77 | function resolveModuleId(path, referencePath) { 78 | if (path[0] != '.') { 79 | return path; 80 | } 81 | else { 82 | var pathParts = path.split('/'); 83 | referencePath = referencePath || ''; 84 | if (referencePath.length && referencePath[referencePath.length-1] != '/') { 85 | referencePath += '/'; 86 | } 87 | var referencePathParts = referencePath.split('/'); 88 | referencePathParts.pop(); 89 | var part; 90 | while (part = pathParts.shift()) { 91 | if (part == '.') { continue; } 92 | else if (part == '..' 93 | && referencePathParts.length 94 | && referencePathParts[referencePathParts.length-1] != '..') { referencePathParts.pop(); } 95 | else { referencePathParts.push(part); } 96 | } 97 | return referencePathParts.join('/'); 98 | } 99 | }; 100 | 101 | function readFile(fileObj) { 102 | var encoding = 'UTF-8'; 103 | var result = null; 104 | try { 105 | var inStream = new java.io.InputStreamReader(new java.io.FileInputStream(fileObj), encoding); 106 | var writer = new java.io.StringWriter(); 107 | 108 | var n, 109 | buffer = java.lang.reflect.Array.newInstance(java.lang.Character.TYPE, 4096); 110 | 111 | while ((n = inStream.read(buffer, 0, buffer.length)) != -1) { 112 | writer.write(buffer, 0, n); 113 | } 114 | 115 | result = new String(writer.toString()); 116 | } 117 | finally { 118 | if (inStream) { 119 | inStream.close(); 120 | } 121 | } 122 | 123 | return result; 124 | }; 125 | 126 | function writeFile(fileObj, contents) { 127 | var encoding = 'UTF-8'; 128 | try { 129 | fileObj.getParentFile().mkdirs(); 130 | var outStream = new java.io.FileOutputStream(fileObj); 131 | outStream.write((new java.lang.String(contents)).getBytes(encoding)); 132 | } 133 | finally { 134 | if (outStream) { 135 | outStream.close(); 136 | } 137 | } 138 | }; 139 | 140 | function processDirectory(inFileObj, outFileObj, referencePath) { 141 | var jsFilter = new java.io.FileFilter() { 142 | accept: function(fileObj) { 143 | return fileObj.isFile() && fileObj.getName().endsWith('.js'); 144 | } 145 | }; 146 | 147 | var jsFiles = inFileObj.listFiles(jsFilter); 148 | 149 | jsFiles.forEach(function(jsFile) { 150 | createWrappedFile(jsFile, new java.io.File(outFileObj, jsFile.getName()), referencePath); 151 | }); 152 | 153 | var dirFilter = new java.io.FileFilter() { 154 | accept: function(fileObj) { 155 | return fileObj.isDirectory(); 156 | } 157 | }; 158 | 159 | var subDirs = inFileObj.listFiles(dirFilter); 160 | 161 | subDirs.forEach(function(subDir) { 162 | processDirectory(subDir, new java.io.File(outFileObj, subDir.getName()), new String(referencePath+subDir.getName()+'/')); 163 | }); 164 | }; 165 | 166 | var inputDir = 'source'; 167 | var outputDir = 'build'; 168 | 169 | for (var i = 0, n = arguments.length; i 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 34 | 35 | 36 |

Yabble Async/A Unit Tests

37 |

38 |

39 |
    40 | 41 | -------------------------------------------------------------------------------- /test/asyncA/tests/absolute/b.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() {}; 2 | -------------------------------------------------------------------------------- /test/asyncA/tests/absolute/program.js: -------------------------------------------------------------------------------- 1 | require.ensure(['test', 'submodule/a', 'b'], function(require) { 2 | var test = require('test'); 3 | var a = require('submodule/a'); 4 | var b = require('b'); 5 | a.foo(function(bThruA) { 6 | test.assert(bThruA.foo === b.foo, 'require.ensure works with absolute identifiers'); 7 | test.print('DONE', 'info'); 8 | }); 9 | }); -------------------------------------------------------------------------------- /test/asyncA/tests/absolute/submodule/a.js: -------------------------------------------------------------------------------- 1 | exports.foo = function (cb) { 2 | require.ensure(['b'], function(require) { 3 | cb(require('b')); 4 | }); 5 | }; 6 | -------------------------------------------------------------------------------- /test/asyncA/tests/absolute/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/asyncA/tests/cyclic/a.js: -------------------------------------------------------------------------------- 1 | exports.a = function () { 2 | return b; 3 | }; 4 | var b = require('b'); 5 | -------------------------------------------------------------------------------- /test/asyncA/tests/cyclic/b.js: -------------------------------------------------------------------------------- 1 | var a = require('a'); 2 | exports.b = function () { 3 | return a; 4 | }; 5 | -------------------------------------------------------------------------------- /test/asyncA/tests/cyclic/program.js: -------------------------------------------------------------------------------- 1 | require.ensure(['test', 'a', 'b'], function(require) { 2 | var test = require('test'); 3 | var a = require('a'); 4 | var b = require('b'); 5 | 6 | test.assert(a.a, 'a exists'); 7 | test.assert(b.b, 'b exists') 8 | test.assert(a.a().b === b.b, 'a gets b'); 9 | test.assert(b.b().a === a.a, 'b gets a'); 10 | 11 | test.print('DONE', 'info'); 12 | }); -------------------------------------------------------------------------------- /test/asyncA/tests/cyclic/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/asyncA/tests/relative/program.js: -------------------------------------------------------------------------------- 1 | require.ensure(['test', 'submodule/a', 'submodule/b'], function(require) { 2 | var test = require('test'); 3 | var a = require('submodule/a'); 4 | var b = require('submodule/b'); 5 | 6 | a.foo(function(bfoo) { 7 | test.assert(bfoo == b.foo, 'a and b share foo through a relative require'); 8 | test.print('DONE', 'info'); 9 | }); 10 | }); -------------------------------------------------------------------------------- /test/asyncA/tests/relative/submodule/a.js: -------------------------------------------------------------------------------- 1 | exports.foo = function(cb) { 2 | require.ensure(['./b'], function(require) { 3 | cb(require('./b').foo); 4 | }); 5 | }; -------------------------------------------------------------------------------- /test/asyncA/tests/relative/submodule/b.js: -------------------------------------------------------------------------------- 1 | exports.foo = function () { 2 | }; 3 | -------------------------------------------------------------------------------- /test/asyncA/tests/relative/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/asyncA/wrappedIndex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 36 | 37 | 38 |

    Yabble Async/A Unit Tests (Wrapped Modules)

    39 |

    40 |

    41 |
      42 | 43 | -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/absolute/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "b": function(require, exports, module) { 4 | exports.foo = function() {}; 5 | 6 | }}, []); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/absolute/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | require.ensure(['test', 'submodule/a', 'b'], function(require) { 5 | var test = require('test'); 6 | var a = require('submodule/a'); 7 | var b = require('b'); 8 | a.foo(function(bThruA) { 9 | test.assert(bThruA.foo === b.foo, 'require.ensure works with absolute identifiers'); 10 | test.print('DONE', 'info'); 11 | }); 12 | }); 13 | }}, []); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/absolute/submodule/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/a": function(require, exports, module) { 4 | exports.foo = function (cb) { 5 | require.ensure(['b'], function(require) { 6 | cb(require('b')); 7 | }); 8 | }; 9 | 10 | }}, []); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/absolute/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/cyclic/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a": function(require, exports, module) { 4 | exports.a = function () { 5 | return b; 6 | }; 7 | var b = require('b'); 8 | 9 | }}, ["b"]); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/cyclic/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "b": function(require, exports, module) { 4 | var a = require('a'); 5 | exports.b = function () { 6 | return a; 7 | }; 8 | 9 | }}, ["a"]); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/cyclic/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | require.ensure(['test', 'a', 'b'], function(require) { 5 | var test = require('test'); 6 | var a = require('a'); 7 | var b = require('b'); 8 | 9 | test.assert(a.a, 'a exists'); 10 | test.assert(b.b, 'b exists') 11 | test.assert(a.a().b === b.b, 'a gets b'); 12 | test.assert(b.b().a === a.a, 'b gets a'); 13 | 14 | test.print('DONE', 'info'); 15 | }); 16 | }}, []); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/cyclic/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/relative/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | require.ensure(['test', 'submodule/a', 'submodule/b'], function(require) { 5 | var test = require('test'); 6 | var a = require('submodule/a'); 7 | var b = require('submodule/b'); 8 | 9 | a.foo(function(bfoo) { 10 | test.assert(bfoo == b.foo, 'a and b share foo through a relative require'); 11 | test.print('DONE', 'info'); 12 | }); 13 | }); 14 | }}, []); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/relative/submodule/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/a": function(require, exports, module) { 4 | exports.foo = function(cb) { 5 | require.ensure(['./b'], function(require) { 6 | cb(require('./b').foo); 7 | }); 8 | }; 9 | }}, []); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/relative/submodule/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/b": function(require, exports, module) { 4 | exports.foo = function () { 5 | }; 6 | 7 | }}, []); -------------------------------------------------------------------------------- /test/asyncA/wrappedTests/relative/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/asyncA/yabbler.bat: -------------------------------------------------------------------------------- 1 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/absolute" -o "wrappedTests/absolute" 2 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/cyclic" -o "wrappedTests/cyclic" 3 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/relative" -o "wrappedTests/relative" -------------------------------------------------------------------------------- /test/determineShallowDependencies/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 37 | 38 | 39 |

      Yabble determineShallowDependencies

      40 |

      41 |

      42 |
        43 | 44 | -------------------------------------------------------------------------------- /test/determineShallowDependencies/modules/ensuredouble.js: -------------------------------------------------------------------------------- 1 | require('moduleA'); 2 | require.ensure(['moduleB', 'moduleC'], function(require) { 3 | require('moduleB'); 4 | require('moduleC'); 5 | }); -------------------------------------------------------------------------------- /test/determineShallowDependencies/modules/ensuresimple.js: -------------------------------------------------------------------------------- 1 | require('moduleA'); 2 | require.ensure(['moduleB'], function(require) { 3 | require('moduleB'); 4 | require('moduleC'); 5 | }); -------------------------------------------------------------------------------- /test/determineShallowDependencies/modules/ensurestrings.js: -------------------------------------------------------------------------------- 1 | require('moduleA'); 2 | require.ensure(['[moduleB]', '[moduleC]'], function(require) { 3 | require('[moduleB]'); 4 | require('[moduleC]'); 5 | }); -------------------------------------------------------------------------------- /test/determineShallowDependencies/modules/ensureterms.js: -------------------------------------------------------------------------------- 1 | require('moduleA'); 2 | require.ensure( 3 | [ 4 | 'moduleB', 5 | 'moduleC' 6 | ], 7 | function(require) { 8 | require('moduleB'); 9 | require('moduleC'); 10 | } 11 | ); -------------------------------------------------------------------------------- /test/determineShallowDependencies/modules/knownfailure.js: -------------------------------------------------------------------------------- 1 | require('moduleA'); 2 | require.ensure(['moduleA'], function(require) { 3 | require('moduleA'); 4 | }); 5 | /* require('moduleB') */ 6 | // require('moduleB') -------------------------------------------------------------------------------- /test/determineShallowDependencies/modules/simple.js: -------------------------------------------------------------------------------- 1 | require("moduleA"); 2 | require('moduleB'); -------------------------------------------------------------------------------- /test/determineShallowDependencies/modules/string.js: -------------------------------------------------------------------------------- 1 | require("\"'moduleA"); 2 | require('"\'moduleB'); 3 | require("\"'moduleC\"'"); 4 | require('"\'moduleD"\''); -------------------------------------------------------------------------------- /test/determineShallowDependencies/modules/terms.js: -------------------------------------------------------------------------------- 1 | require('moduleA'); 2 | $require('bad'); 3 | _require('bad'); 4 | ;require('moduleB'); 5 | something.require('bad'); 6 | require ('moduleC'); 7 | require ('moduleD'); 8 | require 9 | ('moduleE'); 10 | require 11 | require( 'moduleF' ); 12 | require( 'moduleG' ); -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |

        Yabble Unit Tests

        12 |

        13 |

        14 |
          15 |
        1. Modules/1.0
        2. 16 |
        3. Modules/1.0 Wrapped
        4. 17 |
        5. Modules/1.1.1
        6. 18 |
        7. Modules/1.1.1 Wrapped
        8. 19 |
        9. Transport/C
        10. 20 |
        11. Transport/D
        12. 21 |
        13. Async/A
        14. 22 |
        15. Async/A Wrapped
        16. 23 |
        17. determineShallowDependencies()
        18. 24 |
        19. resolveModuleId()
        20. 25 |
        26 |

        27 |

        28 | 29 | -------------------------------------------------------------------------------- /test/modules1.0/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 42 | 43 | 44 |

        Yabble Modules/1.0 Unit Tests

        45 |

        46 |

        47 |
          48 | 49 | -------------------------------------------------------------------------------- /test/modules1.0/tests/absolute/b.js: -------------------------------------------------------------------------------- 1 | exports.foo = function() {}; 2 | -------------------------------------------------------------------------------- /test/modules1.0/tests/absolute/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var a = require('submodule/a'); 3 | var b = require('b'); 4 | test.assert(a.foo().foo === b.foo, 'require works with absolute identifiers'); 5 | test.print('DONE', 'info'); 6 | -------------------------------------------------------------------------------- /test/modules1.0/tests/absolute/submodule/a.js: -------------------------------------------------------------------------------- 1 | exports.foo = function () { 2 | return require('b'); 3 | }; 4 | -------------------------------------------------------------------------------- /test/modules1.0/tests/absolute/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/cyclic/a.js: -------------------------------------------------------------------------------- 1 | exports.a = function () { 2 | return b; 3 | }; 4 | var b = require('b'); 5 | -------------------------------------------------------------------------------- /test/modules1.0/tests/cyclic/b.js: -------------------------------------------------------------------------------- 1 | var a = require('a'); 2 | exports.b = function () { 3 | return a; 4 | }; 5 | -------------------------------------------------------------------------------- /test/modules1.0/tests/cyclic/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var a = require('a'); 3 | var b = require('b'); 4 | 5 | test.assert(a.a, 'a exists'); 6 | test.assert(b.b, 'b exists') 7 | test.assert(a.a().b === b.b, 'a gets b'); 8 | test.assert(b.b().a === a.a, 'b gets a'); 9 | 10 | test.print('DONE', 'info'); 11 | -------------------------------------------------------------------------------- /test/modules1.0/tests/cyclic/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/determinism/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | require('submodule/a'); 3 | test.print('DONE', 'info'); 4 | -------------------------------------------------------------------------------- /test/modules1.0/tests/determinism/submodule/a.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var pass = false; 3 | var test = require('test'); 4 | try { 5 | require('a'); 6 | } catch (exception) { 7 | pass = true; 8 | } 9 | test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.') 10 | -------------------------------------------------------------------------------- /test/modules1.0/tests/determinism/submodule/b.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /test/modules1.0/tests/determinism/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/exactExports/a.js: -------------------------------------------------------------------------------- 1 | exports.program = function () { 2 | return require('program'); 3 | }; 4 | -------------------------------------------------------------------------------- /test/modules1.0/tests/exactExports/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var a = require('a'); 3 | test.assert(a.program() === exports, 'exact exports'); 4 | test.print('DONE', 'info'); 5 | -------------------------------------------------------------------------------- /test/modules1.0/tests/exactExports/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/hasOwnProperty/hasOwnProperty.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbrantly/yabble/cca641e7d9b6dd46f0711aec5bae1d09b78b43d5/test/modules1.0/tests/hasOwnProperty/hasOwnProperty.js -------------------------------------------------------------------------------- /test/modules1.0/tests/hasOwnProperty/program.js: -------------------------------------------------------------------------------- 1 | var hasOwnProperty = require('hasOwnProperty'); 2 | var toString = require('toString'); 3 | var test = require('test'); 4 | test.print('DONE', 'info'); 5 | -------------------------------------------------------------------------------- /test/modules1.0/tests/hasOwnProperty/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/hasOwnProperty/toString.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbrantly/yabble/cca641e7d9b6dd46f0711aec5bae1d09b78b43d5/test/modules1.0/tests/hasOwnProperty/toString.js -------------------------------------------------------------------------------- /test/modules1.0/tests/method/a.js: -------------------------------------------------------------------------------- 1 | exports.foo = function () { 2 | return this; 3 | }; 4 | exports.set = function (x) { 5 | this.x = x; 6 | }; 7 | exports.get = function () { 8 | return this.x; 9 | }; 10 | exports.getClosed = function () { 11 | return exports.x; 12 | }; 13 | -------------------------------------------------------------------------------- /test/modules1.0/tests/method/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var a = require('a'); 3 | var foo = a.foo; 4 | test.assert(a.foo() == a, 'calling a module member'); 5 | test.assert(foo() == (function (){return this})(), 'members not implicitly bound'); 6 | a.set(10); 7 | test.assert(a.get() == 10, 'get and set') 8 | test.print('DONE', 'info'); 9 | -------------------------------------------------------------------------------- /test/modules1.0/tests/method/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/missing/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | try { 3 | require('bogus'); 4 | test.print('FAIL require throws error when module missing', 'fail'); 5 | } catch (exception) { 6 | test.print('PASS require throws error when module missing', 'pass'); 7 | } 8 | test.print('DONE', 'info'); 9 | -------------------------------------------------------------------------------- /test/modules1.0/tests/missing/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/monkeys/a.js: -------------------------------------------------------------------------------- 1 | require('program').monkey = 10; 2 | -------------------------------------------------------------------------------- /test/modules1.0/tests/monkeys/program.js: -------------------------------------------------------------------------------- 1 | var a = require('a'); 2 | var test = require('test'); 3 | test.assert(exports.monkey == 10, 'monkeys permitted'); 4 | test.print('DONE', 'info'); 5 | -------------------------------------------------------------------------------- /test/modules1.0/tests/monkeys/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/nested/a/b/c/d.js: -------------------------------------------------------------------------------- 1 | exports.foo = function () { 2 | return 1; 3 | }; 4 | -------------------------------------------------------------------------------- /test/modules1.0/tests/nested/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier'); 3 | test.print('DONE', 'info'); 4 | -------------------------------------------------------------------------------- /test/modules1.0/tests/nested/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/relative/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | var a = require('submodule/a'); 3 | var b = require('submodule/b'); 4 | test.assert(a.foo == b.foo, 'a and b share foo through a relative require'); 5 | test.print('DONE', 'info'); 6 | -------------------------------------------------------------------------------- /test/modules1.0/tests/relative/submodule/a.js: -------------------------------------------------------------------------------- 1 | exports.foo = require('./b').foo; 2 | -------------------------------------------------------------------------------- /test/modules1.0/tests/relative/submodule/b.js: -------------------------------------------------------------------------------- 1 | exports.foo = function () { 2 | }; 3 | -------------------------------------------------------------------------------- /test/modules1.0/tests/relative/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/tests/transitive/a.js: -------------------------------------------------------------------------------- 1 | exports.foo = require('b').foo; 2 | -------------------------------------------------------------------------------- /test/modules1.0/tests/transitive/b.js: -------------------------------------------------------------------------------- 1 | exports.foo = require('c').foo; 2 | -------------------------------------------------------------------------------- /test/modules1.0/tests/transitive/c.js: -------------------------------------------------------------------------------- 1 | exports.foo = function () { 2 | return 1; 3 | }; 4 | -------------------------------------------------------------------------------- /test/modules1.0/tests/transitive/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | test.assert(require('a').foo() == 1, 'transitive'); 3 | test.print('DONE', 'info'); 4 | -------------------------------------------------------------------------------- /test/modules1.0/tests/transitive/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.0/wrappedIndex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 44 | 45 | 46 |

          Yabble Modules/1.0 Unit Tests (Wrapped Modules)

          47 |

          48 |

          49 |
            50 | 51 | -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/absolute/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "b": function(require, exports, module) { 4 | exports.foo = function() {}; 5 | 6 | }}, []); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/absolute/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | var a = require('submodule/a'); 6 | var b = require('b'); 7 | test.assert(a.foo().foo === b.foo, 'require works with absolute identifiers'); 8 | test.print('DONE', 'info'); 9 | 10 | }}, ["test", "submodule/a", "b"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/absolute/submodule/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/a": function(require, exports, module) { 4 | exports.foo = function () { 5 | return require('b'); 6 | }; 7 | 8 | }}, ["b"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/absolute/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/cyclic/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a": function(require, exports, module) { 4 | exports.a = function () { 5 | return b; 6 | }; 7 | var b = require('b'); 8 | 9 | }}, ["b"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/cyclic/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "b": function(require, exports, module) { 4 | var a = require('a'); 5 | exports.b = function () { 6 | return a; 7 | }; 8 | 9 | }}, ["a"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/cyclic/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | var a = require('a'); 6 | var b = require('b'); 7 | 8 | test.assert(a.a, 'a exists'); 9 | test.assert(b.b, 'b exists') 10 | test.assert(a.a().b === b.b, 'a gets b'); 11 | test.assert(b.b().a === a.a, 'b gets a'); 12 | 13 | test.print('DONE', 'info'); 14 | 15 | }}, ["test", "a", "b"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/cyclic/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/determinism/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | require('submodule/a'); 6 | test.print('DONE', 'info'); 7 | 8 | }}, ["test", "submodule/a"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/determinism/submodule/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/a": function(require, exports, module) { 4 | var test = require('test'); 5 | var pass = false; 6 | var test = require('test'); 7 | try { 8 | require('a'); 9 | } catch (exception) { 10 | pass = true; 11 | } 12 | test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.') 13 | 14 | }}, ["test", "a"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/determinism/submodule/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/b": function(require, exports, module) { 4 | 5 | 6 | 7 | }}, []); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/determinism/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/exactExports/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a": function(require, exports, module) { 4 | exports.program = function () { 5 | return require('program'); 6 | }; 7 | 8 | }}, ["program"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/exactExports/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | var a = require('a'); 6 | test.assert(a.program() === exports, 'exact exports'); 7 | test.print('DONE', 'info'); 8 | 9 | }}, ["test", "a"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/exactExports/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/hasOwnProperty/hasOwnProperty.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "hasOwnProperty": function(require, exports, module) { 4 | 5 | }}, []); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/hasOwnProperty/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var hasOwnProperty = require('hasOwnProperty'); 5 | var toString = require('toString'); 6 | var test = require('test'); 7 | test.print('DONE', 'info'); 8 | 9 | }}, ["hasOwnProperty", "toString", "test"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/hasOwnProperty/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/hasOwnProperty/toString.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "toString": function(require, exports, module) { 4 | 5 | }}, []); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/method/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a": function(require, exports, module) { 4 | exports.foo = function () { 5 | return this; 6 | }; 7 | exports.set = function (x) { 8 | this.x = x; 9 | }; 10 | exports.get = function () { 11 | return this.x; 12 | }; 13 | exports.getClosed = function () { 14 | return exports.x; 15 | }; 16 | 17 | }}, []); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/method/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | var a = require('a'); 6 | var foo = a.foo; 7 | test.assert(a.foo() == a, 'calling a module member'); 8 | test.assert(foo() == (function (){return this})(), 'members not implicitly bound'); 9 | a.set(10); 10 | test.assert(a.get() == 10, 'get and set') 11 | test.print('DONE', 'info'); 12 | 13 | }}, ["test", "a"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/method/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/missing/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | try { 6 | require('bogus'); 7 | test.print('FAIL require throws error when module missing', 'fail'); 8 | } catch (exception) { 9 | test.print('PASS require throws error when module missing', 'pass'); 10 | } 11 | test.print('DONE', 'info'); 12 | 13 | }}, ["test", "bogus"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/missing/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/monkeys/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a": function(require, exports, module) { 4 | require('program').monkey = 10; 5 | 6 | }}, ["program"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/monkeys/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var a = require('a'); 5 | var test = require('test'); 6 | test.assert(exports.monkey == 10, 'monkeys permitted'); 7 | test.print('DONE', 'info'); 8 | 9 | }}, ["a", "test"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/monkeys/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/nested/a/b/c/d.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a/b/c/d": function(require, exports, module) { 4 | exports.foo = function () { 5 | return 1; 6 | }; 7 | 8 | }}, []); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/nested/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier'); 6 | test.print('DONE', 'info'); 7 | 8 | }}, ["test", "a/b/c/d"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/nested/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/relative/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | var a = require('submodule/a'); 6 | var b = require('submodule/b'); 7 | test.assert(a.foo == b.foo, 'a and b share foo through a relative require'); 8 | test.print('DONE', 'info'); 9 | 10 | }}, ["test", "submodule/a", "submodule/b"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/relative/submodule/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/a": function(require, exports, module) { 4 | exports.foo = require('./b').foo; 5 | 6 | }}, ["submodule/b"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/relative/submodule/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/b": function(require, exports, module) { 4 | exports.foo = function () { 5 | }; 6 | 7 | }}, []); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/relative/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/transitive/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a": function(require, exports, module) { 4 | exports.foo = require('b').foo; 5 | 6 | }}, ["b"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/transitive/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "b": function(require, exports, module) { 4 | exports.foo = require('c').foo; 5 | 6 | }}, ["c"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/transitive/c.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "c": function(require, exports, module) { 4 | exports.foo = function () { 5 | return 1; 6 | }; 7 | 8 | }}, []); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/transitive/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | test.assert(require('a').foo() == 1, 'transitive'); 6 | test.print('DONE', 'info'); 7 | 8 | }}, ["test", "a"]); -------------------------------------------------------------------------------- /test/modules1.0/wrappedTests/transitive/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.0/yabbler.bat: -------------------------------------------------------------------------------- 1 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/absolute" -o "wrappedTests/absolute" 2 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/cyclic" -o "wrappedTests/cyclic" 3 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/determinism" -o "wrappedTests/determinism" 4 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/exactExports" -o "wrappedTests/exactExports" 5 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/hasOwnProperty" -o "wrappedTests/hasOwnProperty" 6 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/method" -o "wrappedTests/method" 7 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/missing" -o "wrappedTests/missing" 8 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/monkeys" -o "wrappedTests/monkeys" 9 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/nested" -o "wrappedTests/nested" 10 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/relative" -o "wrappedTests/relative" 11 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/transitive" -o "wrappedTests/transitive" -------------------------------------------------------------------------------- /test/modules1.1.1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 33 | 34 | 35 |

            Yabble Modules/1.1.1 Unit Tests

            36 |

            37 |

            38 |
              39 | 40 | -------------------------------------------------------------------------------- /test/modules1.1.1/tests/main/a.js: -------------------------------------------------------------------------------- 1 | exports.main = function() { 2 | return require.main; 3 | }; -------------------------------------------------------------------------------- /test/modules1.1.1/tests/main/b.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbrantly/yabble/cca641e7d9b6dd46f0711aec5bae1d09b78b43d5/test/modules1.1.1/tests/main/b.js -------------------------------------------------------------------------------- /test/modules1.1.1/tests/main/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | 3 | test.assert(require.main != null && require.main === module, 'main module has require.main'); 4 | 5 | var aMain = require('a').main(); 6 | test.assert(aMain != null && aMain === module, 'submodule has require.main'); 7 | 8 | require.ensure(['b'], function(require) { 9 | test.assert(require.main != null && require.main === module, 'require.ensure has require.main'); 10 | test.print('DONE', 'info'); 11 | }); -------------------------------------------------------------------------------- /test/modules1.1.1/tests/main/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.1.1/tests/module/a.js: -------------------------------------------------------------------------------- 1 | exports.module = function() { 2 | return module; 3 | }; -------------------------------------------------------------------------------- /test/modules1.1.1/tests/module/program.js: -------------------------------------------------------------------------------- 1 | var test = require('test'); 2 | 3 | test.assert(module != null, 'program has module'); 4 | test.assert(module.id == 'program', 'module.id set to program'); 5 | test.assert(/^http(s?):\/\//.test(module.uri) && module.uri.substring(module.uri.length-10) == 'program.js', 'module.uri is absolute and ends with program.js'); 6 | 7 | var aModule = require('a').module(); 8 | var bModule = require('submodule/b').module(); 9 | 10 | test.assert(aModule != null, 'a has module'); 11 | test.assert(aModule.id == 'a', 'module.id set to a'); 12 | test.assert(/^http(s?):\/\//.test(aModule.uri) && aModule.uri.substring(aModule.uri.length-4) == 'a.js', 'module.uri is absolute and ends with a.js'); 13 | 14 | test.assert(bModule != null, 'submodule/b has module'); 15 | test.assert(bModule.id == 'submodule/b', 'module.id set to submodule/b'); 16 | test.assert(/^http(s?):\/\//.test(bModule.uri) && bModule.uri.substring(bModule.uri.length-14) == 'submodule/b.js', 'module.uri is absolute and ends with submodule/b.js'); 17 | test.print('DONE', 'info'); -------------------------------------------------------------------------------- /test/modules1.1.1/tests/module/submodule/b.js: -------------------------------------------------------------------------------- 1 | exports.module = function() { 2 | return module; 3 | }; -------------------------------------------------------------------------------- /test/modules1.1.1/tests/module/test.js: -------------------------------------------------------------------------------- 1 | 2 | exports.print = typeof print !== "undefined" ? print : function () { 3 | var system = require("system"); 4 | var stdio = system.stdio; 5 | stdio.print.apply(stdio, arguments); 6 | }; 7 | 8 | exports.assert = function (guard, message) { 9 | if (guard) { 10 | exports.print('PASS ' + message, 'pass'); 11 | } else { 12 | exports.print('FAIL ' + message, 'fail'); 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedIndex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 35 | 36 | 37 |

              Yabble Modules/1.1.1 Unit Tests (Wrapped Modules)

              38 |

              39 |

              40 |
                41 | 42 | -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedTests/main/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a": function(require, exports, module) { 4 | exports.main = function() { 5 | return require.main; 6 | }; 7 | }}, []); -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedTests/main/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "b": function(require, exports, module) { 4 | 5 | }}, []); -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedTests/main/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | 6 | test.assert(require.main != null && require.main === module, 'main module has require.main'); 7 | 8 | var aMain = require('a').main(); 9 | test.assert(aMain != null && aMain === module, 'submodule has require.main'); 10 | 11 | require.ensure(['b'], function(require) { 12 | test.assert(require.main != null && require.main === module, 'require.ensure has require.main'); 13 | test.print('DONE', 'info'); 14 | }); 15 | }}, ["test", "a"]); -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedTests/main/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedTests/module/a.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "a": function(require, exports, module) { 4 | exports.module = function() { 5 | return module; 6 | }; 7 | }}, []); -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedTests/module/program.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "program": function(require, exports, module) { 4 | var test = require('test'); 5 | 6 | test.assert(module != null, 'program has module'); 7 | test.assert(module.id == 'program', 'module.id set to program'); 8 | test.assert(/^http(s?):\/\//.test(module.uri) && module.uri.substring(module.uri.length-10) == 'program.js', 'module.uri is absolute and ends with program.js'); 9 | 10 | var aModule = require('a').module(); 11 | var bModule = require('submodule/b').module(); 12 | 13 | test.assert(aModule != null, 'a has module'); 14 | test.assert(aModule.id == 'a', 'module.id set to a'); 15 | test.assert(/^http(s?):\/\//.test(aModule.uri) && aModule.uri.substring(aModule.uri.length-4) == 'a.js', 'module.uri is absolute and ends with a.js'); 16 | 17 | test.assert(bModule != null, 'submodule/b has module'); 18 | test.assert(bModule.id == 'submodule/b', 'module.id set to submodule/b'); 19 | test.assert(/^http(s?):\/\//.test(bModule.uri) && bModule.uri.substring(bModule.uri.length-14) == 'submodule/b.js', 'module.uri is absolute and ends with submodule/b.js'); 20 | test.print('DONE', 'info'); 21 | }}, ["test", "a", "submodule/b"]); -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedTests/module/submodule/b.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "submodule/b": function(require, exports, module) { 4 | exports.module = function() { 5 | return module; 6 | }; 7 | }}, []); -------------------------------------------------------------------------------- /test/modules1.1.1/wrappedTests/module/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/modules1.1.1/yabbler.bat: -------------------------------------------------------------------------------- 1 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/main" -o "wrappedTests/main" 2 | java -jar ../../jars/js.jar ../../lib/yabbler.js -i "tests/module" -o "wrappedTests/module" -------------------------------------------------------------------------------- /test/print.js: -------------------------------------------------------------------------------- 1 | window.print = function(message, type) { 2 | if (type == 'info') { 3 | if (message == 'DONE') { 4 | start(); 5 | } 6 | } 7 | else { 8 | ok(type == 'pass', message); 9 | } 10 | } -------------------------------------------------------------------------------- /test/qunit.css: -------------------------------------------------------------------------------- 1 | 2 | ol#qunit-tests { 3 | font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial; 4 | margin:0; 5 | padding:0; 6 | list-style-position:inside; 7 | 8 | font-size: smaller; 9 | } 10 | ol#qunit-tests li{ 11 | padding:0.4em 0.5em 0.4em 2.5em; 12 | border-bottom:1px solid #fff; 13 | font-size:small; 14 | list-style-position:inside; 15 | } 16 | ol#qunit-tests li ol{ 17 | box-shadow: inset 0px 2px 13px #999; 18 | -moz-box-shadow: inset 0px 2px 13px #999; 19 | -webkit-box-shadow: inset 0px 2px 13px #999; 20 | margin-top:0.5em; 21 | margin-left:0; 22 | padding:0.5em; 23 | background-color:#fff; 24 | border-radius:15px; 25 | -moz-border-radius: 15px; 26 | -webkit-border-radius: 15px; 27 | } 28 | ol#qunit-tests li li{ 29 | border-bottom:none; 30 | margin:0.5em; 31 | background-color:#fff; 32 | list-style-position: inside; 33 | padding:0.4em 0.5em 0.4em 0.5em; 34 | } 35 | 36 | ol#qunit-tests li li.pass{ 37 | border-left:26px solid #C6E746; 38 | background-color:#fff; 39 | color:#5E740B; 40 | } 41 | ol#qunit-tests li li.fail{ 42 | border-left:26px solid #EE5757; 43 | background-color:#fff; 44 | color:#710909; 45 | } 46 | ol#qunit-tests li.pass{ 47 | background-color:#D2E0E6; 48 | color:#528CE0; 49 | } 50 | ol#qunit-tests li.fail{ 51 | background-color:#EE5757; 52 | color:#000; 53 | } 54 | ol#qunit-tests li strong { 55 | cursor:pointer; 56 | } 57 | h1#qunit-header{ 58 | background-color:#0d3349; 59 | margin:0; 60 | padding:0.5em 0 0.5em 1em; 61 | color:#fff; 62 | font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial; 63 | border-top-right-radius:15px; 64 | border-top-left-radius:15px; 65 | -moz-border-radius-topright:15px; 66 | -moz-border-radius-topleft:15px; 67 | -webkit-border-top-right-radius:15px; 68 | -webkit-border-top-left-radius:15px; 69 | text-shadow: rgba(0, 0, 0, 0.5) 4px 4px 1px; 70 | } 71 | h2#qunit-banner{ 72 | font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial; 73 | height:5px; 74 | margin:0; 75 | padding:0; 76 | } 77 | h2#qunit-banner.qunit-pass{ 78 | background-color:#C6E746; 79 | } 80 | h2#qunit-banner.qunit-fail, #qunit-testrunner-toolbar { 81 | background-color:#EE5757; 82 | } 83 | #qunit-testrunner-toolbar { 84 | font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial; 85 | padding:0; 86 | /*width:80%;*/ 87 | padding:0em 0 0.5em 2em; 88 | font-size: small; 89 | } 90 | h2#qunit-userAgent { 91 | font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial; 92 | background-color:#2b81af; 93 | margin:0; 94 | padding:0; 95 | color:#fff; 96 | font-size: small; 97 | padding:0.5em 0 0.5em 2.5em; 98 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; 99 | } 100 | p#qunit-testresult{ 101 | font-family:"Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial; 102 | margin:0; 103 | font-size: small; 104 | color:#2b81af; 105 | border-bottom-right-radius:15px; 106 | border-bottom-left-radius:15px; 107 | -moz-border-radius-bottomright:15px; 108 | -moz-border-radius-bottomleft:15px; 109 | -webkit-border-bottom-right-radius:15px; 110 | -webkit-border-bottom-left-radius:15px; 111 | background-color:#D2E0E6; 112 | padding:0.5em 0.5em 0.5em 2.5em; 113 | } 114 | strong b.fail{ 115 | color:#710909; 116 | } 117 | strong b.pass{ 118 | color:#5E740B; 119 | } 120 | -------------------------------------------------------------------------------- /test/qunit.js: -------------------------------------------------------------------------------- 1 | /* 2 | * QUnit - A JavaScript Unit Testing Framework 3 | * 4 | * http://docs.jquery.com/QUnit 5 | * 6 | * Copyright (c) 2009 John Resig, Jörn Zaefferer 7 | * Dual licensed under the MIT (MIT-LICENSE.txt) 8 | * and GPL (GPL-LICENSE.txt) licenses. 9 | */ 10 | 11 | (function(window) { 12 | 13 | var QUnit = { 14 | 15 | // Initialize the configuration options 16 | init: function() { 17 | config = { 18 | stats: { all: 0, bad: 0 }, 19 | moduleStats: { all: 0, bad: 0 }, 20 | started: +new Date, 21 | updateRate: 1000, 22 | blocking: false, 23 | autorun: false, 24 | assertions: [], 25 | filters: [], 26 | queue: [] 27 | }; 28 | 29 | var tests = id("qunit-tests"), 30 | banner = id("qunit-banner"), 31 | result = id("qunit-testresult"); 32 | 33 | if ( tests ) { 34 | tests.innerHTML = ""; 35 | } 36 | 37 | if ( banner ) { 38 | banner.className = ""; 39 | } 40 | 41 | if ( result ) { 42 | result.parentNode.removeChild( result ); 43 | } 44 | }, 45 | 46 | // call on start of module test to prepend name to all tests 47 | module: function(name, testEnvironment) { 48 | config.currentModule = name; 49 | 50 | synchronize(function() { 51 | if ( config.currentModule ) { 52 | QUnit.moduleDone( config.currentModule, config.moduleStats.bad, config.moduleStats.all ); 53 | } 54 | 55 | config.currentModule = name; 56 | config.moduleTestEnvironment = testEnvironment; 57 | config.moduleStats = { all: 0, bad: 0 }; 58 | 59 | QUnit.moduleStart( name, testEnvironment ); 60 | }); 61 | }, 62 | 63 | asyncTest: function(testName, expected, callback) { 64 | if ( arguments.length === 2 ) { 65 | callback = expected; 66 | expected = 0; 67 | } 68 | 69 | QUnit.test(testName, expected, callback, true); 70 | }, 71 | 72 | test: function(testName, expected, callback, async) { 73 | var name = testName, testEnvironment, testEnvironmentArg; 74 | 75 | if ( arguments.length === 2 ) { 76 | callback = expected; 77 | expected = null; 78 | } 79 | // is 2nd argument a testEnvironment? 80 | if ( expected && typeof expected === 'object') { 81 | testEnvironmentArg = expected; 82 | expected = null; 83 | } 84 | 85 | if ( config.currentModule ) { 86 | name = config.currentModule + " module: " + name; 87 | } 88 | 89 | if ( !validTest(name) ) { 90 | return; 91 | } 92 | 93 | synchronize(function() { 94 | QUnit.testStart( testName ); 95 | 96 | testEnvironment = extend({ 97 | setup: function() {}, 98 | teardown: function() {} 99 | }, config.moduleTestEnvironment); 100 | if (testEnvironmentArg) { 101 | extend(testEnvironment,testEnvironmentArg); 102 | } 103 | 104 | // allow utility functions to access the current test environment 105 | QUnit.current_testEnvironment = testEnvironment; 106 | 107 | config.assertions = []; 108 | config.expected = expected; 109 | 110 | try { 111 | if ( !config.pollution ) { 112 | saveGlobal(); 113 | } 114 | 115 | testEnvironment.setup.call(testEnvironment); 116 | } catch(e) { 117 | QUnit.ok( false, "Setup failed on " + name + ": " + e.message ); 118 | } 119 | 120 | if ( async ) { 121 | QUnit.stop(); 122 | } 123 | 124 | try { 125 | callback.call(testEnvironment); 126 | } catch(e) { 127 | fail("Test " + name + " died, exception and test follows", e, callback); 128 | QUnit.ok( false, "Died on test #" + (config.assertions.length + 1) + ": " + e.message ); 129 | // else next test will carry the responsibility 130 | saveGlobal(); 131 | 132 | // Restart the tests if they're blocking 133 | if ( config.blocking ) { 134 | start(); 135 | } 136 | } 137 | }); 138 | 139 | synchronize(function() { 140 | try { 141 | checkPollution(); 142 | testEnvironment.teardown.call(testEnvironment); 143 | } catch(e) { 144 | QUnit.ok( false, "Teardown failed on " + name + ": " + e.message ); 145 | } 146 | 147 | try { 148 | QUnit.reset(); 149 | } catch(e) { 150 | fail("reset() failed, following Test " + name + ", exception and reset fn follows", e, reset); 151 | } 152 | 153 | if ( config.expected && config.expected != config.assertions.length ) { 154 | QUnit.ok( false, "Expected " + config.expected + " assertions, but " + config.assertions.length + " were run" ); 155 | } 156 | 157 | var good = 0, bad = 0, 158 | tests = id("qunit-tests"); 159 | 160 | config.stats.all += config.assertions.length; 161 | config.moduleStats.all += config.assertions.length; 162 | 163 | if ( tests ) { 164 | var ol = document.createElement("ol"); 165 | ol.style.display = "none"; 166 | 167 | for ( var i = 0; i < config.assertions.length; i++ ) { 168 | var assertion = config.assertions[i]; 169 | 170 | var li = document.createElement("li"); 171 | li.className = assertion.result ? "pass" : "fail"; 172 | li.appendChild(document.createTextNode(assertion.message || "(no message)")); 173 | ol.appendChild( li ); 174 | 175 | if ( assertion.result ) { 176 | good++; 177 | } else { 178 | bad++; 179 | config.stats.bad++; 180 | config.moduleStats.bad++; 181 | } 182 | } 183 | 184 | var b = document.createElement("strong"); 185 | b.innerHTML = name + " (" + bad + ", " + good + ", " + config.assertions.length + ")"; 186 | 187 | addEvent(b, "click", function() { 188 | var next = b.nextSibling, display = next.style.display; 189 | next.style.display = display === "none" ? "block" : "none"; 190 | }); 191 | 192 | addEvent(b, "dblclick", function(e) { 193 | var target = e && e.target ? e.target : window.event.srcElement; 194 | if ( target.nodeName.toLowerCase() === "strong" ) { 195 | var text = "", node = target.firstChild; 196 | 197 | while ( node.nodeType === 3 ) { 198 | text += node.nodeValue; 199 | node = node.nextSibling; 200 | } 201 | 202 | text = text.replace(/(^\s*|\s*$)/g, ""); 203 | 204 | if ( window.location ) { 205 | window.location.href = window.location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent(text); 206 | } 207 | } 208 | }); 209 | 210 | var li = document.createElement("li"); 211 | li.className = bad ? "fail" : "pass"; 212 | li.appendChild( b ); 213 | li.appendChild( ol ); 214 | tests.appendChild( li ); 215 | 216 | if ( bad ) { 217 | var toolbar = id("qunit-testrunner-toolbar"); 218 | if ( toolbar ) { 219 | toolbar.style.display = "block"; 220 | id("qunit-filter-pass").disabled = null; 221 | id("qunit-filter-missing").disabled = null; 222 | } 223 | } 224 | 225 | } else { 226 | for ( var i = 0; i < config.assertions.length; i++ ) { 227 | if ( !config.assertions[i].result ) { 228 | bad++; 229 | config.stats.bad++; 230 | config.moduleStats.bad++; 231 | } 232 | } 233 | } 234 | 235 | QUnit.testDone( testName, bad, config.assertions.length ); 236 | 237 | if ( !window.setTimeout && !config.queue.length ) { 238 | done(); 239 | } 240 | }); 241 | 242 | if ( window.setTimeout && !config.doneTimer ) { 243 | config.doneTimer = window.setTimeout(function(){ 244 | if ( !config.queue.length ) { 245 | done(); 246 | } else { 247 | synchronize( done ); 248 | } 249 | }, 13); 250 | } 251 | }, 252 | 253 | /** 254 | * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. 255 | */ 256 | expect: function(asserts) { 257 | config.expected = asserts; 258 | }, 259 | 260 | /** 261 | * Asserts true. 262 | * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); 263 | */ 264 | ok: function(a, msg) { 265 | QUnit.log(a, msg); 266 | 267 | config.assertions.push({ 268 | result: !!a, 269 | message: msg 270 | }); 271 | }, 272 | 273 | /** 274 | * Checks that the first two arguments are equal, with an optional message. 275 | * Prints out both actual and expected values. 276 | * 277 | * Prefered to ok( actual == expected, message ) 278 | * 279 | * @example equal( format("Received {0} bytes.", 2), "Received 2 bytes." ); 280 | * 281 | * @param Object actual 282 | * @param Object expected 283 | * @param String message (optional) 284 | */ 285 | equal: function(actual, expected, message) { 286 | push(expected == actual, actual, expected, message); 287 | }, 288 | 289 | notEqual: function(actual, expected, message) { 290 | push(expected != actual, actual, expected, message); 291 | }, 292 | 293 | deepEqual: function(a, b, message) { 294 | push(QUnit.equiv(a, b), a, b, message); 295 | }, 296 | 297 | notDeepEqual: function(a, b, message) { 298 | push(!QUnit.equiv(a, b), a, b, message); 299 | }, 300 | 301 | strictEqual: function(actual, expected, message) { 302 | push(expected === actual, actual, expected, message); 303 | }, 304 | 305 | notStrictEqual: function(actual, expected, message) { 306 | push(expected !== actual, actual, expected, message); 307 | }, 308 | 309 | start: function() { 310 | // A slight delay, to avoid any current callbacks 311 | if ( window.setTimeout ) { 312 | window.setTimeout(function() { 313 | if ( config.timeout ) { 314 | clearTimeout(config.timeout); 315 | } 316 | 317 | config.blocking = false; 318 | process(); 319 | }, 13); 320 | } else { 321 | config.blocking = false; 322 | process(); 323 | } 324 | }, 325 | 326 | stop: function(timeout) { 327 | config.blocking = true; 328 | 329 | if ( timeout && window.setTimeout ) { 330 | config.timeout = window.setTimeout(function() { 331 | QUnit.ok( false, "Test timed out" ); 332 | QUnit.start(); 333 | }, timeout); 334 | } 335 | }, 336 | 337 | /** 338 | * Resets the test setup. Useful for tests that modify the DOM. 339 | */ 340 | reset: function() { 341 | if ( window.jQuery ) { 342 | jQuery("#main").html( config.fixture ); 343 | jQuery.event.global = {}; 344 | jQuery.ajaxSettings = extend({}, config.ajaxSettings); 345 | } 346 | }, 347 | 348 | /** 349 | * Trigger an event on an element. 350 | * 351 | * @example triggerEvent( document.body, "click" ); 352 | * 353 | * @param DOMElement elem 354 | * @param String type 355 | */ 356 | triggerEvent: function( elem, type, event ) { 357 | if ( document.createEvent ) { 358 | event = document.createEvent("MouseEvents"); 359 | event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, 360 | 0, 0, 0, 0, 0, false, false, false, false, 0, null); 361 | elem.dispatchEvent( event ); 362 | 363 | } else if ( elem.fireEvent ) { 364 | elem.fireEvent("on"+type); 365 | } 366 | }, 367 | 368 | // Safe object type checking 369 | is: function( type, obj ) { 370 | return Object.prototype.toString.call( obj ) === "[object "+ type +"]"; 371 | }, 372 | 373 | // Logging callbacks 374 | done: function(failures, total) {}, 375 | log: function(result, message) {}, 376 | testStart: function(name) {}, 377 | testDone: function(name, failures, total) {}, 378 | moduleStart: function(name, testEnvironment) {}, 379 | moduleDone: function(name, failures, total) {} 380 | }; 381 | 382 | // Backwards compatibility, deprecated 383 | QUnit.equals = QUnit.equal; 384 | QUnit.same = QUnit.deepEqual; 385 | 386 | // Maintain internal state 387 | var config = { 388 | // The queue of tests to run 389 | queue: [], 390 | 391 | // block until document ready 392 | blocking: true 393 | }; 394 | 395 | // Load paramaters 396 | (function() { 397 | var location = window.location || { search: "", protocol: "file:" }, 398 | GETParams = location.search.slice(1).split('&'); 399 | 400 | for ( var i = 0; i < GETParams.length; i++ ) { 401 | GETParams[i] = decodeURIComponent( GETParams[i] ); 402 | if ( GETParams[i] === "noglobals" ) { 403 | GETParams.splice( i, 1 ); 404 | i--; 405 | config.noglobals = true; 406 | } else if ( GETParams[i].search('=') > -1 ) { 407 | GETParams.splice( i, 1 ); 408 | i--; 409 | } 410 | } 411 | 412 | // restrict modules/tests by get parameters 413 | config.filters = GETParams; 414 | 415 | // Figure out if we're running the tests from a server or not 416 | QUnit.isLocal = !!(location.protocol === 'file:'); 417 | })(); 418 | 419 | // Expose the API as global variables, unless an 'exports' 420 | // object exists, in that case we assume we're in CommonJS 421 | if ( typeof exports === "undefined" || typeof require === "undefined" ) { 422 | extend(window, QUnit); 423 | window.QUnit = QUnit; 424 | } else { 425 | extend(exports, QUnit); 426 | exports.QUnit = QUnit; 427 | } 428 | 429 | if ( typeof document === "undefined" || document.readyState === "complete" ) { 430 | config.autorun = true; 431 | } 432 | 433 | addEvent(window, "load", function() { 434 | // Initialize the config, saving the execution queue 435 | var oldconfig = extend({}, config); 436 | QUnit.init(); 437 | extend(config, oldconfig); 438 | 439 | config.blocking = false; 440 | 441 | var userAgent = id("qunit-userAgent"); 442 | if ( userAgent ) { 443 | userAgent.innerHTML = navigator.userAgent; 444 | } 445 | 446 | var toolbar = id("qunit-testrunner-toolbar"); 447 | if ( toolbar ) { 448 | toolbar.style.display = "none"; 449 | 450 | var filter = document.createElement("input"); 451 | filter.type = "checkbox"; 452 | filter.id = "qunit-filter-pass"; 453 | filter.disabled = true; 454 | addEvent( filter, "click", function() { 455 | var li = document.getElementsByTagName("li"); 456 | for ( var i = 0; i < li.length; i++ ) { 457 | if ( li[i].className.indexOf("pass") > -1 ) { 458 | li[i].style.display = filter.checked ? "none" : ""; 459 | } 460 | } 461 | }); 462 | toolbar.appendChild( filter ); 463 | 464 | var label = document.createElement("label"); 465 | label.setAttribute("for", "qunit-filter-pass"); 466 | label.innerHTML = "Hide passed tests"; 467 | toolbar.appendChild( label ); 468 | 469 | var missing = document.createElement("input"); 470 | missing.type = "checkbox"; 471 | missing.id = "qunit-filter-missing"; 472 | missing.disabled = true; 473 | addEvent( missing, "click", function() { 474 | var li = document.getElementsByTagName("li"); 475 | for ( var i = 0; i < li.length; i++ ) { 476 | if ( li[i].className.indexOf("fail") > -1 && li[i].innerHTML.indexOf('missing test - untested code is broken code') > - 1 ) { 477 | li[i].parentNode.parentNode.style.display = missing.checked ? "none" : "block"; 478 | } 479 | } 480 | }); 481 | toolbar.appendChild( missing ); 482 | 483 | label = document.createElement("label"); 484 | label.setAttribute("for", "qunit-filter-missing"); 485 | label.innerHTML = "Hide missing tests (untested code is broken code)"; 486 | toolbar.appendChild( label ); 487 | } 488 | 489 | var main = id('main'); 490 | if ( main ) { 491 | config.fixture = main.innerHTML; 492 | } 493 | 494 | if ( window.jQuery ) { 495 | config.ajaxSettings = window.jQuery.ajaxSettings; 496 | } 497 | 498 | QUnit.start(); 499 | }); 500 | 501 | function done() { 502 | if ( config.doneTimer && window.clearTimeout ) { 503 | window.clearTimeout( config.doneTimer ); 504 | config.doneTimer = null; 505 | } 506 | 507 | if ( config.queue.length ) { 508 | config.doneTimer = window.setTimeout(function(){ 509 | if ( !config.queue.length ) { 510 | done(); 511 | } else { 512 | synchronize( done ); 513 | } 514 | }, 13); 515 | 516 | return; 517 | } 518 | 519 | config.autorun = true; 520 | 521 | // Log the last module results 522 | if ( config.currentModule ) { 523 | QUnit.moduleDone( config.currentModule, config.moduleStats.bad, config.moduleStats.all ); 524 | } 525 | 526 | var banner = id("qunit-banner"), 527 | tests = id("qunit-tests"), 528 | html = ['Tests completed in ', 529 | +new Date - config.started, ' milliseconds.
                ', 530 | '', config.stats.all - config.stats.bad, ' tests of ', config.stats.all, ' passed, ', config.stats.bad,' failed.'].join(''); 531 | 532 | if ( banner ) { 533 | banner.className = (config.stats.bad ? "qunit-fail" : "qunit-pass"); 534 | } 535 | 536 | if ( tests ) { 537 | var result = id("qunit-testresult"); 538 | 539 | if ( !result ) { 540 | result = document.createElement("p"); 541 | result.id = "qunit-testresult"; 542 | result.className = "result"; 543 | tests.parentNode.insertBefore( result, tests.nextSibling ); 544 | } 545 | 546 | result.innerHTML = html; 547 | } 548 | 549 | QUnit.done( config.stats.bad, config.stats.all ); 550 | } 551 | 552 | function validTest( name ) { 553 | var i = config.filters.length, 554 | run = false; 555 | 556 | if ( !i ) { 557 | return true; 558 | } 559 | 560 | while ( i-- ) { 561 | var filter = config.filters[i], 562 | not = filter.charAt(0) == '!'; 563 | 564 | if ( not ) { 565 | filter = filter.slice(1); 566 | } 567 | 568 | if ( name.indexOf(filter) !== -1 ) { 569 | return !not; 570 | } 571 | 572 | if ( not ) { 573 | run = true; 574 | } 575 | } 576 | 577 | return run; 578 | } 579 | 580 | function push(result, actual, expected, message) { 581 | message = message || (result ? "okay" : "failed"); 582 | QUnit.ok( result, result ? message + ": " + QUnit.jsDump.parse(expected) : message + ", expected: " + QUnit.jsDump.parse(expected) + " result: " + QUnit.jsDump.parse(actual) ); 583 | } 584 | 585 | function synchronize( callback ) { 586 | config.queue.push( callback ); 587 | 588 | if ( config.autorun && !config.blocking ) { 589 | process(); 590 | } 591 | } 592 | 593 | function process() { 594 | var start = (new Date()).getTime(); 595 | 596 | while ( config.queue.length && !config.blocking ) { 597 | if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) { 598 | config.queue.shift()(); 599 | 600 | } else { 601 | setTimeout( process, 13 ); 602 | break; 603 | } 604 | } 605 | } 606 | 607 | function saveGlobal() { 608 | config.pollution = []; 609 | 610 | if ( config.noglobals ) { 611 | for ( var key in window ) { 612 | config.pollution.push( key ); 613 | } 614 | } 615 | } 616 | 617 | function checkPollution( name ) { 618 | var old = config.pollution; 619 | saveGlobal(); 620 | 621 | var newGlobals = diff( old, config.pollution ); 622 | if ( newGlobals.length > 0 ) { 623 | ok( false, "Introduced global variable(s): " + newGlobals.join(", ") ); 624 | config.expected++; 625 | } 626 | 627 | var deletedGlobals = diff( config.pollution, old ); 628 | if ( deletedGlobals.length > 0 ) { 629 | ok( false, "Deleted global variable(s): " + deletedGlobals.join(", ") ); 630 | config.expected++; 631 | } 632 | } 633 | 634 | // returns a new Array with the elements that are in a but not in b 635 | function diff( a, b ) { 636 | var result = a.slice(); 637 | for ( var i = 0; i < result.length; i++ ) { 638 | for ( var j = 0; j < b.length; j++ ) { 639 | if ( result[i] === b[j] ) { 640 | result.splice(i, 1); 641 | i--; 642 | break; 643 | } 644 | } 645 | } 646 | return result; 647 | } 648 | 649 | function fail(message, exception, callback) { 650 | if ( typeof console !== "undefined" && console.error && console.warn ) { 651 | console.error(message); 652 | console.error(exception); 653 | console.warn(callback.toString()); 654 | 655 | } else if ( window.opera && opera.postError ) { 656 | opera.postError(message, exception, callback.toString); 657 | } 658 | } 659 | 660 | function extend(a, b) { 661 | for ( var prop in b ) { 662 | a[prop] = b[prop]; 663 | } 664 | 665 | return a; 666 | } 667 | 668 | function addEvent(elem, type, fn) { 669 | if ( elem.addEventListener ) { 670 | elem.addEventListener( type, fn, false ); 671 | } else if ( elem.attachEvent ) { 672 | elem.attachEvent( "on" + type, fn ); 673 | } else { 674 | fn(); 675 | } 676 | } 677 | 678 | function id(name) { 679 | return !!(typeof document !== "undefined" && document && document.getElementById) && 680 | document.getElementById( name ); 681 | } 682 | 683 | // Test for equality any JavaScript type. 684 | // Discussions and reference: http://philrathe.com/articles/equiv 685 | // Test suites: http://philrathe.com/tests/equiv 686 | // Author: Philippe Rathé 687 | QUnit.equiv = function () { 688 | 689 | var innerEquiv; // the real equiv function 690 | var callers = []; // stack to decide between skip/abort functions 691 | var parents = []; // stack to avoiding loops from circular referencing 692 | 693 | 694 | // Determine what is o. 695 | function hoozit(o) { 696 | if (QUnit.is("String", o)) { 697 | return "string"; 698 | 699 | } else if (QUnit.is("Boolean", o)) { 700 | return "boolean"; 701 | 702 | } else if (QUnit.is("Number", o)) { 703 | 704 | if (isNaN(o)) { 705 | return "nan"; 706 | } else { 707 | return "number"; 708 | } 709 | 710 | } else if (typeof o === "undefined") { 711 | return "undefined"; 712 | 713 | // consider: typeof null === object 714 | } else if (o === null) { 715 | return "null"; 716 | 717 | // consider: typeof [] === object 718 | } else if (QUnit.is( "Array", o)) { 719 | return "array"; 720 | 721 | // consider: typeof new Date() === object 722 | } else if (QUnit.is( "Date", o)) { 723 | return "date"; 724 | 725 | // consider: /./ instanceof Object; 726 | // /./ instanceof RegExp; 727 | // typeof /./ === "function"; // => false in IE and Opera, 728 | // true in FF and Safari 729 | } else if (QUnit.is( "RegExp", o)) { 730 | return "regexp"; 731 | 732 | } else if (typeof o === "object") { 733 | return "object"; 734 | 735 | } else if (QUnit.is( "Function", o)) { 736 | return "function"; 737 | } else { 738 | return undefined; 739 | } 740 | } 741 | 742 | // Call the o related callback with the given arguments. 743 | function bindCallbacks(o, callbacks, args) { 744 | var prop = hoozit(o); 745 | if (prop) { 746 | if (hoozit(callbacks[prop]) === "function") { 747 | return callbacks[prop].apply(callbacks, args); 748 | } else { 749 | return callbacks[prop]; // or undefined 750 | } 751 | } 752 | } 753 | 754 | var callbacks = function () { 755 | 756 | // for string, boolean, number and null 757 | function useStrictEquality(b, a) { 758 | if (b instanceof a.constructor || a instanceof b.constructor) { 759 | // to catch short annotaion VS 'new' annotation of a declaration 760 | // e.g. var i = 1; 761 | // var j = new Number(1); 762 | return a == b; 763 | } else { 764 | return a === b; 765 | } 766 | } 767 | 768 | return { 769 | "string": useStrictEquality, 770 | "boolean": useStrictEquality, 771 | "number": useStrictEquality, 772 | "null": useStrictEquality, 773 | "undefined": useStrictEquality, 774 | 775 | "nan": function (b) { 776 | return isNaN(b); 777 | }, 778 | 779 | "date": function (b, a) { 780 | return hoozit(b) === "date" && a.valueOf() === b.valueOf(); 781 | }, 782 | 783 | "regexp": function (b, a) { 784 | return hoozit(b) === "regexp" && 785 | a.source === b.source && // the regex itself 786 | a.global === b.global && // and its modifers (gmi) ... 787 | a.ignoreCase === b.ignoreCase && 788 | a.multiline === b.multiline; 789 | }, 790 | 791 | // - skip when the property is a method of an instance (OOP) 792 | // - abort otherwise, 793 | // initial === would have catch identical references anyway 794 | "function": function () { 795 | var caller = callers[callers.length - 1]; 796 | return caller !== Object && 797 | typeof caller !== "undefined"; 798 | }, 799 | 800 | "array": function (b, a) { 801 | var i, j, loop; 802 | var len; 803 | 804 | // b could be an object literal here 805 | if ( ! (hoozit(b) === "array")) { 806 | return false; 807 | } 808 | 809 | len = a.length; 810 | if (len !== b.length) { // safe and faster 811 | return false; 812 | } 813 | 814 | //track reference to avoid circular references 815 | parents.push(a); 816 | for (i = 0; i < len; i++) { 817 | loop = false; 818 | for(j=0;j= 0) { 963 | type = "array"; 964 | } else { 965 | type = typeof obj; 966 | } 967 | return type; 968 | }, 969 | separator:function() { 970 | return this.multiline ? this.HTML ? '
                ' : '\n' : this.HTML ? ' ' : ' '; 971 | }, 972 | indent:function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing 973 | if ( !this.multiline ) 974 | return ''; 975 | var chr = this.indentChar; 976 | if ( this.HTML ) 977 | chr = chr.replace(/\t/g,' ').replace(/ /g,' '); 978 | return Array( this._depth_ + (extra||0) ).join(chr); 979 | }, 980 | up:function( a ) { 981 | this._depth_ += a || 1; 982 | }, 983 | down:function( a ) { 984 | this._depth_ -= a || 1; 985 | }, 986 | setParser:function( name, parser ) { 987 | this.parsers[name] = parser; 988 | }, 989 | // The next 3 are exposed so you can use them 990 | quote:quote, 991 | literal:literal, 992 | join:join, 993 | // 994 | _depth_: 1, 995 | // This is the list of parsers, to modify them, use jsDump.setParser 996 | parsers:{ 997 | window: '[Window]', 998 | document: '[Document]', 999 | error:'[ERROR]', //when no parser is found, shouldn't happen 1000 | unknown: '[Unknown]', 1001 | 'null':'null', 1002 | undefined:'undefined', 1003 | 'function':function( fn ) { 1004 | var ret = 'function', 1005 | name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE 1006 | if ( name ) 1007 | ret += ' ' + name; 1008 | ret += '('; 1009 | 1010 | ret = [ ret, this.parse( fn, 'functionArgs' ), '){'].join(''); 1011 | return join( ret, this.parse(fn,'functionCode'), '}' ); 1012 | }, 1013 | array: array, 1014 | nodelist: array, 1015 | arguments: array, 1016 | object:function( map ) { 1017 | var ret = [ ]; 1018 | this.up(); 1019 | for ( var key in map ) 1020 | ret.push( this.parse(key,'key') + ': ' + this.parse(map[key]) ); 1021 | this.down(); 1022 | return join( '{', ret, '}' ); 1023 | }, 1024 | node:function( node ) { 1025 | var open = this.HTML ? '<' : '<', 1026 | close = this.HTML ? '>' : '>'; 1027 | 1028 | var tag = node.nodeName.toLowerCase(), 1029 | ret = open + tag; 1030 | 1031 | for ( var a in this.DOMAttrs ) { 1032 | var val = node[this.DOMAttrs[a]]; 1033 | if ( val ) 1034 | ret += ' ' + a + '=' + this.parse( val, 'attribute' ); 1035 | } 1036 | return ret + close + open + '/' + tag + close; 1037 | }, 1038 | functionArgs:function( fn ) {//function calls it internally, it's the arguments part of the function 1039 | var l = fn.length; 1040 | if ( !l ) return ''; 1041 | 1042 | var args = Array(l); 1043 | while ( l-- ) 1044 | args[l] = String.fromCharCode(97+l);//97 is 'a' 1045 | return ' ' + args.join(', ') + ' '; 1046 | }, 1047 | key:quote, //object calls it internally, the key part of an item in a map 1048 | functionCode:'[code]', //function calls it internally, it's the content of the function 1049 | attribute:quote, //node calls it internally, it's an html attribute value 1050 | string:quote, 1051 | date:quote, 1052 | regexp:literal, //regex 1053 | number:literal, 1054 | 'boolean':literal 1055 | }, 1056 | DOMAttrs:{//attributes to dump from nodes, name=>realName 1057 | id:'id', 1058 | name:'name', 1059 | 'class':'className' 1060 | }, 1061 | HTML:false,//if true, entities are escaped ( <, >, \t, space and \n ) 1062 | indentChar:' ',//indentation unit 1063 | multiline:false //if true, items in a collection, are separated by a \n, else just a space. 1064 | }; 1065 | 1066 | return jsDump; 1067 | })(); 1068 | 1069 | })(this); 1070 | -------------------------------------------------------------------------------- /test/resolveModuleId/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 261 | 262 | 263 |

                Yabble resolveModuleId

                264 |

                265 |

                266 |
                  267 | 268 | -------------------------------------------------------------------------------- /test/transportC/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 36 | 37 | 38 |

                  Yabble Transport/C Unit Tests

                  39 |

                  40 |

                  41 |
                    42 | 43 | -------------------------------------------------------------------------------- /test/transportC/tests/injects/program.js: -------------------------------------------------------------------------------- 1 | require.def('program', ['require', 'exports', 'module', 'test', 'a', 'b'], function(require, exports, module) { 2 | var test = require('test'); 3 | test.assert(typeof require == 'function', 'require is a function'); 4 | test.assert(typeof exports == 'object', 'exports is an object'); 5 | test.assert(module.id == 'program', 'module.id is program'); 6 | 7 | require('a'); 8 | require('b'); 9 | 10 | test.print('DONE', 'info'); 11 | }); 12 | 13 | 14 | require.def('a', ['require', 'test'], function(require, exports, module) { 15 | var test = require('test'); 16 | test.assert(typeof require == 'function', 'require is a function'); 17 | test.assert(typeof exports == 'undefined', 'exports is undefined'); 18 | test.assert(typeof modules == 'undefined', 'module is undefined'); 19 | }); 20 | 21 | require.def('b', ['module', 'require', 'exports', 'test'], function(module, require, exports) { 22 | var test = require('test'); 23 | test.assert(typeof require == 'function', 'require is a function'); 24 | test.assert(typeof exports == 'object', 'exports is an object'); 25 | test.assert(module.id == 'b', 'module.id is b'); 26 | }); -------------------------------------------------------------------------------- /test/transportC/tests/injects/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/transportC/tests/multipleDefines/program.js: -------------------------------------------------------------------------------- 1 | require.def('program', ['require', 'exports', 'module', 'test', 'a'], function(require, exports, module) { 2 | var test = require('test'); 3 | test.assert(typeof require == 'function', 'require is a function'); 4 | test.assert(typeof exports == 'object', 'exports is an object'); 5 | test.assert(module.id == 'program', 'module.id is program'); 6 | test.assert(require('a').foo == 'bar', 'module a is available'); 7 | test.print('DONE', 'info'); 8 | }); 9 | 10 | // This part could use some cleaning up 11 | var aIsKnown = require.isKnown('a'); 12 | print((aIsKnown ? 'FAIL ' : 'PASS ') + 'a is not yet known', (aIsKnown ? 'fail' : 'pass')); 13 | 14 | require.def('a', ['require', 'exports', 'module', 'test'], function(require, exports, module) { 15 | var test = require('test'); 16 | test.assert(typeof require == 'function', 'require is a function'); 17 | test.assert(typeof exports == 'object', 'exports is an object'); 18 | test.assert(module.id == 'a', 'module.id is a'); 19 | exports.foo = 'bar'; 20 | }); -------------------------------------------------------------------------------- /test/transportC/tests/multipleDefines/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/transportC/tests/simple/program.js: -------------------------------------------------------------------------------- 1 | require.def('program', ['require', 'exports', 'module', 'test'], function(require, exports, module) { 2 | var test = require('test'); 3 | test.assert(typeof require == 'function', 'require is a function'); 4 | test.assert(typeof exports == 'object', 'exports is an object'); 5 | test.assert(module.id == 'program', 'module.id is program'); 6 | test.print('DONE', 'info'); 7 | }); -------------------------------------------------------------------------------- /test/transportC/tests/simple/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/transportD/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 38 | 39 | 40 |

                    Yabble Transport/D Unit Tests

                    41 |

                    42 |

                    43 |
                      44 | 45 | -------------------------------------------------------------------------------- /test/transportD/tests/injects/program.js: -------------------------------------------------------------------------------- 1 | require.define({ 2 | "program": { 3 | injects: ['require', 'exports', 'module'], 4 | factory: function(require, exports, module) { 5 | var test = require('test'); 6 | test.assert(typeof require == 'function', 'require is a function'); 7 | test.assert(typeof exports == 'object', 'exports is an object'); 8 | test.assert(module.id == 'program', 'module.id is program'); 9 | 10 | require('a'); 11 | require('b'); 12 | 13 | test.print('DONE', 'info'); 14 | } 15 | }, 16 | "a": { 17 | injects: ['require'], 18 | factory: function(require, exports, module) { 19 | var test = require('test'); 20 | test.assert(typeof require == 'function', 'require is a function'); 21 | test.assert(typeof exports == 'undefined', 'exports is undefined'); 22 | test.assert(typeof modules == 'undefined', 'module is undefined'); 23 | } 24 | }, 25 | "b": { 26 | injects: ['module', 'require', 'exports'], 27 | factory: function(module, require, exports) { 28 | var test = require('test'); 29 | test.assert(typeof require == 'function', 'require is a function'); 30 | test.assert(typeof exports == 'object', 'exports is an object'); 31 | test.assert(module.id == 'b', 'module.id is b'); 32 | } 33 | } 34 | }, ['test']); -------------------------------------------------------------------------------- /test/transportD/tests/injects/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/transportD/tests/mixedDescriptors/program.js: -------------------------------------------------------------------------------- 1 | require.define({ 2 | "program": function(require, exports, module) { 3 | var test = require('test'); 4 | test.assert(typeof require == 'function', 'require is a function'); 5 | test.assert(typeof exports == 'object', 'exports is an object'); 6 | test.assert(module.id == 'program', 'module.id is program'); 7 | 8 | require('a'); 9 | 10 | test.print('DONE', 'info'); 11 | }, 12 | "a": { 13 | injects: ['require'], 14 | factory: function(require, exports, module) { 15 | var test = require('test'); 16 | test.assert(typeof require == 'function', 'require is a function'); 17 | test.assert(typeof exports == 'undefined', 'exports is undefined'); 18 | test.assert(typeof modules == 'undefined', 'module is undefined'); 19 | } 20 | } 21 | }, ['test']); -------------------------------------------------------------------------------- /test/transportD/tests/mixedDescriptors/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/transportD/tests/multipleDefines/program.js: -------------------------------------------------------------------------------- 1 | require.define({ 2 | "program": function(require, exports, module) { 3 | var test = require('test'); 4 | test.assert(typeof require == 'function', 'require is a function'); 5 | test.assert(typeof exports == 'object', 'exports is an object'); 6 | test.assert(module.id == 'program', 'module.id is program'); 7 | test.assert(require('a').foo == 'bar', 'module a is available'); 8 | test.print('DONE', 'info'); 9 | } 10 | }, ['test', 'a']); 11 | 12 | // This part could use some cleaning up 13 | var aIsKnown = require.isKnown('a'); 14 | print((aIsKnown ? 'FAIL ' : 'PASS ') + 'a is not yet known', (aIsKnown ? 'fail' : 'pass')); 15 | 16 | require.define({ 17 | "a": function(require, exports, module) { 18 | var test = require('test'); 19 | test.assert(typeof require == 'function', 'require is a function'); 20 | test.assert(typeof exports == 'object', 'exports is an object'); 21 | test.assert(module.id == 'a', 'module.id is a'); 22 | exports.foo = 'bar'; 23 | } 24 | }, ['test']); -------------------------------------------------------------------------------- /test/transportD/tests/multipleDefines/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/transportD/tests/multipleModules/program.js: -------------------------------------------------------------------------------- 1 | require.define({ 2 | "program": function(require, exports, module) { 3 | var test = require('test'); 4 | test.assert(typeof require == 'function', 'require is a function'); 5 | test.assert(typeof exports == 'object', 'exports is an object'); 6 | test.assert(module.id == 'program', 'module.id is program'); 7 | test.assert(require('a').foo == 'bar', 'module a is available'); 8 | test.print('DONE', 'info'); 9 | }, 10 | "a": function(require, exports, module) { 11 | var test = require('test'); 12 | test.assert(typeof require == 'function', 'require is a function'); 13 | test.assert(typeof exports == 'object', 'exports is an object'); 14 | test.assert(module.id == 'a', 'module.id is a'); 15 | exports.foo = 'bar'; 16 | } 17 | }, ['test']); -------------------------------------------------------------------------------- /test/transportD/tests/multipleModules/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); -------------------------------------------------------------------------------- /test/transportD/tests/simple/program.js: -------------------------------------------------------------------------------- 1 | require.define({ 2 | "program": function(require, exports, module) { 3 | var test = require('test'); 4 | test.assert(typeof require == 'function', 'require is a function'); 5 | test.assert(typeof exports == 'object', 'exports is an object'); 6 | test.assert(module.id == 'program', 'module.id is program'); 7 | test.print('DONE', 'info'); 8 | } 9 | }, ['test']); -------------------------------------------------------------------------------- /test/transportD/tests/simple/test.js: -------------------------------------------------------------------------------- 1 | /* This file has been generated by yabbler.js */ 2 | require.define({ 3 | "test": function(require, exports, module) { 4 | 5 | exports.print = typeof print !== "undefined" ? print : function () { 6 | var system = require("system"); 7 | var stdio = system.stdio; 8 | stdio.print.apply(stdio, arguments); 9 | }; 10 | 11 | exports.assert = function (guard, message) { 12 | if (guard) { 13 | exports.print('PASS ' + message, 'pass'); 14 | } else { 15 | exports.print('FAIL ' + message, 'fail'); 16 | } 17 | }; 18 | 19 | 20 | }}, ["system"]); --------------------------------------------------------------------------------