"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
/* --------------------------------------------------------------------------------------------
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 * ------------------------------------------------------------------------------------------ */
const chai_1 = require("chai");
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const constants_1 = require("../constants");
const lsp_server_1 = require("../lsp-server");
describe('Flink Formatter Test', function () {
    it('should format Flink SQL ALTER statements', () => {
        const folderDir = path.join(__dirname, 'sql/alter');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/alter/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL CREATE statements', () => {
        const folderDir = path.join(__dirname, 'sql/create');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/create/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL DESCRIBE statements', () => {
        const folderDir = path.join(__dirname, 'sql/describe');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/describe/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL DROP statements', () => {
        const folderDir = path.join(__dirname, 'sql/drop');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/drop/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL INSERT statements', () => {
        const folderDir = path.join(__dirname, 'sql/insert');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/insert/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL LOAD/UNLOAD statements', () => {
        const folderDir = path.join(__dirname, 'sql/load');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/load/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL QUERY statements', () => {
        const folderDir = path.join(__dirname, 'sql/query');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/query/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    }).timeout(10000);
    it('should format Flink SQL SET/RESET statements', () => {
        const folderDir = path.join(__dirname, 'sql/set');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/set/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL SHOW statements', () => {
        const folderDir = path.join(__dirname, 'sql/show');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/show/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL USE statements', () => {
        const folderDir = path.join(__dirname, 'sql/use');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/use/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL Explain statements', () => {
        const folderDir = path.join(__dirname, 'sql/explain');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/explain/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
    it('should format Flink SQL AUTO OPTIMIZE statements', () => {
        const folderDir = path.join(__dirname, 'sql/auto-optimize');
        const files = fs.readdirSync(folderDir, 'utf8');
        files.forEach(file => {
            const fileDir = path.join(__dirname, `sql/auto-optimize/${file}`);
            const sql = fs.readFileSync(fileDir, 'utf8');
            const result = format(sql);
            (0, chai_1.expect)(result.trimEnd()).to.equal(sql.trimEnd());
        });
    });
});
function format(sql) {
    const uri = 'test://test.sql';
    const textDocument = vscode_languageserver_textdocument_1.TextDocument.create(uri, constants_1.LANGUAGE_ID, 0, sql);
    const lspServer = new lsp_server_1.LSPServer();
    lspServer.warehouse.setParsingValue(textDocument);
    return lspServer.doFormatting(textDocument, {
        tabSize: 4,
        maxLineLength: 60,
        insertSpaces: true
    });
}
//# sourceMappingURL=format.test.js.map