Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Commit

Permalink
Moves testing to brofist.
Browse files Browse the repository at this point in the history
  • Loading branch information
robotlolita committed May 23, 2013
1 parent 0fdef70 commit ce2e089
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 109 deletions.
20 changes: 10 additions & 10 deletions test/benchmarks/extending.js
Expand Up @@ -14,11 +14,11 @@ function data_object() {
return { c: [1], d: [2], to_data: function(){ return z }}}

// ----------------------------------------------------------------------------
var o1 = make_object(100, 'a')
var o2 = make_object(100, 'b')

suite.add('λ fast-extend', function() {
x = boo.internal.fast_extend(o1, [o2]) })
// var o1 = make_object(100, 'a')
// var o2 = make_object(100, 'b')
//
// suite.add('λ fast-extend', function() {
// x = boo.internal.fast_extend(o1, [o2]) })

// ----------------------------------------------------------------------------
var o3 = make_object(100, 'a')
Expand All @@ -35,11 +35,11 @@ suite.add('λ merge', function() {
x = boo.merge(o5, o6) })

// ----------------------------------------------------------------------------
var o7 = make_object(100, 'a')
var o8 = data_object()

suite.add('λ fast-extend (DataObject)', function() {
x = boo.internal.fast_extend(o7, [o8]) })
// var o7 = make_object(100, 'a')
// var o8 = data_object()
//
// suite.add('λ fast-extend (DataObject)', function() {
// x = boo.internal.fast_extend(o7, [o8]) })

// ----------------------------------------------------------------------------
var o9 = make_object(100, 'a')
Expand Down
5 changes: 1 addition & 4 deletions test/benchmarks/instantiation.js
Expand Up @@ -13,17 +13,14 @@ var Animal = boo.Base.derive({
var Cat = Animal.derive({
init:
function(name, colour) {
Animal.init.call(this)
Animal.init.call(this, name)
this.colour = colour }
})

suite.add('λ Base#make', function() {
x = Cat.make('Nyah', 'rainbow-coloured')
})

suite.add('λ make (generic)', function() {
x = boo.make(Cat, 'Nyah', 'rainbow-coloured') })

// -- Native ------------------------------------------------------------------
function nAnimal(name) {
this.name = name }
Expand Down
3 changes: 1 addition & 2 deletions test/benchmarks/suite.js
Expand Up @@ -29,5 +29,4 @@ function run_all(suites) {
next() }

/// -- Suite ------------------------------------------------------------------
run_all([ require('./extending')
, require('./instantiation') ])
run_all([ require('./instantiation') ])
90 changes: 0 additions & 90 deletions test/boo-core.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/mocha.opts

This file was deleted.

6 changes: 6 additions & 0 deletions test/node.js
@@ -0,0 +1,6 @@
var brofist = require('brofist')
var reporter = require('brofist-minimal')

brofist.run(require('./specs'), reporter()).then(function(results) {
if (results.failed.length) process.exit(1)
})
108 changes: 108 additions & 0 deletions test/specs/core.js
@@ -0,0 +1,108 @@
var spec = require('brofist')()
var assert = require('assert')
var boo = require('../../')

module.exports = spec('Module: boo', function(it, spec) {
spec('extend()', function(it) {
it('Should modify the first argument.', function() {
var x = {}
boo.extend(x, { a: 1 })
assert(x.a == 1)
})

it('Should use right-most precedence.', function() {
var x = { a: 1 }
boo.extend(x, { b: 1 }, { a: 2 }, { c: 3, b: 3 })
assert(x.a == 2)
assert(x.b == 3)
assert(x.c == 3)
})

it('Should clone mixins using the .toData() method.', function() {
var x = {}
var y = { data: [], toData: function(){ return { data: [] }}}

boo.extend(x, y)
x.data.push(1)

assert(y.data.length == 0)
assert(x.data.length == 1)
assert(x.data[0] == 1)
})
})

spec('merge()', function(it) {
it('Should merge all mixins in one object.', function() {
var x = { a: 1 }
var y = { b: 2 }
var z = { a: 3 }
var a = boo.merge(x, y, z)

assert(a.a == 3)
assert(a.b == 2)
})

it('Should not modify any mixins.', function() {
var x = { a: 1 }
var y = { b: 2 }
var z = { a: 3 }
var a = boo.merge(x, y, z)

assert(x.a == 1)
assert(y.b == 2)
assert(z.a == 3)
})
})

spec('derive()', function(it) {
it('Should make a new object, inheriting from proto.', function() {
var foo = { a: 1 }
var bar = boo.derive(foo)
assert(foo.isPrototypeOf(bar))
})

it('Should extend the new object with the given mixins.', function() {
var foo = { a: 1 }
var bar = boo.derive(foo, { b: 2, c: 3, a: 4 })

assert(!('b' in foo))
assert(!('c' in foo))

assert(foo.a == 1)
assert(bar.a == 4)
assert(bar.b == 2)
assert(bar.c == 3)
})
})

spec('Object: base', function(it, spec) {
spec('make()', function(it) {
it('Should clone `this`.', function() {
var x = boo.Base.make()
assert(boo.Base.isPrototypeOf(x))
})

it('Should apply the `init` method, if present.', function() {
var y = boo.Base.derive({ init: function(n){ this.a = n }})
var z = y.make(3)

assert(z.a == 3)
})
})

spec('derive()', function(it) {
it('Should derive from `this`.', function() {
var bar = boo.Base.derive()
assert(boo.Base.isPrototypeOf(bar))
})

it('Should extend the new object with the given mixins.', function() {
var bar = boo.Base.derive({ a: 2 }, { b: 3 }, { c: 4 })

assert(bar.a == 2)
assert(bar.b == 3)
assert(bar.c == 4)
})
})
})
})
1 change: 1 addition & 0 deletions test/specs/index.js
@@ -0,0 +1 @@
module.exports = [require('./core')]
4 changes: 4 additions & 0 deletions test/tap.js
@@ -0,0 +1,4 @@
var brofist = require('brofist')
var reporter = require('brofist-tap')

brofist.run(require('./specs'), reporter())

0 comments on commit ce2e089

Please sign in to comment.