diff options
author | Minteck <contact@minteck.org> | 2022-08-10 10:38:44 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-08-10 10:38:44 +0200 |
commit | c6dbf0450566c40efc4a26f4f0717452b6ef95cd (patch) | |
tree | b4be2d508223820d0a77d5a3e35e82684da3b6ec /node_modules/ua-parser/js/test/device.js | |
download | hornchat-mane.tar.gz hornchat-mane.tar.bz2 hornchat-mane.zip |
Diffstat (limited to 'node_modules/ua-parser/js/test/device.js')
-rw-r--r-- | node_modules/ua-parser/js/test/device.js | 59 |
1 files changed, 59 insertions, 0 deletions
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'); + }); +}); + |