Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update meta, start adding tests

  • Loading branch information...
commit 9f912eb82ef9195d9803c91f4cd211e4ad759fd0 1 parent ac8e855
Christian Johansen authored
View
6 .gitmodules
@@ -0,0 +1,6 @@
+[submodule "node_modules/buster-util"]
+ path = node_modules/buster-util
+ url = git@git.cjohansen.no:buster-js/buster-util.git
+[submodule "node_modules/sinon"]
+ path = node_modules/sinon
+ url = http://github.com/cjohansen/Sinon.JS.git
View
2  AUTHORS
@@ -1,3 +1,3 @@
-Buster.JS Utils was written by
+Buster.JS Core was written by
August Lilleaas, augustlilleaas@gmail.com
Christian Johansen, christian@cjohansen.no
View
2  doc/core.txt
@@ -2,8 +2,6 @@ Buster core 0.2.0 documentation
===============================
:Author: Christian Johansen
:Email: christian@cjohansen.no
-:Author: August Lilleaas
-:Email: august.lilleaas@gmail.com
A collection of utilities commonly used across Buster.JS projects.
1  node_modules/buster-util
@@ -0,0 +1 @@
+Subproject commit 347e82b784a5b591e8b6f110e5c0c48e146d90d6
1  node_modules/sinon
@@ -0,0 +1 @@
+Subproject commit 02871ac0e24e4829a168d5d5403c1c575fc44002
View
20 package.json
@@ -1,5 +1,21 @@
{
"name": "buster-core",
"version": "0.2.0",
- "main": "./lib/buster-core"
-}
+ "description": "Buster core utilities"
+ "homepage": "http://busterjs.org/buster-core",
+ "author": {
+ "name": "August Lilleaas",
+ "email": "august.lilleaas@gmail.com",
+ "url": "http://augustl.com"
+ },
+ "contributors": [{
+ "name": "Christian Johansen",
+ "email": "christian@cjohansen.no",
+ "url": "http://cjohansen.no"
+ }],
+ "main": "./lib/buster-core",
+ "repository": {
+ "type": "git",
+ "url": "http://git.gitorious.org/buster-js/buster-core.git"
+ }
+}
View
3  run-tests
@@ -0,0 +1,3 @@
+#!/usr/bin/env node
+
+require("./test/buster-core-test.js");
View
107 test/buster-core-test.js
@@ -0,0 +1,107 @@
+if (typeof require != "undefined") {
+ var testCase = require("buster-util").testCase;
+ var assert = require("assert");
+ var buster = require("../lib/buster-core");
+ var sinon = require("sinon");
+}
+
+testCase("BusterBindTest", {
+ "should call function with bound this object": function () {
+ var func = sinon.spy();
+ var obj = {};
+ var bound = buster.bind(obj, func);
+
+ bound();
+ assert.equal(func.thisValues[0], obj);
+
+ bound.call({});
+ assert.equal(func.thisValues[1], obj);
+
+ bound.apply({});
+ assert.equal(func.thisValues[2], obj);
+ },
+
+ "should call method with bound this object": function () {
+ var obj = { meth: sinon.spy() };
+ var bound = buster.bind(obj, "meth");
+
+ bound();
+ assert.equal(obj.meth.thisValues[0], obj);
+
+ bound.call({});
+ assert.equal(obj.meth.thisValues[1], obj);
+
+ bound.apply({});
+ assert.equal(obj.meth.thisValues[2], obj);
+ },
+
+ "should call function with bound arguments": function () {
+ var func = sinon.spy();
+ var obj = {};
+ var bound = buster.bind(obj, func, 42, "Hey");
+
+ bound();
+
+ assert.ok(func.calledWith(42, "Hey"));
+ },
+
+ "should call function with bound arguments and passed arguments": function () {
+ var func = sinon.spy();
+ var obj = {};
+ var bound = buster.bind(obj, func, 42, "Hey");
+
+ bound("Bound", []);
+ assert.ok(func.calledWith(42, "Hey", "Bound", []));
+
+ bound.call(null, ".call", []);
+ assert.ok(func.calledWith(42, "Hey", ".call", []));
+
+ bound.apply(null, [".apply", []]);
+ assert.ok(func.calledWith(42, "Hey", ".apply", []));
+ }
+});
+
+testCase("BusterIsArgumentsTest", {
+ "should recognize real arguments object": function () {
+ assert.ok(buster.isArguments(arguments));
+ },
+
+ "should reject primitive": function () {
+ assert.ok(!buster.isArguments(42));
+ },
+
+ "should reject object without length": function () {
+ assert.ok(!buster.isArguments({}));
+ },
+
+ "should reject array": function () {
+ assert.ok(!buster.isArguments([]));
+ }
+});
+
+testCase("BusterCreateTest", {
+ "should create object that inherits from other object": function () {
+ var obj = { id: 42 };
+ var obj2 = buster.create(obj);
+
+ assert.ok(obj.isPrototypeOf(obj2));
+ }
+});
+
+testCase("BusterKeysTest", {
+ "should return keys of object": function () {
+ var obj = { a: 1, b: 2, c: 3 };
+
+ assert.deepEqual(buster.keys(obj).sort(), ["a", "b", "c"]);
+ },
+
+ "should exclude inherited properties": function () {
+ var obj = { a: 1, b: 2, c: 3 };
+ var obj2 = buster.create(obj);
+ obj2.d = 4;
+ obj2.e = 5;
+
+ assert.deepEqual(buster.keys(obj2).sort(), ["d", "e"]);
+ }
+});
+
Please sign in to comment.
Something went wrong with that request. Please try again.