From 9fc5105a0778dce430e7f2a831d91dc772439a1f Mon Sep 17 00:00:00 2001 From: Tim Disney Date: Thu, 15 Dec 2011 10:36:45 -0800 Subject: [PATCH] now all the browser tests pass --- index.html | 4 +- lib/contracts.js | 24 +---- src/contracts.coffee | 6 +- test/jquery-c.js | 233 ------------------------------------------- test/test.js | 15 +-- 5 files changed, 9 insertions(+), 273 deletions(-) delete mode 100644 test/jquery-c.js diff --git a/index.html b/index.html index 32db050..55e13ee 100644 --- a/index.html +++ b/index.html @@ -5,11 +5,9 @@ Contract.js Test Suite - - + - diff --git a/lib/contracts.js b/lib/contracts.js index 0eab683..5a63abf 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -332,25 +332,7 @@ printStackTrace.implementation.prototype = { } }; -(function() {(function() { - var old_require; - if (typeof require !== 'undefined' && require !== null) { - old_require = require; - require = function(mod, filename) { - var key, m = old_require(mod); - for(key in m) { - if(typeof(m[key]) && m[key].hasOwnProperty && m[key].hasOwnProperty('use')) { - m[key] = m[key].use(filename, mod); - } - } - return m; - }; - for(var key in old_require) { - require[key] = old_require[key]; - } - } -})(); - +(function() { "use strict"; @@ -1354,7 +1336,7 @@ printStackTrace.implementation.prototype = { return enabled = b; }; - root.autoload = function(obj) { + root.autoload = function() { var globalObj, name; globalObj = typeof window !== "undefined" && window !== null ? window : global; for (name in root) { @@ -1363,4 +1345,4 @@ printStackTrace.implementation.prototype = { } }; -}).call(this); +}).call(this); \ No newline at end of file diff --git a/src/contracts.coffee b/src/contracts.coffee index a67496c..e2f24fb 100644 --- a/src/contracts.coffee +++ b/src/contracts.coffee @@ -335,9 +335,9 @@ fun = (dom, rng, options) -> res = new bf() res = clean_rng.check(res, pos, neg, parents, stack) else - if options["this"] + if options.this # blame is reversed - thisc = options["this"].check(this, neg, pos, parents, stack) + thisc = options.this.check(this, neg, pos, parents, stack) else thisc = this res = clean_rng.check(f.apply(thisc, args), pos, neg, parents, stack) @@ -851,7 +851,7 @@ root.opt = opt root.guard = guard root.enabled = (b) -> enabled = b # puts every exported function onto the global scope -root.autoload = (obj) -> +root.autoload = -> globalObj = window ? global # browser or node globalObj[name] = root[name] for own name of root return diff --git a/test/jquery-c.js b/test/jquery-c.js deleted file mode 100644 index bfec9b7..0000000 --- a/test/jquery-c.js +++ /dev/null @@ -1,233 +0,0 @@ -/*global jQuery: true, Contracts: true */ - -// jQuery = (function() { -// var C = Contracts.C, -// K = Contracts.K, -// jqTopLevel = C.object({ -// fn: C.object({}), // the prototype -// length : K.Number, -// isFunction : C.fun(C.any, K.Boolean), -// isArray: C.fun(C.any, K.Boolean), -// isWindow: C.fun(C.any, K.Boolean), // will fail since isWindows(null/undefined) -> null/undefined -- truthiness fail -// isNaN: C.fun(C.any, K.Boolean), -// isReady: K.Boolean, // possibly some interesting dependent relation -// readyWait : K.Number, // between these ready functions -// ready: C.fun(C.any, C.any), -// bindReady : C.fun(C.any, C.any), -// holdReady: C.fun(K.Boolean, C.any), - -// isPlainObject : C.fun(C.any, K.Boolean), -// // isPlainObject : C.fun(C.any, K.Boolean, {pre: function(obj) { obj.bar === 34 }}), -// isEmptyObject : C.fun(C.any, K.Boolean), -// // ([a] + {name:a...}) -> (a -> b) -> () -- more precise than I can get currently -// each : C.fun(C.or([K.Array, C.object({})]), C.fun(C.any,C.any), C.any), -// type: C.fun(C.any, K.String), -// error : C.fun(K.String, C.any), -// parseJSON : C.funD(C.or([K.String, K.Undefined, K.Null]), function(args) { -// var arg = args[0]; // only care about the first arg -// if(arg === undefined || arg === null || arg === "") { -// return K.Null; -// } else { -// return C.object({}); -// } -// }), -// parseXML : C.fun(C.any, C.any), -// noop : C.fun(K.Undefined, C.Undefined), -// globalEval : C.fun(K.String, C.any), -// // nodeName : {nodeName : String} x String -> String, -// nodeName : C.fun(C.object({ nodeName : K.String}), K.String, K.String), -// trim : C.fun(K.String, K.String), // causes jquery tests to fail since the trim function is liberal -// // breakes qunit's "same(makeArray({length: "0"}), [])" but it does create an empty -// // array...just not deepEqual I think -// makeArray : C.fun(C.any, K.Array), -// inArray : C.fun(C.any, K.Array, K.Number), -// merge : C.fun(K.Array, K.Array, K.Array), // sameness fail -// grep : C.fun(K.Array, C.fun(C.any, K.Number, K.Boolean), K.Boolean, K.Array), -// map : C.fun(C.or([K.Array, C.object({})]), C.fun(C.any, K.Number, C.any), K.Array), -// guid : K.Number, -// // proxy : C.fun([C.fun(C.any, C.any), C.object({})], C.fun(C.any, C.any)), -// proxy : C.fun(C.any, C.any), -// // no documentation on this method -// access : C.fun(C.any, C.any), -// uaMatch : C.fun(K.String, C.object({browser: K.String, version: K.String})), - -// // {...} x {name1: val1 ...} x {nameN: valN} -> { /* props from first obj merged with 1..N */ } -// // also modifies first object -// extend: C.any, -// noConflict: C.any, -// // also has browser dependent property (eg mozilla) -// browser : C.object({version: K.String}), - -// // want to say Date -// now : C.any, - -// sub : C.any -// }), -// jq = C.object({ -// length: K.Number -// }); - -// jq.addPropertyContract({ -// // addClass :: String -> jQuery -// addClass : C.fun(K.String, jq), -// selector : K.String, -// jquery : K.String, -// size : C.fun(C.any, K.Number), -// toArray : C.fun(C.any, K.Array), // sameness fail -// // Unit -> [els] -// // Number -> el -// get : C.fun(C.any, C.any), // sameness fail - -// pushStack : C.any, -// each : C.any, -// ready : C.any, -// eq : C.any, -// first : C.any, -// last : C.any, -// slice : C.any, -// map : C.any, -// end : C.any, -// push : C.any, -// sort : C.any, -// splice : C.any, -// extend : C.any, -// data : C.any, -// removeData : C.any, -// queue : C.any, -// dequeue : C.any, -// delay : C.any, -// clearQueue : C.any, -// promise : C.any, -// attr : C.any, -// removeAttr : C.any, -// prop : C.any, -// removeProp : C.any, -// removeClass : C.any, -// toggleClass : C.any, -// hasClass : C.any, -// val : C.any, -// bind : C.any, -// one : C.any, -// unbind : C.any, -// delegate : C.any, -// undelegate : C.any, -// trigger : C.any, -// triggerHandler : C.any, -// toggle : C.any, -// hover : C.any, -// live : C.any, -// die : C.any, -// blur : C.any, -// focus : C.any, -// focusin : C.any, -// focusout : C.any, -// load : C.any, -// resize : C.any, -// scroll : C.any, -// unload : C.any, -// click : C.any, -// dblclick : C.any, -// mousedown : C.any, -// mouseup : C.any, -// mousemove : C.any, -// mouseover : C.any, -// mouseout : C.any, -// mouseenter : C.any, -// mouseleave : C.any, -// change : C.any, -// select : C.any, -// submit : C.any, -// keydown : C.any, -// keypress : C.any, -// keyup : C.any, -// error : C.any, -// find : C.any, -// has : C.any, -// not : C.any, -// filter : C.any, -// is : C.any, -// closest : C.any, -// index : C.any, -// add : C.any, -// andSelf : C.any, -// parent : C.any, -// parents : C.any, -// parentsUntil : C.any, -// next : C.any, -// prev : C.any, -// nextAll : C.any, -// prevAll : C.any, -// nextUntil : C.any, -// prevUntil : C.any, -// siblings : C.any, -// children : C.any, -// contents : C.any, -// text : C.any, -// wrapAll : C.any, -// wrapInner : C.any, -// wrap : C.any, -// unwrap : C.any, -// append : C.any, -// prepend : C.any, -// before : C.any, -// after : C.any, -// remove : C.any, -// empty : C.any, -// clone : C.any, -// html : C.any, -// replaceWith : C.any, -// detach : C.any, -// domManip : C.any, -// appendTo : C.any, -// prependTo : C.any, -// insertBefore : C.any, -// insertAfter : C.any, -// replaceAll : C.any, -// css : C.any, -// serialize : C.any, -// serializeArray : C.any, -// ajaxStart : C.any, -// ajaxStop : C.any, -// ajaxComplete : C.any, -// ajaxError : C.any, -// ajaxSuccess : C.any, -// ajaxSend : C.any, -// show : C.any, -// hide : C.any, -// _toggle : C.any, -// fadeTo : C.any, -// animate : C.any, -// stop : C.any, -// slideDown : C.any, -// slideUp : C.any, -// slideToggle : C.any, -// fadeIn : C.any, -// fadeOut : C.any, -// fadeToggle : C.any, -// offset : C.any, -// position : C.any, -// offsetParent : C.any, -// scrollLeft : C.any, -// scrollTop : C.any, -// innerHeight : C.any, -// outerHeight : C.any, -// height : C.any, -// innerWidth : C.any, -// outerWidth : C.any, -// width : C.any, -// constructor : C.any, -// init : C.any -// // prevObject : C.any, // these two only are present on jquery objects that have returned elements -// // context : C.any, -// }); - -// return C.guard( -// C.and( -// jqTopLevel, -// C.fun(C.any, jq) -// ), -// jQuery, -// "server", -// "client"); -// })(); - diff --git a/test/test.js b/test/test.js index 2a6c2ac..732705e 100644 --- a/test/test.js +++ b/test/test.js @@ -1,16 +1,5 @@ -var C = Contracts.combinators, - K = Contracts.contracts; - -function load(obj) { - var name; - for(name in obj) { - if(obj.hasOwnProperty(name)) { - window[name] = obj[name]; - } - } -} -load(Contracts.combinators); -load(Contracts.contracts); +Contracts.autoload(); + var server = "server"; var client = "client";