Permalink
Browse files

Adding anon modules and function toString tests.

  • Loading branch information...
1 parent 9df7bf2 commit 9ee7f92f32f15ddd4e2f5ce409305dc7012e0d83 @jrburke jrburke committed May 18, 2011
@@ -8,5 +8,7 @@ var config = require,
//Indicate what levels of the API are implemented by this loader,
//and therefore which tests to run.
implemented = {
- basic: true
+ basic: true,
+ anon: true,
+ funcString: true
};
View
@@ -0,0 +1,3 @@
+define({
+ name: 'a'
+});
View
@@ -0,0 +1,6 @@
+define(['sub/c'], function (c) {
+ return {
+ name: 'b',
+ cName: c.name
+ };
+});
@@ -0,0 +1,32 @@
+go( ["require", "two", "funcTwo", "funcThree"],
+function(require, two, funcTwo, funcThree) {
+ var args = two.doSomething(),
+ twoInst = new funcTwo("TWO"),
+ oneMod = two.getOneModule();
+
+ doh.register(
+ "circular",
+ [
+ function circular(t) {
+ t.is("small", args.size);
+ t.is("redtwo", args.color);
+ //Check CommonJS "module.id" property support.
+ t.is("one", oneMod.id);
+ }
+ ]
+ );
+ doh.run();
+
+ doh.register(
+ "circularFunc",
+ [
+ function circularFunc(t) {
+ t.is("TWO", twoInst.name);
+ t.is("ONE-NESTED", twoInst.oneName());
+ t.is("THREE-THREE_SUFFIX", funcThree("THREE"));
+ }
+ ]
+ );
+ doh.run();
+ }
+);
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Circular Dependencies</title>
+ <script src="../bootstrap.js"></script>
+ <script src="circular-tests.js"></script>
+</head>
+<body>
+ <h1>Circular Dependencies</h1>
+ <p>Support for circular dependencies, including use of 'exports'.</p>
+ <p>See console for output.</p>
+</body>
+</html>
@@ -0,0 +1,11 @@
+define(["require", "funcThree"], function (require) {
+ var four = function (arg) {
+ return "FOUR called with " + arg;
+ };
+
+ four.suffix = function () {
+ return require("funcThree").suffix();
+ };
+
+ return four;
+});
View
@@ -0,0 +1,12 @@
+define(["require", "funcTwo"], function (require) {
+ var one = function (name) {
+ this.name = name;
+ };
+
+ one.prototype.getName = function () {
+ var inst = new (require("funcTwo"))("-NESTED");
+ return this.name + inst.name;
+ };
+
+ return one;
+});
@@ -0,0 +1,11 @@
+define(["funcFour"], function (four) {
+ var three = function (arg) {
+ return arg + "-" + require("funcFour").suffix();
+ };
+
+ three.suffix = function () {
+ return "THREE_SUFFIX";
+ };
+
+ return three;
+});
View
@@ -0,0 +1,12 @@
+define(["require", "funcOne"], function (require) {
+ var two = function (name) {
+ this.name = name;
+ this.one = new (require("funcOne"))("ONE");
+ };
+
+ two.prototype.oneName = function () {
+ return this.one.getName();
+ };
+
+ return two;
+});
View
@@ -0,0 +1,7 @@
+define(["require", "exports", "module", "two"], function(require, exports, module) {
+ exports.size = "large";
+ exports.module = module;
+ exports.doSomething = function() {
+ return require("two");
+ };
+});
@@ -0,0 +1,15 @@
+go(['a', 'b'], function (a, b) {
+
+ doh.register(
+ "basic/simple",
+ [
+ function simple(t){
+ t.is('a', a.name);
+ t.is('b', b.name);
+ t.is('c', b.cName);
+ }
+ ]
+ );
+ doh.run();
+
+});
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Simple named dependencies</title>
+ <script src="../bootstrap.js"></script>
+ <script src="simple-tests.js"></script>
+</head>
+<body>
+ <h1>Simple named dependencies</h1>
+ <p>Simple dependency resolution.</p>
+ <p>See console for output.</p>
+</body>
+</html>
View
@@ -0,0 +1,5 @@
+define(function () {
+ return {
+ name: 'c'
+ };
+});
View
@@ -0,0 +1,12 @@
+define(["require", "one"], function(require, one) {
+ return {
+ size: "small",
+ color: "redtwo",
+ doSomething: function() {
+ return one.doSomething();
+ },
+ getOneModule: function() {
+ return one.module;
+ }
+ };
+});
View
@@ -1,3 +1,6 @@
+/*jslint strict: false, plusplus: false, evil: true */
+/*global document: false, location: false */
+
(function () {
var args = location.search.substring(1),
parts = args.split('&'),
@@ -18,7 +21,7 @@
dohPath = dohPath.substring(0, i + 1) + 'tests/doh/';
function write(path) {
- html += '<script src="' + path + '"><\/\script>';
+ html += '<' + 'script src="' + path + '"></' + 'script>';
}
write(args.impl);
@@ -0,0 +1,5 @@
+define(function(){
+ return function () {
+ return 'five';
+ }
+});
@@ -0,0 +1,3 @@
+define(function(){
+ return 'four';
+});
@@ -0,0 +1,24 @@
+go(['one', 'two', 'three'], function (one, two, three) {
+
+ var args = two.doSomething(),
+ oneMod = two.getOneModule();
+
+ doh.register(
+ "funcString",
+ [
+ function funcString(t){
+ t.is("large", one.size);
+ t.is("small", two.size);
+ t.is("small", args.size);
+ t.is("redtwo", args.color);
+ //Check CommonJS "module.id" property support.
+ t.is("one", oneMod.id);
+ t.is('three', three.name);
+ t.is('four', three.fourName);
+ t.is('five', three.fiveName);
+ }
+ ]
+ );
+ doh.run();
+
+});
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Function.prototype.toString()</title>
+ <script src="../bootstrap.js"></script>
+ <script src="funcString-tests.js"></script>
+</head>
+<body>
+ <h1>Function.prototype.toString()</h1>
+
+ <p>Using Function.prototype.toString() to find dependencies in a
+ definition function.</p>
+
+ <p>See console for output.</p>
+</body>
+</html>
@@ -0,0 +1,7 @@
+define(function(require, exports, module) {
+ exports.size = "large";
+ exports.module = module;
+ exports.doSomething = function() {
+ return require("two");
+ };
+});
@@ -0,0 +1,8 @@
+define(function (require, exports) {
+ var four = require('four'),
+ five = require('five');
+
+ exports.name = 'three';
+ exports.fourName = four;
+ exports.fiveName = five();
+});
@@ -0,0 +1,14 @@
+define(function(require) {
+ //Dependencies
+ var one = require('one');
+ return {
+ size: "small",
+ color: "redtwo",
+ doSomething: function() {
+ return one.doSomething();
+ },
+ getOneModule: function() {
+ return one.module;
+ }
+ };
+});
View
@@ -1,9 +1,14 @@
+/*jslint strict: false, plusplus: false */
+/*global location: false, doh: false, implemented: false */
+
(function () {
var suffix = '.html' + location.search,
levelNames = [
- 'basic'
+ 'basic',
+ 'anon',
+ 'funcString'
],
- i, levels;
+ i, levels, name;
//Convenience function to register test.
function reg(testName, timeout) {
@@ -16,8 +21,18 @@
reg('basic/defineAmd');
reg('basic/simple');
reg('basic/circular');
+ },
+
+ anon: function () {
+ reg('anon/simple');
+ reg('anon/circular');
+ },
+
+ funcString: function () {
+ reg('funcString/funcString')
}
+
//basic: true, //include require, exports, module tests.
//anonymous: true, //include function callback and basic object callback,
//circular deps

0 comments on commit 9ee7f92

Please sign in to comment.