var assert = require('assert');
var ESQ = require('../lib/esq');

describe('Testing ESQ', function() {
  var esq = null;
  beforeEach(function() { esq = new ESQ(); });

  describe('getQuery', function() {
    it('with no query', function() {
      var result = esq.getQuery();
      assert.deepEqual(result, { });
    });

    it('with building a query first', function() {
      esq.query('filtered', 'filter', { });
      var result = esq.getQuery();
      assert.deepEqual(result, { filtered: { filter: { } } });
    });
  });

  describe('query', function() {
    it('with no args', function() {
      var result = esq.query();
      assert.deepEqual(result, { });
    });

    it('with standard params', function() {
      var result = esq.query('foo', 'bar', { });
      assert.deepEqual(result, { foo: { bar: { } } });
    });

    it('with bad args', function() {
      var result = esq.query('foo', 'bar', ['foobar'], 123);
      assert.deepEqual(result, { foo: { bar: { foobar: [ 123 ] } } });
    });
  });

  describe('_createNestedObject', function() {
    var base = null;
    beforeEach(function() { base = { }; });

    it('with no parameters', function() {
      esq._createNestedObject({ }, [ ], null);
      assert.deepEqual(base, { });
    });

    it('with base and name parameters', function() {
      esq._createNestedObject(base, ['a'], null);
      assert.deepEqual(base, { a: { } });
    });

    it('with base, name and value parameters', function() {
      esq._createNestedObject(base, ['a'], { b: 'c' });
      assert.deepEqual(base, { a: { b: 'c' } });
    });

    it('with object type value parameters', function() {
      esq._createNestedObject(base, ['a'], { b: 'c' });
      esq._createNestedObject(base, ['a'], { d: 'e' });
      assert.deepEqual(base, { a: { b: 'c', d: 'e' } });
    });

    it('with array type value parameters', function() {
      esq._createNestedObject(base, ['a'], [{ b: 'c' }]);
      esq._createNestedObject(base, ['a'], [{ d: 'e' }]);
      assert.deepEqual(base, { a: [ { b: 'c' }, { d: 'e' } ] });
    });

    it('with multiple levels of nesting', function() {
      esq._createNestedObject(base, ['a', 'b', 'c']);
      assert.deepEqual(base, { a: { b: { c: { } } } });
    });

    it('with multiple levels of nesting and values', function() {
      esq._createNestedObject(base, ['a', 'b', 'c'], { d: 'e' });
      esq._createNestedObject(base, ['a', 'b', 'c'], { f: 'g' });
      assert.deepEqual(base, { a: { b: { c: { d: 'e', f: 'g' } } } });
    });
  });
});

@@ -1813,32 +1813,273 @@
  %7D %7D);%0A    %7D);%0A%0A
+    it('with array type name parameters', function() %7B%0A      esq._createNestedObject(base, %5B%5B'a'%5D, 'b'%5D, 'c');%0A      esq._createNestedObject(base, %5B%5B'a'%5D, 'd'%5D, 'e');%0A      assert.deepEqual(base, %7B a: %5B %7B b: 'c' %7D, %7B d: 'e' %7D %5D %7D);%0A    %7D);%0A%0A
     it('with arr

Add a test for array creation with field name