"use strict";

var any = require("./any");
var createSpy = require("./spy");
var createSpyObject = require("./spy-object");

// DEPRECATED
jasmine = {
    createSpy: createSpy,
    createSpyObj: createSpyObject,
    any: any
};

// During declaration
var currentSuite;
// During execution
var currentReport;
var currentTest;

describe = function (name, callback) {
    if (!currentSuite) {
        throw new Error("Can't call describe when there is no active suite");
    }
    var suite = currentSuite.nestSuite(name);
    suite.describe(callback);
};

xdescribe = function (name, callback) {
    if (!currentSuite) {
        throw new Error("Can't call xdescribe when there is no active suite");
    }
    var suite = currentSuite.nestSuite(name);
    suite.skip = true;
    suite.describe(callback);
};

ddescribe = function (name, callback) {
    if (!currentSuite) {
        throw new Error("Can't call ddescribe when there is no active suite");
    }
    var suite = currentSuite.nestSuite(name);
    suite.setExclusive();
    suite.describe(callback);
};

it = function (name, callback) {
    if (!currentSuite) {
        throw new Error("Can't call it when there is no active suite");
    }
    currentSuite.nestTest(name, callback);
};

iit = function (name, callback) {
    if (!currentSuite) {
        throw new Error("Can't call iit when there is no active suite");
    }
    var test = currentSuite.nestTest(name, callback);
    currentSuite.setExclusive();
    test.exclusive = true;
};

xit = function (name, callback) {
    if (!currentSuite) {
        throw new Error("Can't call xit when there is no active suite");
    }
    var test = currentSuite.nestTest(name, callback);
    test.skip = true;
};

beforeEach = function (callback) {
    if (!currentSuite) {
        throw new Error("Cannot use `beforeEach` outside of a 'define' block");
    }
    currentSuite.beforeEach = callback;
};

afterEach = function (callback) {
    if (!currentSuite) {
        throw new Error("Cannot use `afterEach` outside of a 'define' block");
    }
    currentSuite.afterEach = callback;
};

expect = function (value) {
    if (!currentReport) {
        throw new Error("Cannot declare an expectation outside of an 'it' block");
    }
    if (value && typeof value.expect === "function") {
        return value.expect(currentReport);
    } else {
        return new currentTest.suite.Expectation(
            value,
            currentReport
        );
    }
};

spyOn = function (object, name) {
    object[name] = createSpy(name, object[name]);
    return object[name];
};

// For internal linkage

getCurrentSuite = function () {
    if (currentSuite) {
        return currentSuite;
    } else if (currentTest) {
        return currentTest.suite;
    }
};

setCurrentSuite = function (suite) {
    currentSuite = suite;
};

getCurrentReport = function () {
    return currentReport;
};

setCurrentReport = function (report) {
    currentReport = report;
};

getCurrentTest = function () {
    return currentTest;
};

setCurrentTest = function (test) {
    currentTest = test;
};


@@ -132,16 +132,27 @@
 RECATED%0A
+globalThis.
 jasmine 
@@ -330,16 +330,27 @@
 tTest;%0A%0A
+globalThis.
 describe
@@ -569,16 +569,27 @@
 k);%0A%7D;%0A%0A
+globalThis.
 xdescrib
@@ -833,16 +833,27 @@
 k);%0A%7D;%0A%0A
+globalThis.
 ddescrib
@@ -1100,16 +1100,27 @@
 k);%0A%7D;%0A%0A
+globalThis.
 it = fun
@@ -1294,16 +1294,27 @@
 k);%0A%7D;%0A%0A
+globalThis.
 iit = fu
@@ -1561,16 +1561,27 @@
 ue;%0A%7D;%0A%0A
+globalThis.
 xit = fu
@@ -1790,16 +1790,27 @@
 ue;%0A%7D;%0A%0A
+globalThis.
 beforeEa
@@ -1991,16 +1991,27 @@
 ck;%0A%7D;%0A%0A
+globalThis.
 afterEac
@@ -2189,16 +2189,27 @@
 ck;%0A%7D;%0A%0A
+globalThis.
 expect =
@@ -2571,16 +2571,27 @@
   %7D%0A%7D;%0A%0A
+globalThis.
 spyOn = 
@@ -2720,16 +2720,27 @@
 inkage%0A%0A
+globalThis.
 getCurre
@@ -2886,24 +2886,35 @@
 ;%0A    %7D%0A%7D;%0A%0A
+globalThis.
 setCurrentSu
@@ -2964,24 +2964,35 @@
  suite;%0A%7D;%0A%0A
+globalThis.
 getCurrentRe
@@ -3038,24 +3038,35 @@
 Report;%0A%7D;%0A%0A
+globalThis.
 setCurrentRe
@@ -3124,16 +3124,27 @@
 rt;%0A%7D;%0A%0A
+globalThis.
 getCurre
@@ -3194,16 +3194,27 @@
 st;%0A%7D;%0A%0A
+globalThis.
 setCurre
@@ -3259,17 +3259,16 @@
 Test = test;%0A%7D;%0A
-%0A

Fix Jasmine DSL for strict mode