(function () { var data = { a: { a: ['aa1', 'aa2', 'aa3'], b: { a: 'aba', b: 'abb' }, a3: 'a31, a32, a33', a4: 1234 }, b: ['b1', 'b2', 'b3'], c: 'c1, c2, c3', d: 123 }; var arr = ['a', 'b', 'c']; var obj = {a: 0, b: 1, c: 2}; module('qs.js', undefined); test('qs.call', function () { var _scopeCallback = function (value) { return (undefined === value) ? null : value; }; window._testData = { callback: function (value) { return (undefined === value) ? null : value; }, testContext: {name: 'testContext'}, contextCheck: function () { var args = Array.prototype.slice.call(arguments); args.push(this.name); return args.join(', '); } }; strictEqual(qs.call(_scopeCallback), null, 'scope function callback'); strictEqual(qs.call(_testData.callback), null, 'global function callback'); strictEqual(qs.call('_testData.callback'), null, 'global string callback 1'); strictEqual(qs.call('window._testData.callback'), null, 'global string callback 2'); strictEqual(qs.call({fn: '_testData.callback', args: ['param']}), 'param', 'global object callback with args'); strictEqual( qs.call({fn: _testData.contextCheck, args: ['param1', 'param2'], context: _testData.testContext}), 'param1, param2, testContext', 'global object callback with context' ); deepEqual( qs.call([_scopeCallback, {fn: '_testData.callback', args: ['bar']}]), [null, 'bar'], 'list of callbacks' ); }); module('underscore.extended.js', undefined); test('_.getType()', function () { strictEqual(_.getType(null), 'null', 'getType(null)'); strictEqual(_.getType(undefined), 'undefined', 'getType(undefined)'); strictEqual(_.getType('abc'), 'String', 'getType String 1'); strictEqual(_.getType(123), 'Number', 'getType Number'); strictEqual(_.getType([]), 'Array', 'getType Array'); strictEqual(_.getType({}), 'Object', 'getType Object'); strictEqual(_.getType(/foo/gim), 'RegExp', 'getType RegExp'); strictEqual(_.getType(new Date()), 'Date', 'getType Date'); strictEqual(_.getType('abc', true), 'string', 'getType loweCase = true'); }); test('_.obj', function () { strictEqual(_.obj.get(data, 'd'), 123, 'get number'); strictEqual(_.obj.get(data, 'a.b.a'), 'aba', 'get complex name 1'); strictEqual(_.obj.get(data, 'a.a.1'), 'aa2', 'get complex name 2'); strictEqual(_.obj.get(data, 'x.not.existing', 'default'), 'default', 'get default value'); strictEqual(_.obj.get(data, 'x.not.existing'), undefined, 'get not existing key'); }); test('_.str', function () { strictEqual(_.str.trim(' x '), 'x', 'trim'); strictEqual(_.str.trimLeft(' x '), 'x ', 'trimLeft'); strictEqual(_.str.trimRight(' x '), ' x', 'trimRight'); strictEqual(_.str.trim('-^$.+8?|()[]{}x-^$.+8?|()[]{}', '-^$.+8?|()[]{}'), 'x', 'trim custom chars'); strictEqual(_.str.capitalize('oneTwoTHREE'), 'OneTwoTHREE', 'capitalize'); strictEqual(_.str.camelize('-one_two three.FOUR'), 'OneTwoThree.FOUR', 'camelize'); strictEqual(_.str.repeat('x', 3, '-'), 'x-x-x', 'repeat'); strictEqual(_.str.tpl('a: {a}, b: {b}', {a: 'first', b: 'second'}), 'a: first, b: second', 'tpl'); strictEqual(_.str.plural('word', 0), 'words', 'plural 0'); strictEqual(_.str.plural('word', 1), 'word', 'plural 1'); strictEqual(_.str.plural('word', 2), 'words', 'plural 2'); strictEqual(_.str.plural(['child', 'children'], 1), 'child', 'plural array 1'); strictEqual(_.str.plural(['child', 'children'], 2), 'children', 'plural array 2'); }); test('_.num', function () { strictEqual(_.num.format('123'), '123', 'format (defaults)'); strictEqual(_.num.format(123, 2), '123.00', 'format (decimals)'); strictEqual(_.num.format(123456.789, 2, ',', ' '), '123 456,79', 'format (custom)'); }); })();