Skip to content
Snippets Groups Projects
Commit dda7622d authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

port coarse UA parser tests to vows

parent ef7818e6
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ const fs = require('fs'), ...@@ -8,6 +8,7 @@ const fs = require('fs'),
// TODO: convert to vows based test (or introduce nodeunit dependency) // TODO: convert to vows based test (or introduce nodeunit dependency)
vows = require('vows'), vows = require('vows'),
coarse = require('../lib/coarse_user_agent_parser'), coarse = require('../lib/coarse_user_agent_parser'),
assert = require('assert'),
path = require('path'); path = require('path');
var suite = vows.describe('coarse-user-agent-parser'); var suite = vows.describe('coarse-user-agent-parser');
...@@ -17,26 +18,33 @@ suite.options.error = false; ...@@ -17,26 +18,33 @@ suite.options.error = false;
/* Update test data with https://gist.github.com/2590547 */ /* Update test data with https://gist.github.com/2590547 */
fs.readFile(path.join(__dirname, 'data/user_agents.json'), 'utf-8', function (err, data) { suite.addBatch({
if (err) { "UA parsing": {
console.error(err); topic: function() {
} else { fs.readFile(path.join(__dirname, 'data/user_agents.json'), 'utf-8', this.callback);
var test_data = JSON.parse(data); },
for (var i=0; i < test_data.tests.length; i++) { "data can be read": function(err, data) {
var t = test_data.tests[i]; assert.isNull(err);
if (t.ua) { },
var actual = coarse.parse(t.ua); "with lots of data": {
if (actual.os != t.os) { topic: function(err, data) {
console.error('Error parsing ' + t.ua + ' expected [' + t.os + '] got [' + actual.os + ']'); this.callback(JSON.parse(data));
} },
if (actual.browser != t.browser) { "demonstrates proper functioning of coarse parser": function(test_data) {
console.error('Error parsing ' + t.ua + ' expected [' + t.browser + '] got [' + actual.browser + ']'); for (var i=0; i < test_data.tests.length; i++) {
} var t = test_data.tests[i];
if (actual.version != t.version) { if (t.ua) {
console.error('Error parsing ' + t.ua + ' expected [' + t.version + '] got [' + actual.version + ']'); var actual = coarse.parse(t.ua);
assert.strictEqual(t.os, actual.os, t.ua);
assert.strictEqual(t.browser, actual.browser, t.ua);
assert.strictEqual(t.version, actual.version, t.ua);
}
} }
} }
} }
console.log('Finished ' + test_data.tests.length);
} }
}); });
\ No newline at end of file
// run or export the suite.
if (process.argv[1] === __filename) suite.run();
else suite.export(module);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment