"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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Red Hat. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
const path = __importStar(require("path"));
const testHelper_1 = require("./utils/testHelper");
const assert_1 = __importDefault(require("assert"));
const serviceSetup_1 = require("./utils/serviceSetup");
const vscode_languageserver_types_1 = require("vscode-languageserver-types");
const yamlSettings_1 = require("../src/yamlSettings");
/**
 * Setup the schema we are going to use with the language settings
 */
// Defines a Mocha test describe to group tests of similar kind together
describe('Multiple Documents Validation Tests', () => {
    let languageSettingsSetup;
    let languageHandler;
    let validationHandler;
    let languageService;
    let yamlSettings;
    before(() => {
        const uri = (0, testHelper_1.toFsPath)(path.join(__dirname, './fixtures/customMultipleSchemaSequences.json'));
        const fileMatch = ['*.yml', '*.yaml'];
        languageSettingsSetup = new serviceSetup_1.ServiceSetup()
            .withHover()
            .withIndentation('  ')
            .withValidate()
            .withSchemaFileMatch({
            fileMatch,
            uri,
        })
            .withCustomTags(['!Test', '!Ref sequence']);
        const { languageService: langService, validationHandler: valHandler, languageHandler: langHandler, yamlSettings: settings, } = (0, testHelper_1.setupLanguageService)(languageSettingsSetup.languageSettings);
        languageService = langService;
        validationHandler = valHandler;
        languageHandler = langHandler;
        yamlSettings = settings;
    });
    describe('Multiple Documents Validation', function () {
        function validatorSetup(content) {
            const testTextDocument = (0, testHelper_1.setupTextDocument)(content);
            languageService.configure(languageSettingsSetup.languageSettings);
            return validationHandler.validateTextDocument(testTextDocument);
        }
        function hoverSetup(content, position) {
            const testTextDocument = (0, testHelper_1.setupTextDocument)(content);
            languageService.configure(languageSettingsSetup.languageSettings);
            yamlSettings.documents = new yamlSettings_1.TextDocumentTestManager();
            yamlSettings.documents.set(testTextDocument);
            return languageHandler.hoverHandler({
                position: testTextDocument.positionAt(position),
                textDocument: testTextDocument,
            });
        }
        it('Should validate multiple documents', async () => {
            const content = `
name: jack
age: 22
---
cwd: test
            `;
            const result = await validatorSetup(content);
            assert_1.default.equal(result.length, 0);
        });
        it('Should find errors in both documents', async () => {
            const content = `name1: jack
age: asd
---
cwd: False`;
            const result = await validatorSetup(content);
            assert_1.default.equal(result.length, 3);
        });
        it('Should find errors in first document', async () => {
            const content = `name: jack
age: age
---
cwd: test`;
            const result = await validatorSetup(content);
            assert_1.default.equal(result.length, 1);
        });
        it('Should find errors in second document', async () => {
            const content = `name: jack
age: 22
---
cwd: False
`;
            const result = await validatorSetup(content);
            assert_1.default.equal(result.length, 1);
        });
        it('Should hover in first document', async () => {
            const content = 'name: jack\nage: 22\n---\ncwd: False';
            const result = await hoverSetup(content, 1 + content.indexOf('age'));
            assert_1.default.strictEqual(vscode_languageserver_types_1.MarkupContent.is(result.contents), true);
            assert_1.default.strictEqual(result.contents.kind, 'markdown');
            assert_1.default.strictEqual(result.contents.value, 'The age of this person');
        });
    });
});
//# sourceMappingURL=multipleDocuments.test.js.map