]> git.cworth.org Git - obsolete/notmuch-web/blob - node_modules/express/node_modules/qs/support/should/examples/runner.js
Install the "express" node module via npm
[obsolete/notmuch-web] / node_modules / express / node_modules / qs / support / should / examples / runner.js
1
2 /**
3  * Module dependencies.
4  */
5
6 var should = require('../');
7
8 function test(name, fn){
9   try {
10     fn();
11   } catch (err) {
12     console.log('    \x1b[31m%s', name);
13     console.log('    %s\x1b[0m', err.stack);
14     return;
15   }
16   console.log('  √ \x1b[32m%s\x1b[0m', name);
17 }
18
19 function Point(x, y) {
20   this.x = x;
21   this.y = y;
22   this.sub = function(other){
23     return new Point(
24         this.x - other.x
25       , this.y - other.y);
26   }
27 }
28
29 console.log();
30
31 test('new Point(x, y)', function(){
32   var point = new Point(50, 100);
33   point.should.be.an.instanceof(Point);
34   point.should.have.property('x', 50);
35   point.should.have.property('y', 100);
36 });
37
38 test('Point#sub()', function(){
39   var a = new Point(50, 100)
40     , b = new Point(20, 50);
41   a.sub(b).should.be.an.instanceof(Point);
42   a.sub(b).should.not.equal(a);
43   a.sub(b).should.not.equal(b);
44   a.sub(b).should.have.property('x', 30);
45   a.sub(b).should.have.property('y', 50);
46 });
47
48 test('Point#add()', function(){
49   var point = new Point(50, 100);
50   point.should.respondTo('add');
51 });
52
53 console.log();