"use strict";
var helpers = require("../../helpers");
var chai_1 = require("chai");
describe("helpers", function () {
    var assertTestData = function (testData, method) {
        var actualResult = method(testData.input);
        chai_1.assert.deepEqual(actualResult, testData.expectedResult, "For input " + testData.input + ", the expected result is: " + testData.expectedResult + ", but actual result is: " + actualResult + ".");
    };
    describe("getPropertyName", function () {
        var ES5Functions = [
            {
                input: "function (a) {\n\t\t\t\t\treturn a.test;\n\t\t\t\t}",
                expectedResult: "test"
            },
            {
                input: "function(a) {return a.test;}",
                expectedResult: "test"
            },
            {
                input: null,
                expectedResult: null
            },
            {
                input: "",
                expectedResult: null
            },
            {
                input: "function(a){ return a; }",
                expectedResult: null
            },
            {
                input: "function(a) {return a.b.test;}",
                expectedResult: "test"
            },
            {
                input: "function(a) {return a.b.c.d.[\"test1\"].e.f.test;}",
                expectedResult: "test"
            },
            {
                input: "function(a) {return ;}",
                expectedResult: null
            },
            {
                input: "function(a) {return undefined;}",
                expectedResult: null
            },
            {
                input: "function(a) {return null;}",
                expectedResult: null
            },
            {
                input: "function(a) {return \"test\";}",
                expectedResult: null
            }
        ];
        var ES6Functions = [
            {
                input: "(a) => {\n\t\t\t\t\treturn a.test;\n\t\t\t\t}",
                expectedResult: "test"
            },
            {
                input: "(a)=>{return a.test;}",
                expectedResult: "test"
            },
            {
                input: "a => a.test",
                expectedResult: "test"
            },
            {
                input: "(a) => a.test",
                expectedResult: "test"
            },
            {
                input: "(a)     =>    a.test      ",
                expectedResult: "test"
            },
            {
                input: "(a)=>a.test       ",
                expectedResult: "test"
            },
            {
                input: null,
                expectedResult: null
            },
            {
                input: "",
                expectedResult: null
            },
            {
                input: "a => a",
                expectedResult: null
            },
            {
                input: "(a) => a.b.test",
                expectedResult: "test"
            },
            {
                input: "(a) => { return a.b.test; }",
                expectedResult: "test"
            },
            {
                input: "a => a.b.c.d.[\"test1\"].e.f.test",
                expectedResult: "test"
            },
            {
                input: "(a) => {return ;}",
                expectedResult: null
            },
            {
                input: "a => undefined ",
                expectedResult: null
            },
            {
                input: "a => null",
                expectedResult: null
            },
            {
                input: "a => \"test\"",
                expectedResult: null
            },
            {
                input: function (a) { return a.test; },
                expectedResult: "test"
            }
        ];
        it("returns correct property name for ES5 functions", function () {
            _.each(ES5Functions, function (testData) { return assertTestData(testData, helpers.getPropertyName); });
        });
        it("returns correct property name for ES6 functions", function () {
            _.each(ES6Functions, function (testData) { return assertTestData(testData, helpers.getPropertyName); });
        });
    });
    describe("toBoolean", function () {
        var toBooleanTestData = [
            {
                input: true,
                expectedResult: true
            },
            {
                input: false,
                expectedResult: false
            },
            {
                input: "true",
                expectedResult: true
            },
            {
                input: "false",
                expectedResult: false
            },
            {
                input: "",
                expectedResult: false
            },
            {
                input: null,
                expectedResult: false
            },
            {
                input: undefined,
                expectedResult: false
            },
            {
                input: '\n',
                expectedResult: false
            },
            {
                input: '\r\n',
                expectedResult: false
            },
            {
                input: '\t',
                expectedResult: false
            },
            {
                input: '\t\t\t\t\t\t\n\t\t\t\t\r\n\r\n\n\n   \t\t\t\r\n',
                expectedResult: false
            },
            {
                input: "some random text",
                expectedResult: false
            },
            {
                input: { "true": true },
                expectedResult: false
            },
            {
                input: {},
                expectedResult: false
            },
            {
                input: { "a": { "b": 1 } },
                expectedResult: false
            }
        ];
        it("returns expected result", function () {
            _.each(toBooleanTestData, function (testData) { return assertTestData(testData, helpers.toBoolean); });
        });
        it("returns false when Object.create(null) is passed", function () {
            var actualResult = helpers.toBoolean(Object.create(null));
            chai_1.assert.deepEqual(actualResult, false);
        });
    });
    describe("isNullOrWhitespace", function () {
        var isNullOrWhitespaceTestData = [
            {
                input: "",
                expectedResult: true
            },
            {
                input: "     ",
                expectedResult: true
            },
            {
                input: null,
                expectedResult: true
            },
            {
                input: undefined,
                expectedResult: true
            },
            {
                input: [],
                expectedResult: false
            },
            {
                input: ["test1", "test2"],
                expectedResult: false
            },
            {
                input: {},
                expectedResult: false
            },
            {
                input: { a: 1, b: 2 },
                expectedResult: false
            },
            {
                input: true,
                expectedResult: false
            },
            {
                input: false,
                expectedResult: false
            },
            {
                input: '\n',
                expectedResult: true
            },
            {
                input: '\r\n',
                expectedResult: true
            },
            {
                input: '\t',
                expectedResult: true
            },
            {
                input: '\t\t\t\t\t\t\r\n\t\t\t\t\t\n\t\t\t     \t\t\t\t\t\n\r\n   ',
                expectedResult: true
            }
        ];
        it("returns expected result", function () {
            _.each(isNullOrWhitespaceTestData, function (t) { return assertTestData(t, helpers.isNullOrWhitespace); });
        });
        it("returns false when Object.create(null) is passed", function () {
            var actualResult = helpers.isNullOrWhitespace(Object.create(null));
            chai_1.assert.deepEqual(actualResult, false);
        });
    });
});
