const expect = require('chai').expect,
    Scope = require('../../');

describe('scope module', function () {
    var scope;

    beforeEach(function () {
        scope = Scope.create();
        scope.set('expect', expect); // inject expect in scope for testing
    });
    afterEach(function () {
        scope = null;
    });

    it('should create a new scope', function () {
        expect(scope instanceof Scope).to.be.ok;
    });

    it('should allow setting of globals', function (done) {
        scope.set('myGlobal', { test: 123 });
        scope.exec(`
            // expect(this).to.have.property('myGlobal');
            expect(myGlobal).to.be.an('object').that.eql({test: 123});
        `, done);
    });

    it('should allow unsetting of globals', function (done) {
        scope.set('myGlobal', { test: 123 });

        scope.exec(`
            // expect(this).to.have.property('myGlobal');
            expect(myGlobal).to.be.an('object').that.eql({test: 123});
        `, function (err) {
            if (err) { return done(err); }

            scope.unset('myGlobal', { test: 123 });

            scope.exec('expect(this.myGlobal).to.be.undefined;', done);
        });
    });

    it('should now allow unnecessary globals from showing up', function (done) {
        global.oneTestGlobal = true;
        scope.exec(`
            expect(this.oneTestGlobal).to.be.undefined;
        `, function (err) {
            delete global.oneTestGlobal;
            done(err);
        });
    });

    it('should add all allowed globals even if it\'s missing in the global scope', function (done) {
        var WeakSet = global.WeakSet;

        delete global.WeakSet;

        scope.exec(`
            expect(this).to.have.property('WeakSet').that.is.undefined;
        `, function (err) {
            global.WeakSet = WeakSet;
            done(err);
        });
    });
});

@@ -1871,13 +1871,794 @@
 %0A    %7D);
+%0A%0A    // @fixme https://github.com/postmanlabs/uniscope/pull/408%0A    it.skip('should handle globals with invalid identifer name', function (done) %7B%0A        global%5B'123'%5D = true;%0A        global%5B'a-b'%5D = true;%0A        scope.exec(%60%0A            expect(this%5B'123'%5D).to.be.undefined;%0A            expect(this%5B'a-b'%5D).to.be.undefined;%0A        %60, function (err) %7B%0A            delete global%5B'123'%5D;%0A            delete global%5B'a-b'%5D;%0A            done(err);%0A        %7D);%0A    %7D);%0A%0A    it('should handle globals with unicode identifer name', function (done) %7B%0A        global.%E0%B2%A0_%E0%B2%A0 = true;%0A        scope.exec(%60%0A            expect(this.%E0%B2%A0_%E0%B2%A0).to.be.undefined;%0A            expect(%E0%B2%A0_%E0%B2%A0).to.be.undefined;%0A        %60, function (err) %7B%0A            delete global.%E0%B2%A0_%E0%B2%A0;%0A            done(err);%0A        %7D);%0A    %7D);
 %0A%7D);%0A

Add unit tests for invalid and unicode identifier names