"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let assert = require('assert');
const utils_1 = require("../utils");
let path = require('path');
let options = {
    'deep1': {
        'deep2': {
            'deep3': {
                'int': 4
            }
        }
    },
    'string': "mda"
};
class Test {
    constructor() {
        this.a = 0;
    }
    test() {
        return "test";
    }
}
class Test2 extends Test {
}
describe('test utils', function () {
    it('deepExtend', function (done) {
        assert.equal(options.deep1.deep2.deep3.int, 4);
        assert.equal(options.string, "mda");
        let config = utils_1.default.deepExtend({}, options, { 'deep1': { 'deep2': { 'deep3': { 'int': 6 } } } });
        assert.equal(config.deep1.deep2.deep3.int, 6);
        assert.equal(config.string, "mda");
        done();
    });
    it('pad', function (done) {
        assert.equal(utils_1.default.pad(4), "04");
        assert.equal(utils_1.default.pad(0), "00");
        assert.equal(utils_1.default.pad(10), "10");
        assert.equal(utils_1.default.pad(444), "444");
        done();
    });
    it('getIp', function (done) {
        assert.equal(utils_1.default.getIp({ 'ip': "::1" }), "127.0.0.1");
        assert.equal(utils_1.default.getIp({ '_remoteAddress': "::1" }), "127.0.0.1");
        assert.equal(utils_1.default.getIp({ 'connection': { 'remoteAddress': "::1" } }), "127.0.0.1");
        assert.equal(utils_1.default.getIp({ 'ip': "::ffff:ab87:3422" }), "ab87:3422");
        assert.equal(utils_1.default.getIp({ '_remoteAddress': "::ffff:342" }), "342");
        assert.equal(utils_1.default.getIp({ 'connection': { 'remoteAddress': "::ffff:ffff" } }), "ffff");
        assert.equal(utils_1.default.getIp({ 'connection': null }), undefined);
        assert.equal(utils_1.default.getIp({ 'simple': null }), undefined);
        assert.equal(utils_1.default.getIp(null), undefined);
        done();
    });
    it('getFullRouteFrom', function (done) {
        let baseRoot = __dirname;
        if (require.main) {
            baseRoot = path.dirname(require.main.filename);
        }
        assert.equal(utils_1.default.getFullRouteFrom(null), baseRoot);
        assert.equal(utils_1.default.getFullRouteFrom(), baseRoot);
        assert.equal(utils_1.default.getFullRouteFrom("test"), baseRoot + "/test");
        assert.equal(utils_1.default.getFullRouteFrom("../test"), baseRoot + "/../test");
        assert.equal(utils_1.default.getFullRouteFrom(""), baseRoot + "/");
        done();
    });
    it('convertToBytesSize', function (done) {
        assert.equal(utils_1.default.convertToBytesSize(984), "984.00B");
        assert.equal(utils_1.default.convertToBytesSize(0), "0");
        assert.equal(utils_1.default.convertToBytesSize(1), "1.00B");
        assert.equal(utils_1.default.convertToBytesSize(-12), "-12");
        assert.equal(utils_1.default.convertToBytesSize(1024), "1.00KB");
        assert.equal(utils_1.default.convertToBytesSize(1024 + 10), "1.01KB");
        assert.equal(utils_1.default.convertToBytesSize(1024 - 10), "1014.00B");
        assert.equal(utils_1.default.convertToBytesSize(Math.pow(1024, 2)), "1.00MB");
        assert.equal(utils_1.default.convertToBytesSize(Math.pow(1024, 3)), "1.00GB");
        assert.equal(utils_1.default.convertToBytesSize(Math.pow(1024, 4)), "1.00TB");
        assert.equal(utils_1.default.convertToBytesSize(Math.pow(1024, 5)), "1.00PB");
        assert.equal(utils_1.default.convertToBytesSize(Math.pow(1024, 6)), "+1023.99PB");
        done();
    });
});
//# sourceMappingURL=test-utils.js.map