Skip to content

Commit

Permalink
move to mocha for tests and update them
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Apr 12, 2012
1 parent 81ca3b5 commit 66487d4
Show file tree
Hide file tree
Showing 20 changed files with 914 additions and 937 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -30,15 +30,15 @@ uninstall:
@node-waf uninstall @node-waf uninstall


test-tmp: test-tmp:
@rm -rf tests/tmp @rm -rf test/tmp
@mkdir -p tests/tmp @mkdir -p test/tmp


ifndef only ifndef only
test: test-tmp test: test-tmp
@PATH=./node_modules/expresso/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH expresso @PATH=./node_modules/mocha/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH mocha -R spec
else else
test: test-tmp test: test-tmp
@PATH=./node_modules/expresso/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH expresso test/${only}.test.js @PATH=./node_modules/mocha/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH mocha -R spec test/${only}.test.js
endif endif


fix: fix:
Expand Down
76 changes: 47 additions & 29 deletions test/color.test.js
@@ -1,36 +1,54 @@
var mapnik = require('mapnik'); var mapnik = require('mapnik');
var assert = require('assert');


exports['test color creation'] = function(beforeExit, assert) { describe('mapnik.Color', function() {
// no 'new' keyword it('should throw with invalid usage', function() {
assert.throws(function() { mapnik.Color(); }); // no 'new' keyword
assert.throws(function() { mapnik.Color(); });
// invalid args
assert.throws(function() { new mapnik.Color(); });
assert.throws(function() { new mapnik.Color(1); });
assert.throws(function() { new mapnik.Color('foo'); });
});


// invalid args it('should be green via keyword', function() {
assert.throws(function() { new mapnik.Color(); }); var c = new mapnik.Color('green');
assert.throws(function() { new mapnik.Color(1); }); assert.equal(c.r, 0);
assert.throws(function() { new mapnik.Color('foo'); }); assert.equal(c.g, 128);
assert.equal(c.b, 0);
assert.equal(c.a, 255);
assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');
});


var c = new mapnik.Color('green');
assert.equal(c.r, 0);
assert.equal(c.g, 128);
assert.equal(c.b, 0);
assert.equal(c.a, 255);
assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');


c = new mapnik.Color(0, 128, 0); it('should be gray via rgb', function() {
assert.equal(c.r, 0); var c = new mapnik.Color(0, 128, 0);
assert.equal(c.g, 128); assert.equal(c.r, 0);
assert.equal(c.b, 0); assert.equal(c.g, 128);
assert.equal(c.a, 255); assert.equal(c.b, 0);
assert.equal(c.hex(), '#008000'); assert.equal(c.a, 255);
assert.equal(c.toString(), 'rgb(0,128,0)'); assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');
});


c = new mapnik.Color(0, 128, 0, 255); it('should be gray via rgba', function() {
assert.equal(c.r, 0); var c = new mapnik.Color(0, 128, 0, 255);
assert.equal(c.g, 128); assert.equal(c.r, 0);
assert.equal(c.b, 0); assert.equal(c.g, 128);
assert.equal(c.a, 255); assert.equal(c.b, 0);
assert.equal(c.hex(), '#008000'); assert.equal(c.a, 255);
assert.equal(c.toString(), 'rgb(0,128,0)'); assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');
});


}; it('should be gray via rgba %', function() {
var c = new mapnik.Color('rgba(0%,50%,0%,1)');
assert.equal(c.r, 0);
assert.equal(c.g, 128);
assert.equal(c.b, 0);
assert.equal(c.a, 255);
assert.equal(c.hex(), '#008000');
assert.equal(c.toString(), 'rgb(0,128,0)');
});
});
81 changes: 54 additions & 27 deletions test/constants.test.js
@@ -1,30 +1,57 @@
var mapnik = require('mapnik'); var mapnik = require('mapnik');
var assert = require('assert');
var fs = require('fs'); var fs = require('fs');


exports['test constants'] = function(beforeExit, assert) { describe('mapnik constants', function() {
assert.ok(mapnik.settings); it('should have valid settings', function() {
assert.ok(mapnik.settings.paths); assert.ok(mapnik.settings);
assert.ok(mapnik.settings.paths.fonts.length); assert.ok(mapnik.settings.paths);
assert.ok(fs.statSync(mapnik.settings.paths.fonts)); assert.ok(mapnik.settings.paths.fonts.length);
assert.ok(mapnik.settings.paths.input_plugins.length); assert.ok(fs.statSync(mapnik.settings.paths.fonts));
assert.ok(fs.statSync(mapnik.settings.paths.input_plugins)); assert.ok(mapnik.settings.paths.input_plugins.length);

assert.ok(fs.statSync(mapnik.settings.paths.input_plugins));
// reloading the default plugins path should return false as no more plugins are registered
assert.ok(!mapnik.register_datasources(mapnik.settings.paths.input_plugins)); // reloading the default plugins path should return false as no more plugins are registered

assert.ok(!mapnik.register_datasources(mapnik.settings.paths.input_plugins));
/* has version info */
assert.ok(mapnik.versions); /* has version info */
assert.ok(mapnik.versions.node); assert.ok(mapnik.versions);
assert.ok(mapnik.versions.v8); assert.ok(mapnik.versions.node);
assert.ok(mapnik.versions.mapnik); assert.ok(mapnik.versions.v8);
assert.ok(mapnik.versions.mapnik_number); assert.ok(mapnik.versions.mapnik);
assert.ok(mapnik.versions.boost); assert.ok(mapnik.versions.mapnik_number);
assert.ok(mapnik.versions.boost_number); assert.ok(mapnik.versions.boost);

assert.ok(mapnik.versions.boost_number);
assert.ok(mapnik.Geometry.Point,1);
assert.ok(mapnik.Geometry.LineString,2); assert.ok(mapnik.Geometry.Point, 1);
assert.ok(mapnik.Geometry.Polygon,3); assert.ok(mapnik.Geometry.LineString, 2);

assert.ok(mapnik.Geometry.Polygon, 3);
// make sure we have some
assert.ok(mapnik.datasources().length > 0); // make sure we have some
}; assert.ok(mapnik.datasources().length > 0);
});

it('should have valid version info', function() {
/* has version info */
assert.ok(mapnik.versions);
assert.ok(mapnik.versions.node);
assert.ok(mapnik.versions.v8);
assert.ok(mapnik.versions.mapnik);
assert.ok(mapnik.versions.mapnik_number);
assert.ok(mapnik.versions.boost);
assert.ok(mapnik.versions.boost_number);

assert.ok(mapnik.Geometry.Point, 1);
assert.ok(mapnik.Geometry.LineString, 2);
assert.ok(mapnik.Geometry.Polygon, 3);

// make sure we have some
assert.ok(mapnik.datasources().length > 0);
});

it('should expose Geometry enums', function() {
assert.ok(mapnik.Geometry.Point, 1);
assert.ok(mapnik.Geometry.LineString, 2);
assert.ok(mapnik.Geometry.Polygon, 3);
});
});

0 comments on commit 66487d4

Please sign in to comment.