diff --git a/.circleci/config.yml b/.circleci/config.yml index 363f33a..2a3a349 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,36 +1,15 @@ -version: 2 +version: 2.1 + jobs: - build: - docker: - - image: circleci/node:latest - steps: - - checkout - - run: - name: Update npm - command: 'sudo npm install -g npm@latest' - - restore_cache: - key: dependency-cache-{{ checksum "package.json" }} - - run: - name: Install npm wee - command: npm install - - save_cache: - key: dependency-cache-{{ checksum "package.json" }} - paths: - - node_modules - test: + build_and_test: docker: - - image: circleci/node:latest + - image: cimg/node:current steps: - checkout - - run: - name: Test - command: npm test + - run: npm install + - run: npm test workflows: - version: 2 build_and_test: jobs: - - build - - test: - requires: - - build + - build_and_test diff --git a/.gitignore b/.gitignore index 9daa824..ac9d097 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store +dist node_modules diff --git a/esm/jquery-param.es.js b/esm/jquery-param.es.js deleted file mode 100644 index 598c9bb..0000000 --- a/esm/jquery-param.es.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @preserve jquery-param (c) KNOWLEDGECODE | MIT - */ - -/** - * serialize any object - * @param {Object} a - any object to serialize - * @returns {string} a serialized string - */ -var param = function (a) { - var s = []; - var add = function (k, v) { - v = typeof v === 'function' ? v() : v; - v = v === null ? '' : v === undefined ? '' : v; - s[s.length] = encodeURIComponent(k) + '=' + encodeURIComponent(v); - }; - var buildParams = function (prefix, obj) { - var i, len, key; - - if (prefix) { - if (Array.isArray(obj)) { - for (i = 0, len = obj.length; i < len; i++) { - buildParams( - prefix + '[' + (typeof obj[i] === 'object' && obj[i] ? i : '') + ']', - obj[i] - ); - } - } else if (Object.prototype.toString.call(obj) === '[object Object]') { - for (key in obj) { - buildParams(prefix + '[' + key + ']', obj[key]); - } - } else { - add(prefix, obj); - } - } else if (Array.isArray(obj)) { - for (i = 0, len = obj.length; i < len; i++) { - add(obj[i].name, obj[i].value); - } - } else { - for (key in obj) { - buildParams(key, obj[key]); - } - } - return s; - }; - - return buildParams('', a).join('&'); -}; - -export default param; diff --git a/esm/jquery-param.es.min.js b/esm/jquery-param.es.min.js deleted file mode 100644 index 0d62023..0000000 --- a/esm/jquery-param.es.min.js +++ /dev/null @@ -1,5 +0,0 @@ -/* - jquery-param (c) KNOWLEDGECODE | MIT -*/ -export default function(h){function d(c,a){var e;if(c)if(Array.isArray(a)){var b=0;for(e=a.length;b - - - - - - Mocha Tests - - -
- - - - - - - - - diff --git a/test/test.js b/test/test.js deleted file mode 100644 index b8b7c59..0000000 --- a/test/test.js +++ /dev/null @@ -1,864 +0,0 @@ -(function (global) { - 'use strict'; - - describe('equivalence', function () { - var $, - expect = global.expect || require('expect.js'), - param = global.param || require('../jquery-param'), - test = function (done, obj) { - try { - expect(decodeURIComponent(param(obj))).to.eql(decodeURIComponent($.param(obj))); - done(); - } catch (e) { - done(e); - } - }; - - before(function (done) { - if (global.jQuery) { - $ = global.jQuery; - } else { - var _window = (new (require('jsdom').JSDOM)()).window; - $ = require('jquery')(_window); - _window.close(); - } - done(); - }); - - it('ascii', function (done) { - var obj = { - foo: 'bar' - }; - test(done, obj); - }); - - it('non-ascii', function (done) { - var obj = { - foo: 'こんにちは' - }; - test(done, obj); - }); - - it('number', function (done) { - var obj = { - foo: 12345 - }; - test(done, obj); - }); - - it('boolean', function (done) { - var obj = { - foo: true - }; - test(done, obj); - }); - - // Array #1 (ascii) - it('Array #1', function (done) { - var obj = { - foo: ['hello', 'world', '!'] - }; - test(done, obj); - }); - // Array #2 (non-ascii) - it('Array #2', function (done) { - var obj = { - foo: ['こんにちは', '世界', '!'] - }; - test(done, obj); - }); - // Array #3 (number) - it('Array #3', function (done) { - var obj = { - foo: [0, 1, 2] - }; - test(done, obj); - }); - // Array #4 (boolean) - it('Array #4', function (done) { - var obj = { - foo: [true, false, true] - }; - test(done, obj); - }); - // Array #5 (Array) - it('Array #5', function (done) { - var obj = { - 'foo': ['[]', '[]', '[]'] - }; - test(done, obj); - }); - // Array #6 (Object) - it('Array #6', function (done) { - var obj = { - foo: [{}, {}, {}] - }; - test(done, obj); - }); - // Array #7 (Date) - it('Array #7', function (done) { - var obj = { - foo: [new Date(), new Date(), new Date()] - }; - test(done, obj); - }); - // Array #8 (Error) - it('Array #8', function (done) { - var obj = { - foo: [new Error(), new Error(), new Error()] - }; - test(done, obj); - }); - // Array #9 (Function) - it('Array #9', function (done) { - var obj = { - foo: [new Function(), new Function(), new Function()] // eslint-disable-line no-new-func - }; - test(done, obj); - }); - // Array #10 (RegExp) - it('Array #10', function (done) { - var obj = { - foo: [/[[]]/, /[[]]/, /[[]]/] - }; - test(done, obj); - }); - // Array #11 (function) - it('Array #11', function (done) { - var obj = { - foo: [function () {}, function () {}, function () {}] - }; - test(done, obj); - }); - // Array #12 (null) - it('Array #12', function (done) { - var obj = { - foo: [null, null, null] - }; - test(done, obj); - }); - // Array #13 (undefined) - it('Array #13', function (done) { - var obj = { - foo: [undefined, undefined, undefined] - }; - test(done, obj); - }); - // Array #14 (NaN) - it('Array #14', function (done) { - var obj = { - foo: [NaN, NaN, NaN] - }; - test(done, obj); - }); - - // Object #1 (ascii) - it('Object #1', function (done) { - var obj = { - foo: { bar: 'hello' } - }; - test(done, obj); - }); - // Object #2 (non-ascii) - it('Object #2', function (done) { - var obj = { - foo: { bar: 'こんにちは' } - }; - test(done, obj); - }); - // Object #3 (number) - it('Object #3', function (done) { - var obj = { - foo: { bar: 3.14 } - }; - test(done, obj); - }); - // Object #4 (boolean) - it('Object #4', function (done) { - var obj = { - foo: { bar: false } - }; - test(done, obj); - }); - // Object #5 (Array) - it('Object #5', function (done) { - var obj = { - foo: { bar: [1, 2, 3] } - }; - test(done, obj); - }); - // Object #6 (Object) - it('Object #6', function (done) { - var obj = { - foo: { bar: {} } - }; - test(done, obj); - }); - // Object #7 (Date) - it('Object #7', function (done) { - var obj = { - foo: { bar: new Date() } - }; - test(done, obj); - }); - // Object #8 (Error) - it('Object #8', function (done) { - var obj = { - foo: { bar: new Error() } - }; - test(done, obj); - }); - // Object #9 (Function) - it('Object #9', function (done) { - var obj = { - foo: { bar: new Function() } // eslint-disable-line no-new-func - }; - test(done, obj); - }); - // Object #10 (RegExp) - it('Object #10', function (done) { - var obj = { - foo: { bar: /[[]]/ } - }; - test(done, obj); - }); - // Object #11 (function) - it('Object #11', function (done) { - var obj = { - foo: { bar: function () {} } - }; - test(done, obj); - }); - // Object #12 (null) - it('Object #12', function (done) { - var obj = { - foo: { bar: null } - }; - test(done, obj); - }); - // Object #13 (undefined) - it('Object #13', function (done) { - var obj = { - foo: { bar: undefined } - }; - test(done, obj); - }); - // Object #14 (NaN) - it('Object #14', function (done) { - var obj = { - foo: { bar: NaN } - }; - test(done, obj); - }); - - it('String', function (done) { - var obj = { - foo: new String() // eslint-disable-line no-new-wrappers - }; - test(done, obj); - }); - - it('Number', function (done) { - var obj = { - foo: new Number() // eslint-disable-line no-new-wrappers - }; - test(done, obj); - }); - - it('Boolean', function (done) { - var obj = { - foo: new Boolean() // eslint-disable-line no-new-wrappers - }; - test(done, obj); - }); - - it('Date', function (done) { - var obj = { - foo: new Date() - }; - test(done, obj); - }); - - it('Error', function (done) { - var obj = { - foo: new Error() - }; - test(done, obj); - }); - - it('Function', function (done) { - var obj = { - foo: new Function() // eslint-disable-line no-new-func - }; - test(done, obj); - }); - - it('RegExp', function (done) { - var obj = { - foo: /[[]]/ - }; - test(done, obj); - }); - - it('null', function (done) { - var obj = { - foo: null - }; - test(done, obj); - }); - - it('undefined', function (done) { - var obj = { - foo: undefined - }; - test(done, obj); - }); - - it('NaN', function (done) { - var obj = { - foo: NaN - }; - test(done, obj); - }); - - // function #1 (ascii) - it('function #1', function (done) { - var obj = { - foo: function () { - return 'hello'; - } - }; - test(done, obj); - }); - // function #2 (non-ascii) - it('function #2', function (done) { - var obj = { - foo: function () { - return 'こんにちは'; - } - }; - test(done, obj); - }); - // function #3 (number) - it('function #3', function (done) { - var obj = { - foo: function () { - return 0; - } - }; - test(done, obj); - }); - // function #4 (boolean) - it('function #4', function (done) { - var obj = { - foo: function () { - return false; - } - }; - test(done, obj); - }); - // function #5 (Array) - it('function #5', function (done) { - var obj = { - foo: function () { - return []; - } - }; - test(done, obj); - }); - // function #6 (Object) - it('function #6', function (done) { - var obj = { - foo: function () { - return {}; - } - }; - test(done, obj); - }); - // function #7 (Date) - it('function #7', function (done) { - var obj = { - foo: function () { - return new Date(); - } - }; - test(done, obj); - }); - // function #8 (Error) - it('function #8', function (done) { - var obj = { - foo: function () { - return new Error(); - } - }; - test(done, obj); - }); - // function #9 (Function) - it('function #9', function (done) { - var obj = { - foo: function () { - return new Function(); // eslint-disable-line no-new-func - } - }; - test(done, obj); - }); - // function #10 (RegExp) - it('function #9', function (done) { - var obj = { - foo: function () { - return /[[]]/; - } - }; - test(done, obj); - }); - // function #11 (function) - it('function #11', function (done) { - var obj = { - foo: function () { - return function () { - return undefined; - }; - } - }; - test(done, obj); - }); - // function #12 (null) - it('function #12', function (done) { - var obj = { - foo: function () { - return null; - } - }; - test(done, obj); - }); - // function #13 (undefined) - it('function #13', function (done) { - var obj = { - foo: function () { - return undefined; - } - }; - test(done, obj); - }); - // function #14 (NaN) - it('function #14', function (done) { - var obj = { - foo: function () { - return NaN; - } - }; - test(done, obj); - }); - - // Array in Array #1 (ascii) - it('Array in Array #1', function (done) { - var obj = { - foo: [ - ['hello', 'world', '!'], - ['hello', 'world', '!'], - ['hello', 'world', '!'] - ] - }; - test(done, obj); - }); - // Array in Array #2 (non-ascii) - it('Array in Array #2', function (done) { - var obj = { - foo: [ - ['こんにちは', '世界', '!'], - ['こんにちは', '世界', '!'], - ['こんにちは', '世界', '!'] - ] - }; - test(done, obj); - }); - // Array in Array #3 (number) - it('Array in Array #3', function (done) { - var obj = { - foo: [ - [-1, 0, 1], - [-1, 0, 1], - [-1, 0, 1] - ] - }; - test(done, obj); - }); - // Array in Array #4 (boolean) - it('Array in Array #4', function (done) { - var obj = { - foo: [ - [true, false, true], - [true, false, true], - [true, false, true] - ] - }; - test(done, obj); - }); - // Array in Array #5 (Array) - it('Array in Array #5', function (done) { - var obj = { - foo: [ - [[], [], []], - [[], [], []], - [[], [], []] - ] - }; - test(done, obj); - }); - // Array in Array #6 (Object) - it('Array in Array #6', function (done) { - var obj = { - foo: [ - [{}, {}, {}], - [{}, {}, {}], - [{}, {}, {}] - ] - }; - test(done, obj); - }); - // Array in Array #7 (Date) - it('Array in Array #7', function (done) { - var obj = { - foo: [ - [new Date(), new Date(), new Date()], - [new Date(), new Date(), new Date()], - [new Date(), new Date(), new Date()] - ] - }; - test(done, obj); - }); - // Array in Array #8 (Error) - it('Array in Array #8', function (done) { - var obj = { - foo: [ - [new Error(), new Error(), new Error()], - [new Error(), new Error(), new Error()], - [new Error(), new Error(), new Error()] - ] - }; - test(done, obj); - }); - // Array in Array #9 (Function) - it('Array in Array #9', function (done) { - var obj = { - foo: [ - [new Function(), new Function(), new Function()], // eslint-disable-line no-new-func - [new Function(), new Function(), new Function()], // eslint-disable-line no-new-func - [new Function(), new Function(), new Function()] // eslint-disable-line no-new-func - ] - }; - test(done, obj); - }); - // Array in Array #10 (RegExp) - it('Array in Array #10', function (done) { - var obj = { - foo: [ - [/[[]]/, /[[]]/, /[[]]/], - [/[[]]/, /[[]]/, /[[]]/], - [/[[]]/, /[[]]/, /[[]]/] - ] - }; - test(done, obj); - }); - // Array in Array #11 (function) - it('Array in Array #11', function (done) { - var obj = { - foo: [ - [function () {}, function () {}, function () {}], - [function () {}, function () {}, function () {}], - [function () {}, function () {}, function () {}] - ] - }; - test(done, obj); - }); - // Array in Array #12 (null) - it('Array in Array #12', function (done) { - var obj = { - foo: [ - [null, null, null], - [null, null, null], - [null, null, null] - ] - }; - test(done, obj); - }); - // Array in Array #13 (undefined) - it('Array in Array #13', function (done) { - var obj = { - foo: [ - [undefined, undefined, undefined], - [undefined, undefined, undefined], - [undefined, undefined, undefined] - ] - }; - test(done, obj); - }); - // Array in Array #14 (NaN) - it('Array in Array #14', function (done) { - var obj = { - foo: [ - [NaN, NaN, NaN], - [NaN, NaN, NaN], - [NaN, NaN, NaN] - ] - }; - test(done, obj); - }); - - // Object in Object #1 (ascii) - it('Object in Object #1', function (done) { - var obj = { - foo: { - 'hello': 'hello', - 'world': 'world', - '!': '!' - } - }; - test(done, obj); - }); - // Object in Object #2 (non-ascii) - it('Object in Object #2', function (done) { - var obj = { - foo: { - 'こんにちは': 'こんにちは', - '世界': '世界', - '!': '!' - } - }; - test(done, obj); - }); - // Object in Object #3 (number) - it('Object in Object #3', function (done) { - var obj = { - foo: { - '-1': -1, - '0': 0, - '1': 1 - } - }; - test(done, obj); - }); - // Object in Object #4 (boolean) - it('Object in Object #4', function (done) { - var obj = { - foo: { - 'true': true, - 'false': false - } - }; - test(done, obj); - }); - // Object in Object #5 (Array) - it('Object in Object #5', function (done) { - var obj = { - foo: { - '[]': [], - '[[]]': [[]], - '[[[]]]': [[[]]] - } - }; - test(done, obj); - }); - // Object in Object #6 (Object) - it('Object in Object #6', function (done) { - var obj = { - foo: { - '{}': {}, - '{{}}': { '{}': {} }, - '{{{}}}': { '{}': { '{}': {} } } - } - }; - test(done, obj); - }); - // Object in Object #7 (Date) - it('Object in Object #7', function (done) { - var obj = { - foo: { - 'date1': new Date(), - 'date2': new Date(), - 'date3': new Date() - } - }; - test(done, obj); - }); - // Object in Object #8 (Error) - it('Object in Object #8', function (done) { - var obj = { - foo: { - 'error1': new Error(), - 'error2': new Error(), - 'error3': new Error() - } - }; - test(done, obj); - }); - // Object in Object #9 (Function) - it('Object in Object #9', function (done) { - var obj = { - foo: { - 'Function1': new Function(), // eslint-disable-line no-new-func - 'Function2': new Function(), // eslint-disable-line no-new-func - 'Function3': new Function() // eslint-disable-line no-new-func - } - }; - test(done, obj); - }); - // Object in Object #10 (RegExp) - it('Object in Object #10', function (done) { - var obj = { - foo: { - '/[[]]/': /[[]]/, - '/[[[]]]/': /[[[]]]/, - '/[[[[]]]]/': /[[[[]]]]/ - } - }; - test(done, obj); - }); - // Object in Object #11 (function) - it('Object in Object #11', function (done) { - var obj = { - foo: { - 'function1': function () {}, - 'function2': function () {}, - 'function3': function () {} - } - }; - test(done, obj); - }); - // Object in Object #12 (null) - it('Object in Object #12', function (done) { - var obj = { - foo: { - 'null1': null, - 'null2': null, - 'null3': null - } - }; - test(done, obj); - }); - // Object in Object #13 (undefined) - it('Object in Object #13', function (done) { - var obj = { - foo: { - 'undefined1': undefined, - 'undefined2': undefined, - 'undefined3': undefined - } - }; - test(done, obj); - }); - // Object in Object #14 (NaN) - it('Object in Object #14', function (done) { - var obj = { - foo: { - 'NaN1': NaN, - 'NaN2': NaN, - 'NaN3': NaN - } - }; - test(done, obj); - }); - - it('Extended Object', function (done) { - var P = function () {}; - var obj = Object.create(P.prototype); - - P.prototype.foo = function () { return [1, 2, 3]; }; - obj.bar = { 'undefined': 'null' }; - test(done, obj); - }); - - it('Mixed Array #1', function (done) { - var obj = { - foo: [undefined, null, NaN, new Date(), / /], - bar: { - 1: undefined, - 2: null, - 3: NaN, - 4: new Date(), - 5: / / - } - }; - test(done, obj); - }); - it('Mixed Array #2', function (done) { - var obj = [ - { name: 'foo', value: 'bar' }, - { name: 'foo', value: 'bar' }, - { name: 'name', value: 'value' }, - { name: null, value: null }, - { name: undefined, value: undefined }, - { foo: 'name', bar: 'value' }, - { foo: null, bar: null }, - { foo: undefined, bar: undefined }, - { foo: '', bar: '' }, - { foo: 0, bar: 0 }, - { foo: NaN, bar: NaN } - ]; - test(done, obj); - }); - - it('empty', function (done) { - var obj = ''; - test(done, obj); - }); - - it('zero', function (done) { - var obj = 0; - test(done, obj); - }); - - it('false', function (done) { - var obj = false; - test(done, obj); - }); - - it('Date only', function (done) { - var obj = new Date(); - test(done, obj); - }); - - it('String only', function (done) { - var obj = new String(); // eslint-disable-line no-new-wrappers - test(done, obj); - }); - - it('Number only', function (done) { - var obj = new Number(); // eslint-disable-line no-new-wrappers - test(done, obj); - }); - - it('Boolean only', function (done) { - var obj = new Boolean(); // eslint-disable-line no-new-wrappers - test(done, obj); - }); - - it('Error only', function (done) { - var obj = new Error(); - test(done, obj); - }); - - it('Function only', function (done) { - var obj = new Function(); // eslint-disable-line no-new-func - test(done, obj); - }); - - it('RegExp only', function (done) { - var obj = /[[]]/; - test(done, obj); - }); - - it('NaN only', function (done) { - var obj = NaN; - test(done, obj); - }); - - it('null Prototype', function (done) { - var obj = Object.create(null); - obj.test = Object.create(null); - obj.test.test = 1; - test(done, obj); - }); - }); - -}(this)); diff --git a/test/test.mjs b/test/test.mjs new file mode 100644 index 0000000..b080ead --- /dev/null +++ b/test/test.mjs @@ -0,0 +1,846 @@ +import { expect } from 'chai'; +import { JSDOM } from 'jsdom'; +import jquery from 'jquery'; +import param from '../dist/esm/jquery-param.mjs'; + +describe('equivalence', function () { + var $ = jquery(new JSDOM().window), + test = function (obj) { + expect(decodeURIComponent(param(obj))).to.equal(decodeURIComponent($.param(obj))); + }; + + it('ascii', function () { + var obj = { + foo: 'bar' + }; + test(obj); + }); + + it('non-ascii', function () { + var obj = { + foo: 'こんにちは' + }; + test(obj); + }); + + it('number', function () { + var obj = { + foo: 12345 + }; + test(obj); + }); + + it('boolean', function () { + var obj = { + foo: true + }; + test(obj); + }); + + // Array #1 (ascii) + it('Array #1', function () { + var obj = { + foo: ['hello', 'world', '!'] + }; + test(obj); + }); + // Array #2 (non-ascii) + it('Array #2', function () { + var obj = { + foo: ['こんにちは', '世界', '!'] + }; + test(obj); + }); + // Array #3 (number) + it('Array #3', function () { + var obj = { + foo: [0, 1, 2] + }; + test(obj); + }); + // Array #4 (boolean) + it('Array #4', function () { + var obj = { + foo: [true, false, true] + }; + test(obj); + }); + // Array #5 (Array) + it('Array #5', function () { + var obj = { + 'foo': ['[]', '[]', '[]'] + }; + test(obj); + }); + // Array #6 (Object) + it('Array #6', function () { + var obj = { + foo: [{}, {}, {}] + }; + test(obj); + }); + // Array #7 (Date) + it('Array #7', function () { + var obj = { + foo: [new Date(), new Date(), new Date()] + }; + test(obj); + }); + // Array #8 (Error) + it('Array #8', function () { + var obj = { + foo: [new Error(), new Error(), new Error()] + }; + test(obj); + }); + // Array #9 (Function) + it('Array #9', function () { + var obj = { + foo: [new Function(), new Function(), new Function()] // eslint-disable-line no-new-func + }; + test(obj); + }); + // Array #10 (RegExp) + it('Array #10', function () { + var obj = { + foo: [/[[]]/, /[[]]/, /[[]]/] + }; + test(obj); + }); + // Array #11 (function) + it('Array #11', function () { + var obj = { + foo: [function () {}, function () {}, function () {}] + }; + test(obj); + }); + // Array #12 (null) + it('Array #12', function () { + var obj = { + foo: [null, null, null] + }; + test(obj); + }); + // Array #13 (undefined) + it('Array #13', function () { + var obj = { + foo: [undefined, undefined, undefined] + }; + test(obj); + }); + // Array #14 (NaN) + it('Array #14', function () { + var obj = { + foo: [NaN, NaN, NaN] + }; + test(obj); + }); + + // Object #1 (ascii) + it('Object #1', function () { + var obj = { + foo: { bar: 'hello' } + }; + test(obj); + }); + // Object #2 (non-ascii) + it('Object #2', function () { + var obj = { + foo: { bar: 'こんにちは' } + }; + test(obj); + }); + // Object #3 (number) + it('Object #3', function () { + var obj = { + foo: { bar: 3.14 } + }; + test(obj); + }); + // Object #4 (boolean) + it('Object #4', function () { + var obj = { + foo: { bar: false } + }; + test(obj); + }); + // Object #5 (Array) + it('Object #5', function () { + var obj = { + foo: { bar: [1, 2, 3] } + }; + test(obj); + }); + // Object #6 (Object) + it('Object #6', function () { + var obj = { + foo: { bar: {} } + }; + test(obj); + }); + // Object #7 (Date) + it('Object #7', function () { + var obj = { + foo: { bar: new Date() } + }; + test(obj); + }); + // Object #8 (Error) + it('Object #8', function () { + var obj = { + foo: { bar: new Error() } + }; + test(obj); + }); + // Object #9 (Function) + it('Object #9', function () { + var obj = { + foo: { bar: new Function() } // eslint-disable-line no-new-func + }; + test(obj); + }); + // Object #10 (RegExp) + it('Object #10', function () { + var obj = { + foo: { bar: /[[]]/ } + }; + test(obj); + }); + // Object #11 (function) + it('Object #11', function () { + var obj = { + foo: { bar: function () {} } + }; + test(obj); + }); + // Object #12 (null) + it('Object #12', function () { + var obj = { + foo: { bar: null } + }; + test(obj); + }); + // Object #13 (undefined) + it('Object #13', function () { + var obj = { + foo: { bar: undefined } + }; + test(obj); + }); + // Object #14 (NaN) + it('Object #14', function () { + var obj = { + foo: { bar: NaN } + }; + test(obj); + }); + + it('String', function () { + var obj = { + foo: new String() // eslint-disable-line no-new-wrappers + }; + test(obj); + }); + + it('Number', function () { + var obj = { + foo: new Number() // eslint-disable-line no-new-wrappers + }; + test(obj); + }); + + it('Boolean', function () { + var obj = { + foo: new Boolean() // eslint-disable-line no-new-wrappers + }; + test(obj); + }); + + it('Date', function () { + var obj = { + foo: new Date() + }; + test(obj); + }); + + it('Error', function () { + var obj = { + foo: new Error() + }; + test(obj); + }); + + it('Function', function () { + var obj = { + foo: new Function() // eslint-disable-line no-new-func + }; + test(obj); + }); + + it('RegExp', function () { + var obj = { + foo: /[[]]/ + }; + test(obj); + }); + + it('null', function () { + var obj = { + foo: null + }; + test(obj); + }); + + it('undefined', function () { + var obj = { + foo: undefined + }; + test(obj); + }); + + it('NaN', function () { + var obj = { + foo: NaN + }; + test(obj); + }); + + // function #1 (ascii) + it('function #1', function () { + var obj = { + foo: function () { + return 'hello'; + } + }; + test(obj); + }); + // function #2 (non-ascii) + it('function #2', function () { + var obj = { + foo: function () { + return 'こんにちは'; + } + }; + test(obj); + }); + // function #3 (number) + it('function #3', function () { + var obj = { + foo: function () { + return 0; + } + }; + test(obj); + }); + // function #4 (boolean) + it('function #4', function () { + var obj = { + foo: function () { + return false; + } + }; + test(obj); + }); + // function #5 (Array) + it('function #5', function () { + var obj = { + foo: function () { + return []; + } + }; + test(obj); + }); + // function #6 (Object) + it('function #6', function () { + var obj = { + foo: function () { + return {}; + } + }; + test(obj); + }); + // function #7 (Date) + it('function #7', function () { + var obj = { + foo: function () { + return new Date(); + } + }; + test(obj); + }); + // function #8 (Error) + it('function #8', function () { + var obj = { + foo: function () { + return new Error(); + } + }; + test(obj); + }); + // function #9 (Function) + it('function #9', function () { + var obj = { + foo: function () { + return new Function(); // eslint-disable-line no-new-func + } + }; + test(obj); + }); + // function #10 (RegExp) + it('function #9', function () { + var obj = { + foo: function () { + return /[[]]/; + } + }; + test(obj); + }); + // function #11 (function) + it('function #11', function () { + var obj = { + foo: function () { + return function () { + return undefined; + }; + } + }; + test(obj); + }); + // function #12 (null) + it('function #12', function () { + var obj = { + foo: function () { + return null; + } + }; + test(obj); + }); + // function #13 (undefined) + it('function #13', function () { + var obj = { + foo: function () { + return undefined; + } + }; + test(obj); + }); + // function #14 (NaN) + it('function #14', function () { + var obj = { + foo: function () { + return NaN; + } + }; + test(obj); + }); + + // Array in Array #1 (ascii) + it('Array in Array #1', function () { + var obj = { + foo: [ + ['hello', 'world', '!'], + ['hello', 'world', '!'], + ['hello', 'world', '!'] + ] + }; + test(obj); + }); + // Array in Array #2 (non-ascii) + it('Array in Array #2', function () { + var obj = { + foo: [ + ['こんにちは', '世界', '!'], + ['こんにちは', '世界', '!'], + ['こんにちは', '世界', '!'] + ] + }; + test(obj); + }); + // Array in Array #3 (number) + it('Array in Array #3', function () { + var obj = { + foo: [ + [-1, 0, 1], + [-1, 0, 1], + [-1, 0, 1] + ] + }; + test(obj); + }); + // Array in Array #4 (boolean) + it('Array in Array #4', function () { + var obj = { + foo: [ + [true, false, true], + [true, false, true], + [true, false, true] + ] + }; + test(obj); + }); + // Array in Array #5 (Array) + it('Array in Array #5', function () { + var obj = { + foo: [ + [[], [], []], + [[], [], []], + [[], [], []] + ] + }; + test(obj); + }); + // Array in Array #6 (Object) + it('Array in Array #6', function () { + var obj = { + foo: [ + [{}, {}, {}], + [{}, {}, {}], + [{}, {}, {}] + ] + }; + test(obj); + }); + // Array in Array #7 (Date) + it('Array in Array #7', function () { + var obj = { + foo: [ + [new Date(), new Date(), new Date()], + [new Date(), new Date(), new Date()], + [new Date(), new Date(), new Date()] + ] + }; + test(obj); + }); + // Array in Array #8 (Error) + it('Array in Array #8', function () { + var obj = { + foo: [ + [new Error(), new Error(), new Error()], + [new Error(), new Error(), new Error()], + [new Error(), new Error(), new Error()] + ] + }; + test(obj); + }); + // Array in Array #9 (Function) + it('Array in Array #9', function () { + var obj = { + foo: [ + [new Function(), new Function(), new Function()], // eslint-disable-line no-new-func + [new Function(), new Function(), new Function()], // eslint-disable-line no-new-func + [new Function(), new Function(), new Function()] // eslint-disable-line no-new-func + ] + }; + test(obj); + }); + // Array in Array #10 (RegExp) + it('Array in Array #10', function () { + var obj = { + foo: [ + [/[[]]/, /[[]]/, /[[]]/], + [/[[]]/, /[[]]/, /[[]]/], + [/[[]]/, /[[]]/, /[[]]/] + ] + }; + test(obj); + }); + // Array in Array #11 (function) + it('Array in Array #11', function () { + var obj = { + foo: [ + [function () {}, function () {}, function () {}], + [function () {}, function () {}, function () {}], + [function () {}, function () {}, function () {}] + ] + }; + test(obj); + }); + // Array in Array #12 (null) + it('Array in Array #12', function () { + var obj = { + foo: [ + [null, null, null], + [null, null, null], + [null, null, null] + ] + }; + test(obj); + }); + // Array in Array #13 (undefined) + it('Array in Array #13', function () { + var obj = { + foo: [ + [undefined, undefined, undefined], + [undefined, undefined, undefined], + [undefined, undefined, undefined] + ] + }; + test(obj); + }); + // Array in Array #14 (NaN) + it('Array in Array #14', function () { + var obj = { + foo: [ + [NaN, NaN, NaN], + [NaN, NaN, NaN], + [NaN, NaN, NaN] + ] + }; + test(obj); + }); + + // Object in Object #1 (ascii) + it('Object in Object #1', function () { + var obj = { + foo: { + 'hello': 'hello', + 'world': 'world', + '!': '!' + } + }; + test(obj); + }); + // Object in Object #2 (non-ascii) + it('Object in Object #2', function () { + var obj = { + foo: { + 'こんにちは': 'こんにちは', + '世界': '世界', + '!': '!' + } + }; + test(obj); + }); + // Object in Object #3 (number) + it('Object in Object #3', function () { + var obj = { + foo: { + '-1': -1, + '0': 0, + '1': 1 + } + }; + test(obj); + }); + // Object in Object #4 (boolean) + it('Object in Object #4', function () { + var obj = { + foo: { + 'true': true, + 'false': false + } + }; + test(obj); + }); + // Object in Object #5 (Array) + it('Object in Object #5', function () { + var obj = { + foo: { + '[]': [], + '[[]]': [[]], + '[[[]]]': [[[]]] + } + }; + test(obj); + }); + // Object in Object #6 (Object) + it('Object in Object #6', function () { + var obj = { + foo: { + '{}': {}, + '{{}}': { '{}': {} }, + '{{{}}}': { '{}': { '{}': {} } } + } + }; + test(obj); + }); + // Object in Object #7 (Date) + it('Object in Object #7', function () { + var obj = { + foo: { + 'date1': new Date(), + 'date2': new Date(), + 'date3': new Date() + } + }; + test(obj); + }); + // Object in Object #8 (Error) + it('Object in Object #8', function () { + var obj = { + foo: { + 'error1': new Error(), + 'error2': new Error(), + 'error3': new Error() + } + }; + test(obj); + }); + // Object in Object #9 (Function) + it('Object in Object #9', function () { + var obj = { + foo: { + 'Function1': new Function(), // eslint-disable-line no-new-func + 'Function2': new Function(), // eslint-disable-line no-new-func + 'Function3': new Function() // eslint-disable-line no-new-func + } + }; + test(obj); + }); + // Object in Object #10 (RegExp) + it('Object in Object #10', function () { + var obj = { + foo: { + '/[[]]/': /[[]]/, + '/[[[]]]/': /[[[]]]/, + '/[[[[]]]]/': /[[[[]]]]/ + } + }; + test(obj); + }); + // Object in Object #11 (function) + it('Object in Object #11', function () { + var obj = { + foo: { + 'function1': function () {}, + 'function2': function () {}, + 'function3': function () {} + } + }; + test(obj); + }); + // Object in Object #12 (null) + it('Object in Object #12', function () { + var obj = { + foo: { + 'null1': null, + 'null2': null, + 'null3': null + } + }; + test(obj); + }); + // Object in Object #13 (undefined) + it('Object in Object #13', function () { + var obj = { + foo: { + 'undefined1': undefined, + 'undefined2': undefined, + 'undefined3': undefined + } + }; + test(obj); + }); + // Object in Object #14 (NaN) + it('Object in Object #14', function () { + var obj = { + foo: { + 'NaN1': NaN, + 'NaN2': NaN, + 'NaN3': NaN + } + }; + test(obj); + }); + + it('Extended Object', function () { + var P = function () {}; + var obj = Object.create(P.prototype); + + P.prototype.foo = function () { return [1, 2, 3]; }; + obj.bar = { 'undefined': 'null' }; + test(obj); + }); + + it('Mixed Array #1', function () { + var obj = { + foo: [undefined, null, NaN, new Date(), / /], + bar: { + 1: undefined, + 2: null, + 3: NaN, + 4: new Date(), + 5: / / + } + }; + test(obj); + }); + it('Mixed Array #2', function () { + var obj = [ + { name: 'foo', value: 'bar' }, + { name: 'foo', value: 'bar' }, + { name: 'name', value: 'value' }, + { name: null, value: null }, + { name: undefined, value: undefined }, + { foo: 'name', bar: 'value' }, + { foo: null, bar: null }, + { foo: undefined, bar: undefined }, + { foo: '', bar: '' }, + { foo: 0, bar: 0 }, + { foo: NaN, bar: NaN } + ]; + test(obj); + }); + + it('empty', function () { + var obj = ''; + test(obj); + }); + + it('zero', function () { + var obj = 0; + test(obj); + }); + + it('false', function () { + var obj = false; + test(obj); + }); + + it('Date only', function () { + var obj = new Date(); + test(obj); + }); + + it('String only', function () { + var obj = new String(); // eslint-disable-line no-new-wrappers + test(obj); + }); + + it('Number only', function () { + var obj = new Number(); // eslint-disable-line no-new-wrappers + test(obj); + }); + + it('Boolean only', function () { + var obj = new Boolean(); // eslint-disable-line no-new-wrappers + test(obj); + }); + + it('Error only', function () { + var obj = new Error(); + test(obj); + }); + + it('Function only', function () { + var obj = new Function(); // eslint-disable-line no-new-func + test(obj); + }); + + it('RegExp only', function () { + var obj = /[[]]/; + test(obj); + }); + + it('NaN only', function () { + var obj = NaN; + test(obj); + }); + + it('null Prototype', function () { + var obj = Object.create(null); + obj.test = Object.create(null); + obj.test.test = 1; + test(obj); + }); +});