/*jshint strict:false */
/*globals describe, it */

var formatGreeting,
    assert = require('chai').assert,
    fillopts = require('../index');


formatGreeting = function (opts, punctuation) {
    return 'Hello, ' + opts.title + ' ' + opts.name + punctuation;
};


describe('fillopts', function () {
    it('fills opts', function () {
        var filled = fillopts(formatGreeting, {title: 'Dr.', name: 'Crusher'});
        assert.equal(filled(), 'Hello, Dr. Crusher');
    });
    it('preserves args', function () {
        var filled = fillopts(formatGreeting, {title: 'Dr.', name: 'Crusher'});
        assert.equal(filled(null, '!'), 'Hello, Dr. Crusher!');
    });
    it('combines filled opts', function () {
        var filled = fillopts(
            fillopts(formatGreeting, {title: 'Dr.'}),
            {name: 'Crusher'}
        );
        assert.equal(filled(), 'Hello, Dr. Crusher');
    });
    it('overrides previous opts', function () {
        var filled = fillopts(
            fillopts(formatGreeting, {title: 'Dr.'}, {name: 'Crusher'}),
            {name: 'Pulaski'}
        );
        assert.equal(filled(), 'Hello, Dr. Pulaski');
    });
    it("doesn't mutate the old function", function () {
        var filledA = fillopts(formatGreeting, {title: 'Dr.', name: 'Pulaski'}),
            filledB = fillopts(filledA, {name: 'Crusher'});
        assert.equal(filledA(), 'Hello, Dr. Pulaski');
        assert.equal(filledB(), 'Hello, Dr. Crusher');
    });

    describe('withOpts', function () {
        it('adds opts', function () {
            var filled = fillopts(formatGreeting)
                .withOpts({title: 'Dr.', name: 'Crusher'});
            assert.equal(filled(), 'Hello, Dr. Crusher');
        });
        it('combines filled opts', function () {
            var filled = fillopts(formatGreeting)
                .withOpts({title: 'Dr.'})
                .withOpts({name: 'Crusher'});
            assert.equal(filled(), 'Hello, Dr. Crusher');
        });
        it('overrides previous opts', function () {
            var filled = fillopts(formatGreeting)
                .withOpts({title: 'Dr.'}, {name: 'Crusher'})
                .withOpts({name: 'Pulaski'});
            assert.equal(filled(), 'Hello, Dr. Pulaski');
        });
        it("doesn't mutate the old function", function () {
            var filledA = fillopts(formatGreeting, {title: 'Dr.', name: 'Pulaski'}),
                filledB = filledA.withOpts({name: 'Crusher'});
            assert.equal(filledA(), 'Hello, Dr. Pulaski');
            assert.equal(filledB(), 'Hello, Dr. Crusher');
        });
    });
});

@@ -242,16 +242,17 @@
 .name + 
+(
 punctuat
@@ -254,16 +254,23 @@
 ctuation
+ %7C%7C '')
 ;%0A%7D;%0A%0A%0Ad
@@ -1025,36 +1025,34 @@
 g, %7Btitle: 'Dr.'
-%7D
 , 
-%7B
 name: 'Crusher'%7D
@@ -2132,12 +2132,10 @@
 Dr.'
-%7D
 , 
-%7B
 name

Fix bad tests