text: var Lab = require('@hapi/lab');
  var lab = exports.lab = Lab.script();
  
  var describe = lab.describe;
  var it = lab.it;
  var Code = require('@hapi/code');
  var expect = Code.expect;
  
  var clone = require('clone');
  var set = require('../set');
  var pluck = require('../pluck');
  
  describe('set', function () {
    it('should set a key with value on a object', () => {
      var obj = {
        foo: 1,
        bar: 1,
        qux: 1
      };
  
      var key = 'bar';
      var val = 100;
  
      var expected = clone(obj);
      expected[key] = val;
  
      expect(set(obj, key, val)).to.equal(expected);
      expect(obj[key]).to.equal(100); // original obj modified
      
    });
    it('should set a key with a val when used with array functions', () => {
      var objs = [
        {
          bar: 1
        },
        {
          foo: 2,
          bar: 2,
        },
        {
          foo: 3,
          bar: 3,
          koo: 3,
          goo: 3
        }
      ];
      var key = 'bar';
      var val = 100;
      var expected = objs.map(function (obj) {
        var out = clone(obj);
        out[key] = val;
        return out;
      });
      expect(objs.map(set(key, val))).to.equal(expected);
      expect(objs.map(pluck(key))).to.equal([100, 100, 100]); // original obj modified
      
    });
    it('should set a set of keys and vals when given an object', () => {
      var obj = {
        foo: 1,
        bar: 1,
        qux: 1
      };
  
      var key = 'bar';
      var val = 100;
      var setObj = {};
      setObj[key] = val;
  
      var expected = clone(obj);
      expected[key] = val;
  
      expect(set(obj, setObj)).to.equal(expected);
      expect(obj[key]).to.equal(100); // original obj modified
      
    });
    it('should set the right value when given an object and a keypath', () => {
      var obj = {
        foo: 1,
        qux: 1
      };
  
      var expected = {
        foo: 1,
        bar: {
          baz: 100
        },
        qux: 1
      };
  
      expect(set(obj, 'bar.baz', 100)).to.equal(expected);
      expect(obj).to.equal(expected);
      
    });
    it('should set the right value when given an object and a keypath object', () => {
      var obj = {
        foo: 1,
        qux: 1
      };
  
      var keypathObj = {
        'bar.baz' : 100,
        yolo: 1
      };
  
      var expected = {
        foo: 1,
        bar: {
          baz: 100
        },
        qux: 1,
        yolo: 1
      };
      expect(set(obj, keypathObj)).to.equal(expected);
      expect(obj).to.equal(expected);
      
    });
    it('should set a set of keys and vals when given an object when used with array functions', () => {
      var objs = [
        {
          bar: 1
        },
        {
          foo: 2,
          bar: 2,
          qux: 2
        },
        {
          foo: 3,
          bar: 3,
          koo: 3,
          goo: 3
        }
      ];
      var key = 'bar';
      var val = 100;
      var setObj = {};
      setObj[key] = val;
      var expected = objs.map(function (obj) {
        var copy = clone(obj);
        copy[key] = val;
        return copy;
      });
      expect(objs.map(set(setObj))).to.equal(expected);
      expect(objs.map(pluck(key))).to.equal([100, 100, 100]); // original obj modified
      
    });
    describe('deep', function () {
      it('should set a deep keypath', () => {
        const obj = {
          // foo: 1,
          bar: 2
        }
        const out = set(obj, 'foo.qux', 100);
        expect(out).to.equal({ foo: { qux: 100 }, bar: 2 });
        
      })
    })
    describe('errors', function() {
      it('should error when given two args that artent str, val or obj, obj', () => {
        try {
          set(/what/, /what/);
        }
        catch (err) {
          expect(err).to.exist();
          
        }
      }); 
      it('should error when when using __proto__ reserved key', () => {
        try {
          set(() => {}, "__proto__");
        }
        catch (err) {
          expect(err).to.exist();  
        }
      });
      it('should error when when using prototype reserved key', () => {
        try {
          set(() => {}, "prototype");
        }
        catch (err) {
          expect(err).to.exist();  
        }
      });
      it('should error when when using constructor reserved key', () => {
        try {
          set(() => {}, "constructor");
        }
        catch (err) {
          expect(err).to.exist(); 
        }
      });
    });
  });
  