diff options
Diffstat (limited to 'node_modules/ua-parser/js')
-rw-r--r-- | node_modules/ua-parser/js/LICENSE | 41 | ||||
-rw-r--r-- | node_modules/ua-parser/js/index.js | 32 | ||||
-rw-r--r-- | node_modules/ua-parser/js/lib/device.js | 41 | ||||
-rw-r--r-- | node_modules/ua-parser/js/lib/helpers.js | 6 | ||||
-rw-r--r-- | node_modules/ua-parser/js/lib/os.js | 78 | ||||
-rw-r--r-- | node_modules/ua-parser/js/lib/results.js | 47 | ||||
-rw-r--r-- | node_modules/ua-parser/js/lib/ua.js | 53 | ||||
-rw-r--r-- | node_modules/ua-parser/js/test/device.js | 59 | ||||
-rw-r--r-- | node_modules/ua-parser/js/test/helpers.js | 12 | ||||
-rw-r--r-- | node_modules/ua-parser/js/test/old-api.js | 25 | ||||
-rw-r--r-- | node_modules/ua-parser/js/test/os.js | 103 | ||||
-rw-r--r-- | node_modules/ua-parser/js/test/parse.js | 16 | ||||
-rw-r--r-- | node_modules/ua-parser/js/test/ua.js | 94 | ||||
-rw-r--r-- | node_modules/ua-parser/js/test/with_fixtures.js | 73 |
14 files changed, 680 insertions, 0 deletions
diff --git a/node_modules/ua-parser/js/LICENSE b/node_modules/ua-parser/js/LICENSE new file mode 100644 index 0000000..51905d7 --- /dev/null +++ b/node_modules/ua-parser/js/LICENSE @@ -0,0 +1,41 @@ +Your choice of license: MIT or Apache, Version 2.0. + +MIT License +=========== + +Copyright (c) 2010 Tobie Langel (http://tobielangel.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +Apache License, Version 2.0 +=========================== + +Copyright 2010 Tobie Langel + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.
\ No newline at end of file diff --git a/node_modules/ua-parser/js/index.js b/node_modules/ua-parser/js/index.js new file mode 100644 index 0000000..e1890fe --- /dev/null +++ b/node_modules/ua-parser/js/index.js @@ -0,0 +1,32 @@ +var path = require('path'), + fs = require('fs'), + yaml = require('yamlparser'), + Results = require('./lib/results').BackwardsCompatResults; + +var file = path.join(__dirname, '..', 'regexes.yaml'), + regexes = fs.readFileSync(file, 'utf8'); + +regexes = yaml.eval(regexes); + +var parseUA = require('./lib/ua').makeParser(regexes.user_agent_parsers); +exports.parseUA = parseUA; + +var parseOS = require('./lib/os').makeParser(regexes.os_parsers); +exports.parseOS = parseOS; + +var parseDevice = require('./lib/device').makeParser(regexes.device_parsers); +exports.parseDevice = parseDevice; + +exports.parse = parse; +function parse(str) { + var ua = parseUA(str), + os = parseOS(str), + device = parseDevice(str); + return new Results(str, ua, os, device); +} + +if (require.main === module) { + var output, input = process.argv[2]; + if (!input) { process.exit(1); } + process.stdout.write(parseUA(input).toString()); +} diff --git a/node_modules/ua-parser/js/lib/device.js b/node_modules/ua-parser/js/lib/device.js new file mode 100644 index 0000000..374e971 --- /dev/null +++ b/node_modules/ua-parser/js/lib/device.js @@ -0,0 +1,41 @@ +exports.Device = Device +function Device(family) { + this.family = family || 'Other'; +} + +Device.prototype.toString = function() { + return this.family; +}; + + +exports.makeParser = function(regexes) { + var parsers = regexes.map(function (obj) { + var regexp = new RegExp(obj.regex), + deviceRep = obj.device_replacement; + + function parser(str) { + var m = str.match(regexp); + if (!m) { return null; } + + var family = deviceRep ? deviceRep.replace('$1', m[1]) : m[1]; + return new Device(family); + } + + return parser; + }); + + function parser(str, ua_family, os_family) { + var obj; + + if (typeof str === 'string') { + for (var i = 0, length = parsers.length; i < length; i++) { + obj = parsers[i](str, ua_family, os_family); + if (obj) { return obj; } + } + } + + return obj || new Device(); + } + + return parser; +}; diff --git a/node_modules/ua-parser/js/lib/helpers.js b/node_modules/ua-parser/js/lib/helpers.js new file mode 100644 index 0000000..19f305d --- /dev/null +++ b/node_modules/ua-parser/js/lib/helpers.js @@ -0,0 +1,6 @@ +var DIGITS = /^\d/; + +exports.startsWithDigit = startsWithDigit; +function startsWithDigit(str) { + return DIGITS.test(str); +}
\ No newline at end of file diff --git a/node_modules/ua-parser/js/lib/os.js b/node_modules/ua-parser/js/lib/os.js new file mode 100644 index 0000000..f54b99a --- /dev/null +++ b/node_modules/ua-parser/js/lib/os.js @@ -0,0 +1,78 @@ +var startsWithDigit = require('./helpers').startsWithDigit; + +exports.OS = OS +function OS(family, major, minor, patch, patchMinor) { + this.family = family || 'Other'; + this.major = major || null; + this.minor = minor || null; + this.patch = patch || null; + this.patchMinor = patchMinor || null; +} + +OS.prototype.toVersionString = function() { + var output = ''; + if (this.major != null) { + output += this.major; + if (this.minor != null) { + output += '.' + this.minor; + if (this.patch != null) { + if (startsWithDigit(this.patch)) { output += '.'; } + output += this.patch; + if (this.patchMinor != null) { + if (startsWithDigit(this.patchMinor)) { output += '.'; } + output += this.patchMinor; + } + } + } + } + return output; +}; + +OS.prototype.toString = function() { + var suffix = this.toVersionString(); + if (suffix) { suffix = ' ' + suffix; } + return this.family + suffix; +}; + +function _makeParsers(obj) { + var regexp = new RegExp(obj.regex), + famRep = obj.os_replacement, + majorRep = obj.os_v1_replacement, + minorRep = obj.os_v2_replacement, + patchRep = obj.os_v3_replacement, + patchMinorRep = obj.os_v4_replacement; + + function parser(str) { + var m = str.match(regexp); + if (!m) { return null; } + + var family = famRep ? famRep.replace('$1', m[1]) : m[1], + major = majorRep || m[2], + minor = minorRep || m[3], + patch = patchRep || m[4], + patchMinor = patchMinorRep || m[5]; + + return new OS(family, major, minor, patch, patchMinor); + } + + return parser; +} + +exports.makeParser = function(regexes) { + var parsers = regexes.map(_makeParsers) + + function parser(str) { + var obj; + + if (typeof str === 'string') { + for (var i = 0, length = parsers.length; i < length; i++) { + obj = parsers[i](str); + if (obj) { return obj; } + } + } + + return obj || new OS(); + } + + return parser; +}
\ No newline at end of file diff --git a/node_modules/ua-parser/js/lib/results.js b/node_modules/ua-parser/js/lib/results.js new file mode 100644 index 0000000..0b30cd0 --- /dev/null +++ b/node_modules/ua-parser/js/lib/results.js @@ -0,0 +1,47 @@ +var UNDEF = void 0; + +exports.BackwardsCompatResults = BackwardsCompatResults; +function BackwardsCompatResults(ua_str, ua, os, device) { + this.string = ua_str; + this.userAgent = this.ua = ua; + this.os = os; + this.device = device + + // Backwards compat + var major = ua.major, + minor = ua.minor, + patch = ua.patch; + + this.family = ua.family; + this.major = major === null ? UNDEF : parseInt(major); + this.minor = minor === null ? UNDEF : parseInt(minor); + this.patch = patch === null ? UNDEF : parseInt(patch); +} + +// Backwards compat +BackwardsCompatResults.prototype.toVersionString = function() { + var output = '', + ua = this.ua; + if (ua.major != null) { + output += ua.major; + if (ua.minor != null) { + output += '.' + ua.minor; + if (ua.patch != null) { + output += '.' + ua.patch; + } + } + } + return output; +}; + +// Backwards compat +BackwardsCompatResults.prototype.toString = function() { + var suffix = this.toVersionString(); + if (suffix) { suffix = ' ' + suffix; } + return this.ua.family + suffix; +}; + +// Backwards compat +BackwardsCompatResults.prototype.toFullString = function() { + return this.toString() + (this.os ? '/' + this.os : ''); +}; diff --git a/node_modules/ua-parser/js/lib/ua.js b/node_modules/ua-parser/js/lib/ua.js new file mode 100644 index 0000000..d8876d6 --- /dev/null +++ b/node_modules/ua-parser/js/lib/ua.js @@ -0,0 +1,53 @@ +var startsWithDigit = require('./helpers').startsWithDigit, + OS = require('./os').OS; + +exports.UA = UA +function UA(family, major, minor, patch) { + this.family = family || 'Other'; + this.major = major || null; + this.minor = minor || null; + this.patch = patch || null; +} + +require('util').inherits(UA, OS) + +function _makeParsers(obj) { + var regexp = new RegExp(obj.regex), + famRep = obj.family_replacement, + majorRep = obj.v1_replacement, + minorRep = obj.v2_replacement, + patchRep = obj.v3_replacement; + + function parser(str) { + var m = str.match(regexp); + if (!m) { return null; } + + var family = famRep ? famRep.replace('$1', m[1]) : m[1], + major = majorRep || m[2], + minor = minorRep || m[3], + patch = patchRep || m[4]; + + return new UA(family, major, minor, patch); + } + + return parser; +} + +exports.makeParser = function(regexes) { + var parsers = regexes.map(_makeParsers) + + function parser(str) { + var obj; + + if (typeof str === 'string') { + for (var i = 0, length = parsers.length; i < length; i++) { + obj = parsers[i](str); + if (obj) { return obj; } + } + } + + return obj || new UA(); + } + + return parser; +}
\ No newline at end of file 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; +} |