+/* eslint-disable capitalized-comments */
+/* eslint-env mocha */
+'use strict';
+
+
+const assert = require('assert');
+const qs = require('../index.js');
+
+describe('querystring', function () {
+ describe('parse', function () {
+
+ it('should return empty object from no input', function () {
+ assert.deepStrictEqual(
+ qs.parse(undefined),
+ {},
+ );
+ });
+
+ it('should return empty object from empty string', function () {
+ assert.deepStrictEqual(
+ qs.parse(''),
+ {},
+ );
+ });
+
+ it('should return simple mapping', function () {
+ assert.deepStrictEqual(
+ qs.parse('foo=1&bar=2&baz=quux'),
+ {
+ foo: '1',
+ bar: '2',
+ baz: 'quux',
+ },
+ );
+ });
+
+ it('should return array for repeated keys', function () {
+ assert.deepStrictEqual(
+ qs.parse('foo=1&foo=2&foo=quux'),
+ {
+ foo: [ '1', '2', 'quux' ],
+ },
+ );
+ });
+
+ it('should return null values for bare keys', function () {
+ assert.deepStrictEqual(
+ qs.parse('foo&foo&bar&quux'),
+ {
+ foo: [ null, null ],
+ bar: null,
+ quux: null,
+ },
+ );
+ });
+
+ it('should handle space encodings and equals in values', function () {
+ assert.deepStrictEqual(
+ qs.parse('this+key=+spacey+string+;&foo=equally=string&'),
+ {
+ '': [ null, null ],
+ 'this key': ' spacey string ',
+ foo: 'equally=string',
+ },
+ );
+ });
+
+ it('should handle raw spaces and encoded spaces', function () {
+ assert.deepStrictEqual(
+ qs.parse('this+has actual+spaces=but okay%20whatever'),
+ {
+ 'this has actual spaces': 'but okay whatever',
+ },
+ );
+ });
+
+ it('should handle empty values', function () {
+ assert.deepStrictEqual(
+ qs.parse(';;;;;;;+;;;;'),
+ {
+ '': [ null, null, null, null, null, null, null, null, null, null, null ],
+ ' ': null,
+ },
+ );
+ });
+
+ it('should handle PHP style array declarations', function () {
+ assert.deepStrictEqual(
+ qs.parse('foo%5B%5D&bar[]=1&bar[]=2&baz', true),
+ {
+ 'foo': [null],
+ bar: ['1', '2'],
+ baz: null,
+ },
+ )
+ });
+
+ }); // parse
+});
+