From c6dbf0450566c40efc4a26f4f0717452b6ef95cd Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 10 Aug 2022 10:38:44 +0200 Subject: Initial commit --- node_modules/ua-parser/js/test/device.js | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 node_modules/ua-parser/js/test/device.js (limited to 'node_modules/ua-parser/js/test/device.js') diff --git a/node_modules/ua-parser/js/test/device.js b/node_modules/ua-parser/js/test/device.js new file mode 100644 index 0000000..752c7a4 --- /dev/null +++ b/node_modules/ua-parser/js/test/device.js @@ -0,0 +1,59 @@ +var assert = require('assert'), + Device = require('../lib/device').Device, + makeParser = require('../lib/device').makeParser; + +suite('Device object', function() { + test('Device constructor with no arguments', function() { + var device = new Device(); + assert.strictEqual(device.family, 'Other'); + assert.strictEqual(device.toString(), 'Other'); + }); + + test('Device constructor with valid arguments', function() { + var device = new Device('Foo'); + assert.strictEqual(device.family, 'Foo'); + assert.strictEqual(device.toString(), 'Foo'); + }); +}); + +suite('Device parser', function() { + test('makeParser returns a function', function() { + assert.equal(typeof makeParser([]), 'function'); + }); + + test('Unexpected args don\'t throw', function() { + var parse = makeParser([]); + assert.doesNotThrow(function() { parse('Foo'); }); + assert.doesNotThrow(function() { parse(''); }); + assert.doesNotThrow(function() { parse(); }); + assert.doesNotThrow(function() { parse(null); }); + assert.doesNotThrow(function() { parse({}); }); + assert.doesNotThrow(function() { parse(123); }); + }); + + test('Parser returns an instance of Device when unsuccessful at parsing', function() { + var parse = makeParser([{regex: 'foo'}]); + assert.ok(parse('bar') instanceof Device); + }); + + test('Parser returns an instance of Device when sucessful', function() { + var parse = makeParser([{regex: 'foo'}]); + assert.ok(parse('foo') instanceof Device); + }); + + test('Parser correctly identifies Device name', function() { + var parse = makeParser([{regex: '(foo)'}]); + assert.strictEqual(parse('foo').family, 'foo'); + }); + + test('Parser correctly processes replacements', function() { + var parse = makeParser([{ + regex: '(foo)', + device_replacement: '$1bar' + }]); + + var device = parse('foo'); + assert.strictEqual(device.family, 'foobar'); + }); +}); + -- cgit