Browse files

Updted tests and added testling

  • Loading branch information...
1 parent 3911221 commit 073954dd34e77fcce45a65598ad1f2715113b8eb @doug-martin committed Jan 22, 2013
Showing with 103 additions and 50 deletions.
  1. +4 −1 README.md
  2. +14 −3 extender.js
  3. +12 −2 package.json
  4. +7 −0 test/browserling.js
  5. +53 −31 test/extender.test.js
  6. +13 −13 test/is.js
View
5 README.md
@@ -1,7 +1,10 @@
<a name="top"></a>
- [![build status](https://secure.travis-ci.org/doug-martin/extender.png)](http://travis-ci.org/doug-martin/extender)
+[![build status](https://secure.travis-ci.org/doug-martin/extender.png)](http://travis-ci.org/doug-martin/extender)
+
+[![browser support](http://ci.testling.com/doug-martin/extender.png)](http://ci.testling.com/doug-martin/extender)
+
# Extender
`extender` is a library that helps in making chainable APIs, by creating a function that accepts different values and returns an object decorated with functions based on the type.
View
17 extender.js
@@ -445,14 +445,15 @@
function _extender(obj) {
var ret = obj, i, l;
if (!(obj instanceof Base)) {
- var base = {}, instance = (base.instance = {"__extender__": _extender});
+ var OurBase = Base;
for (i = 0, l = defined.length; i < l; i++) {
var definer = defined[i];
if (definer[0](obj)) {
- merge(instance, definer[1]);
+ OurBase = OurBase.extend({instance: definer[1]});
}
}
- ret = new (Base.extend(base))(obj);
+ ret = new OurBase(obj);
+ ret["__extender__"] = _extender;
}
return ret;
}
@@ -470,6 +471,16 @@
decorate = decorate || {};
var proto = {};
decorateProto(proto, decorate);
+ //handle browsers like which skip over the constructor while looping
+ if (!proto.hasOwnProperty("constructor")) {
+ if (decorate.hasOwnProperty("constructor")) {
+ addMethod(proto, "constructor", decorate.constructor);
+ } else {
+ proto.constructor = function () {
+ this._super(arguments);
+ };
+ }
+ }
defined.push([tester, proto]);
}
return _extender;
View
14 package.json
@@ -1,6 +1,6 @@
{
"name": "extender",
- "version": "0.0.4",
+ "version": "0.0.5",
"description": "Easily create object decorators!",
"main": "index.js",
"scripts": {
@@ -19,11 +19,21 @@
],
"author": "Doug Martin (blog.dougamartin.com)",
"license": "MIT",
+ "testling": {
+ "files": "test/browserling.js",
+ "browsers": {
+ "ie": [6, 7, 8, 9],
+ "chrome": [4, 23, "canary"],
+ "firefox": [3, 3.5, 3.6, 4, 17, "nightly"],
+ "opera": [10, 10.5, 11, 11.5, 11.6, 12, "next"],
+ "safari": ["5.0.1", 5.1]
+ }
+ },
"dependencies": {
"declare.js": "0.0.3"
},
"devDependencies": {
- "it": "~0.1.0",
+ "it": "~0.2.0",
"grunt-it": "~0.2.0"
}
}
View
7 test/browserling.js
@@ -0,0 +1,7 @@
+var it = require("it");
+
+it.reporter("tap");
+
+require("./extender.test");
+
+it.run();
View
84 test/extender.test.js
@@ -8,23 +8,23 @@ var it = require("it"),
it.describe("extender",function (it) {
var isMethods = {
- isFunction: is.function,
- isNumber: is.number,
- isString: is.string,
- isDate: is.date,
- isArray: is.array,
- isBoolean: is.boolean,
- isUndefined: is.undefined,
- isDefined: is.defined,
- isUndefinedOrNull: is.undefinedOrNull,
- isNull: is.null,
- isArguments: is.arguments,
- isInstanceOf: is.instanceOf,
- isRegExp: is.regExp
+ isFunction: is.isFunction,
+ isNumber: is.isNumber,
+ isString: is.isString,
+ isDate: is.isDate,
+ isArray: is.isArray,
+ isBoolean: is.isBoolean,
+ isUndefined: is.isUndefined,
+ isDefined: is.isDefined,
+ isUndefinedOrNull: is.isUndefinedOrNull,
+ isNull: is.isNull,
+ isArguments: is.isArguments,
+ isInstanceOf: is.isInstanceOf,
+ isRegExp: is.isRegExp
};
var myExtender = extender
.define(isMethods)
- .define(is.string, {
+ .define(is.isString, {
multiply: function (str, times) {
var ret = str;
for (var i = 1; i < times; i++) {
@@ -53,7 +53,7 @@ it.describe("extender",function (it) {
}
}
})
- .define(is.array, {
+ .define(is.isArray, {
pluck: function (arr, m) {
var ret = [];
for (var i = 0, l = arr.length; i < l; i++) {
@@ -72,7 +72,7 @@ it.describe("extender",function (it) {
}
}
})
- .define(is.boolean, {
+ .define(is.isBoolean, {
invert: function (val) {
return !val;
@@ -136,19 +136,19 @@ it.describe("extender",function (it) {
it.should("keep extenders in their own scope", function () {
var myExtender = extender
.define({
- isFunction: is.function,
- isNumber: is.number,
- isString: is.string,
- isDate: is.date,
- isArray: is.array,
- isBoolean: is.boolean,
- isUndefined: is.undefined,
- isDefined: is.defined,
- isUndefinedOrNull: is.undefinedOrNull,
- isNull: is.null,
- isArguments: is.arguments,
- isInstanceOf: is.instanceOf,
- isRegExp: is.regExp
+ isFunction: is.isFunction,
+ isNumber: is.isNumber,
+ isString: is.isString,
+ isDate: is.isDate,
+ isArray: is.isArray,
+ isBoolean: is.isBoolean,
+ isUndefined: is.isUndefined,
+ isDefined: is.isDefined,
+ isUndefinedOrNull: is.isUndefinedOrNull,
+ isNull: is.isNull,
+ isArguments: is.isArguments,
+ isInstanceOf: is.isInstanceOf,
+ isRegExp: is.isRegExp
});
var extended = myExtender([
@@ -164,7 +164,7 @@ it.describe("extender",function (it) {
var myExtender = extender
.define(isMethods)
.expose(isMethods);
- var myExtender2 = extender.define(is.array, {
+ var myExtender2 = extender.define(is.isArray, {
pluck: function (arr, m) {
var ret = [];
for (var i = 0, l = arr.length; i < l; i++) {
@@ -204,5 +204,27 @@ it.describe("extender",function (it) {
});
+ it.describe("custom extenders with constructors", function (it) {
+ var myExtender = extender.define({
+ constructor: function (value) {
+ this.valueType = Object.prototype.toString.call(value);
+ },
+
+ noWrap: {
+ stringType: function () {
+ return this.valueType;
+ }
+ }
+ });
+
+ it.should("invoke the constructor", function () {
+ assert.equal(myExtender("string").stringType(), "[object String]");
+ });
+
+ it.should("call super properly", function () {
+ assert.equal(myExtender("hello").value(), "hello");
+ });
+ });
+
-}).run();
+});
View
26 test/is.js
@@ -65,16 +65,16 @@ function isNumber(obj) {
return !isUndefinedOrNull(obj) && (typeof obj === "number" || obj instanceof Number);
}
-exports.function = isFunction;
-exports.number = isNumber;
-exports.string = isString;
-exports.date = isDate;
-exports.array = isArray;
-exports.boolean = isBoolean;
-exports.undefined = isUndefined;
-exports.defined = isDefined;
-exports.undefinedOrNull = isUndefinedOrNull;
-exports.null = isNull;
-exports.arguments = isArguments;
-exports.instanceOf = isInstanceOf;
-exports.regExp = isRegExp;
+exports.isFunction = isFunction;
+exports.isNumber = isNumber;
+exports.isString = isString;
+exports.isDate = isDate;
+exports.isArray = isArray;
+exports.isBoolean = isBoolean;
+exports.isUndefined = isUndefined;
+exports.isDefined = isDefined;
+exports.isUndefinedOrNull = isUndefinedOrNull;
+exports.isNull = isNull;
+exports.isArguments = isArguments;
+exports.isInstanceOf = isInstanceOf;
+exports.isRegExp = isRegExp;

0 comments on commit 073954d

Please sign in to comment.