summaryrefslogtreecommitdiff
path: root/node_modules/ua-parser/js/test
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/ua-parser/js/test')
-rw-r--r--node_modules/ua-parser/js/test/device.js59
-rw-r--r--node_modules/ua-parser/js/test/helpers.js12
-rw-r--r--node_modules/ua-parser/js/test/old-api.js25
-rw-r--r--node_modules/ua-parser/js/test/os.js103
-rw-r--r--node_modules/ua-parser/js/test/parse.js16
-rw-r--r--node_modules/ua-parser/js/test/ua.js94
-rw-r--r--node_modules/ua-parser/js/test/with_fixtures.js73
7 files changed, 382 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');
+ });
+});
+
diff --git a/node_modules/ua-parser/js/test/helpers.js b/node_modules/ua-parser/js/test/helpers.js
new file mode 100644
index 0000000..4d9204e
--- /dev/null
+++ b/node_modules/ua-parser/js/test/helpers.js
@@ -0,0 +1,12 @@
+var assert = require('assert'),
+ helpers = require('../lib/helpers');
+
+suite('Helpers', function() {
+ test('startsWithDigit', function() {
+ assert.ok(helpers.startsWithDigit('0'));
+ assert.ok(helpers.startsWithDigit('1'));
+ assert.ok(helpers.startsWithDigit('0a'));
+ assert.ok(!helpers.startsWithDigit('a'));
+ });
+});
+
diff --git a/node_modules/ua-parser/js/test/old-api.js b/node_modules/ua-parser/js/test/old-api.js
new file mode 100644
index 0000000..7b9b6e2
--- /dev/null
+++ b/node_modules/ua-parser/js/test/old-api.js
@@ -0,0 +1,25 @@
+// Documenting current behaviour for backwards compat reqs.
+
+var assert = require('assert'),
+ parse = require('../index').parse;
+
+var USER_AGENT_STRING = 'Mozilla/5.0 (Windows NT 6.1; rv:2.0b6pre) Gecko/20100903 Firefox/4.0b6pre Firefox/4.0b6pre';
+
+suite('parse function', function() {
+ test('output with valid UA string', function() {
+ var output = parse(USER_AGENT_STRING);
+ assert.strictEqual(output.family, 'Firefox Beta');
+ assert.strictEqual(output.major, 4);
+ assert.strictEqual(output.minor, 0);
+ assert.ok(isNaN(output.patch));
+ });
+
+ test('output with invalid UA string', function() {
+ var output = parse('');
+ assert.strictEqual(output.family, 'Other');
+ assert.strictEqual(output.major, undefined);
+ assert.strictEqual(output.minor, undefined);
+ assert.strictEqual(output.patch, undefined);
+ });
+});
+
diff --git a/node_modules/ua-parser/js/test/os.js b/node_modules/ua-parser/js/test/os.js
new file mode 100644
index 0000000..ad3e4b0
--- /dev/null
+++ b/node_modules/ua-parser/js/test/os.js
@@ -0,0 +1,103 @@
+var assert = require('assert'),
+ OS = require('../lib/os').OS,
+ makeParser = require('../lib/os').makeParser;
+
+suite('os object', function() {
+ test('OS constructor with no arguments', function() {
+ var os = new OS();
+ assert.strictEqual(os.family, 'Other');
+ assert.strictEqual(os.major, null);
+ assert.strictEqual(os.minor, null);
+ assert.strictEqual(os.patch, null);
+ assert.strictEqual(os.patchMinor, null);
+ });
+
+ test('OS constructor with valid arguments', function() {
+ var os = new OS('Bar', '4', '3', '2', '1');
+ assert.strictEqual(os.family, 'Bar');
+ assert.strictEqual(os.major, '4');
+ assert.strictEqual(os.minor, '3');
+ assert.strictEqual(os.patch, '2');
+ assert.strictEqual(os.patchMinor, '1');
+ });
+
+ test('OS#toVersionString with only numerical args', function() {
+ assert.strictEqual(new OS('Bar', '4', '3', '2', '1').toVersionString(), '4.3.2.1');
+ assert.strictEqual(new OS('Bar', '4', '3', '2').toVersionString(), '4.3.2');
+ assert.strictEqual(new OS('Bar', '4', '3').toVersionString(), '4.3');
+ assert.strictEqual(new OS('Bar', '4').toVersionString(), '4');
+ assert.strictEqual(new OS('Bar').toVersionString(), '');
+ });
+
+ test('OS#toVersionString with non numerical args', function() {
+ assert.strictEqual(new OS('Bar', '4', '3', '2', 'beta').toVersionString(), '4.3.2beta');
+ assert.strictEqual(new OS('Bar', '4', '3', 'beta').toVersionString(), '4.3beta');
+ });
+
+ test('OS#toString for known OS', function() {
+ assert.strictEqual(new OS('Bar', '4', '3', '2', '1').toString(), 'Bar 4.3.2.1');
+ });
+
+ test('OS#toString for unknown OS', function() {
+ assert.strictEqual(new OS().toString(), 'Other');
+ });
+});
+
+suite('OS 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 OS when unsuccessful at parsing', function() {
+ var parse = makeParser([]);
+ assert.ok(parse('foo') instanceof OS);
+ });
+
+ test('Parser returns an instance of OS when sucessful', function() {
+ var parse = makeParser([{regex: 'foo'}]);
+ assert.ok(parse('foo') instanceof OS);
+ });
+
+ test('Parser correctly identifies OS name', function() {
+ var parse = makeParser([{regex: '(foo)'}]);
+ assert.strictEqual(parse('foo').family, 'foo');
+ });
+
+ test('Parser correctly identifies version numbers', function() {
+ var parse = makeParser([{regex: '(foo) (\\d)\\.(\\d).(\\d)\\.(\\d)'}]),
+ os = parse('foo 1.2.3.4');
+ assert.strictEqual(os.family, 'foo');
+ assert.strictEqual(os.major, '1');
+ assert.strictEqual(os.minor, '2');
+ assert.strictEqual(os.patch, '3');
+ assert.strictEqual(os.patchMinor, '4');
+ });
+
+ test('Parser correctly processes replacements', function() {
+ var parse = makeParser([{
+ regex: '(foo) (\\d)\\.(\\d)\\.(\\d)\\.(\\d)',
+ os_replacement: '$1bar',
+ os_v1_replacement: 'a',
+ os_v2_replacement: 'b',
+ os_v3_replacement: 'c',
+ os_v4_replacement: 'd'
+ }]);
+
+ var os = parse('foo 1.2.3.4');
+ assert.strictEqual(os.family, 'foobar');
+ assert.strictEqual(os.major, 'a');
+ assert.strictEqual(os.minor, 'b');
+ assert.strictEqual(os.patch, 'c');
+ });
+});
+
diff --git a/node_modules/ua-parser/js/test/parse.js b/node_modules/ua-parser/js/test/parse.js
new file mode 100644
index 0000000..5feaae5
--- /dev/null
+++ b/node_modules/ua-parser/js/test/parse.js
@@ -0,0 +1,16 @@
+var assert = require('assert'),
+ parse = require('../index').parse;
+
+var USER_AGENT_STRING = 'Mozilla/5.0 (Windows NT 6.1; rv:2.0b6pre) Gecko/20100903 Firefox/4.0b6pre Firefox/4.0b6pre';
+
+suite('parse function', function() {
+ test('Unexpected args don\'t throw', function() {
+ assert.doesNotThrow(function() { parse(USER_AGENT_STRING); });
+ assert.doesNotThrow(function() { parse(''); });
+ assert.doesNotThrow(function() { parse(); });
+ assert.doesNotThrow(function() { parse(null); });
+ assert.doesNotThrow(function() { parse({}); });
+ assert.doesNotThrow(function() { parse(123); });
+ });
+});
+
diff --git a/node_modules/ua-parser/js/test/ua.js b/node_modules/ua-parser/js/test/ua.js
new file mode 100644
index 0000000..5b1c378
--- /dev/null
+++ b/node_modules/ua-parser/js/test/ua.js
@@ -0,0 +1,94 @@
+var assert = require('assert'),
+ UA = require('../lib/ua').UA,
+ makeParser = require('../lib/ua').makeParser;
+
+suite('UA object', function() {
+ test('UA constructor with no arguments', function() {
+ var ua = new UA();
+ assert.strictEqual(ua.family, 'Other');
+ assert.strictEqual(ua.major, null);
+ assert.strictEqual(ua.minor, null);
+ assert.strictEqual(ua.patch, null);
+ });
+
+ test('UA constructor with valid arguments', function() {
+ var ua = new UA('Firefox', '16', '3', 'beta');
+ assert.strictEqual(ua.family, 'Firefox');
+ assert.strictEqual(ua.major, '16');
+ assert.strictEqual(ua.minor, '3');
+ assert.strictEqual(ua.patch, 'beta');
+ });
+
+ test('UA#toVersionString with only numerical args', function() {
+ assert.strictEqual(new UA('Firefox', '16', '3', '2').toVersionString(), '16.3.2');
+ });
+
+ test('UA#toVersionString with non numerical patch version', function() {
+ assert.strictEqual(new UA('Firefox', '16', '3', 'beta').toVersionString(), '16.3beta');
+ });
+
+ test('UA#toString for known UA', function() {
+ assert.strictEqual(new UA('Firefox', '16', '3', '2').toString(), 'Firefox 16.3.2');
+ });
+
+ test('UA#toString for unknown UA', function() {
+ assert.strictEqual(new UA().toString(), 'Other');
+ });
+});
+
+
+suite('UA 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 UA when unsuccessful at parsing', function() {
+ assert.ok(makeParser([])('bar') instanceof UA);
+ });
+
+ test('Parser returns an instance of UA when sucessful', function() {
+ var parse = makeParser([{regex: 'foo'}]);
+ assert.ok(parse('foo') instanceof UA);
+ });
+
+ test('Parser correctly identifies UA name', function() {
+ var parse = makeParser([{regex: '(foo)'}]);
+ assert.strictEqual(parse('foo').family, 'foo');
+ });
+
+ test('Parser correctly identifies version numbers', function() {
+ var parse = makeParser([{regex: '(foo) (\\d)\\.(\\d)\\.(\\d)'}]),
+ ua = parse('foo 1.2.3');
+ assert.strictEqual(ua.family, 'foo');
+ assert.strictEqual(ua.major, '1');
+ assert.strictEqual(ua.minor, '2');
+ assert.strictEqual(ua.patch, '3');
+ });
+
+ test('Parser correctly processes replacements', function() {
+ var parse = makeParser([{
+ regex: '(foo) (\\d)\\.(\\d).(\\d)',
+ family_replacement: '$1bar',
+ v1_replacement: 'a',
+ v2_replacement: 'b',
+ v3_replacement: 'c'
+ }]);
+
+ var ua = parse('foo 1.2.3');
+ assert.strictEqual(ua.family, 'foobar');
+ assert.strictEqual(ua.major, 'a');
+ assert.strictEqual(ua.minor, 'b');
+ assert.strictEqual(ua.patch, 'c');
+ });
+});
+
diff --git a/node_modules/ua-parser/js/test/with_fixtures.js b/node_modules/ua-parser/js/test/with_fixtures.js
new file mode 100644
index 0000000..c632bc9
--- /dev/null
+++ b/node_modules/ua-parser/js/test/with_fixtures.js
@@ -0,0 +1,73 @@
+var assert = require('assert'),
+ path = require('path'),
+ fs = require('fs'),
+ yaml = require('yamlparser'),
+ uaParser = require('../index');
+
+function readYAML(fileName) {
+ var file = path.join(__dirname, '..', '..', 'test_resources', fileName);
+ var fixtures = fs.readFileSync(file, 'utf8');
+ fixtures = yaml.eval(fixtures);
+ return fixtures;
+}
+
+function msg(name, actual, expected) {
+ return "Expected " + name + " to be " + JSON.stringify(expected) + " got " + JSON.stringify(actual) + " instead.";
+}
+
+['firefox_user_agent_strings.yaml', 'test_user_agent_parser.yaml', 'pgts_browser_list.yaml'].forEach(function(fileName) {
+ var fixtures = readYAML(fileName).test_cases;
+ suite(fileName, function() {
+ fixtures.forEach(function(f) {
+ if (f.js_ua) return;
+ test(f.user_agent_string, function() {
+ var ua = uaParser.parse(f.user_agent_string).userAgent;
+ fixFixture(f, ['major', 'minor', 'patch']);
+ assert.strictEqual(ua.family, f.family, msg('ua.family', ua.family, f.family));
+ assert.strictEqual(ua.major, f.major, msg('ua.major', ua.major, f.major));
+ assert.strictEqual(ua.minor, f.minor, msg('ua.minor', ua.minor, f.minor));
+ assert.strictEqual(ua.patch, f.patch, msg('ua.patch', ua.patch, f.patch));
+ });
+ });
+ });
+});
+
+['test_user_agent_parser_os.yaml', 'additional_os_tests.yaml'].forEach(function(fileName) {
+ var fixtures = readYAML(fileName).test_cases;
+ suite(fileName, function() {
+ fixtures.forEach(function(f) {
+ test(f.user_agent_string, function() {
+ var os = uaParser.parse(f.user_agent_string).os;
+ fixFixture(f, ['major', 'minor', 'patch', 'patch_minor']);
+ assert.strictEqual(os.family, f.family, msg('os.family', os.family, f.family));
+ assert.strictEqual(os.major, f.major, msg('os.major', os.major, f.major));
+ assert.strictEqual(os.minor, f.minor, msg('os.minor', os.minor, f.minor));
+ assert.strictEqual(os.patch, f.patch, msg('os.patch', os.patch, f.patch));
+ assert.strictEqual(os.patchMinor, f.patch_minor, msg('os.patchMinor', os.patchMinor, f.patch_minor));
+ });
+ });
+ });
+});
+
+['test_device.yaml'].forEach(function(fileName) {
+ var fixtures = readYAML(fileName).test_cases;
+ suite(fileName, function() {
+ fixtures.forEach(function(f) {
+ test(f.user_agent_string, function() {
+ var device = uaParser.parse(f.user_agent_string).device;
+ assert.strictEqual(device.family, f.family, msg('device.family', device.family, f.family));
+ });
+ });
+ });
+});
+
+function fixFixture(f, props) {
+ // A bug in the YAML parser makes empty fixture props
+ // return a vanila object.
+ props.forEach(function(p) {
+ if (typeof f[p] === 'object') {
+ f[p] = null;
+ }
+ })
+ return f;
+}