"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const internal_1 = require("../../../internal");
const cdmObjectTypeGuards_1 = require("../../../Utilities/cdmObjectTypeGuards");
const testHelper_1 = require("../../testHelper");
describe('Cdm/SymbolResolution/SymbolResolve', () => {
    const testsSubpath = 'Cdm/SymbolResolution';
    /**
     * Test that symbols are set correctly and that object can be correctly fetched using the symbols
     */
    it('TestSymbolResolution', (done) => __awaiter(void 0, void 0, void 0, function* () {
        const corpus = testHelper_1.testHelper.getLocalCorpus(testsSubpath, 'TestSymbolResolution');
        // load the file
        const resOpt = new internal_1.resolveOptions();
        resOpt.importsLoadStrategy = internal_1.importsLoadStrategy.load;
        const ent = yield corpus.fetchObjectAsync('local:/symbolEntity.cdm.json/symbolEnt', null, resOpt);
        resOpt.wrtDoc = ent.inDocument;
        // resolve a reference to the trait object
        const traitDef = corpus.resolveSymbolReference(resOpt, ent.inDocument, 'symbolEnt/exhibitsTraits/someTraitOnEnt', internal_1.cdmObjectType.traitDef, false);
        expect(cdmObjectTypeGuards_1.isCdmTraitDefinition(traitDef))
            .toBeTruthy();
        // resolve a path to the reference object that contains the trait
        const traitRef = corpus.resolveSymbolReference(resOpt, ent.inDocument, 'symbolEnt/exhibitsTraits/someTraitOnEnt/(ref)', internal_1.cdmObjectType.traitDef, false);
        expect(cdmObjectTypeGuards_1.isCdmTraitReference(traitRef))
            .toBeTruthy();
        // fetchObjectDefinition on a path to a reference should fetch the actual object
        const traitRefDefinition = traitRef.fetchObjectDefinition(resOpt);
        const traitDefDefinition = traitDef.fetchObjectDefinition(resOpt);
        expect(traitRefDefinition)
            .toBe(traitDef);
        expect(traitDefDefinition)
            .toBe(traitDef);
        const groupRef = corpus.resolveSymbolReference(resOpt, ent.inDocument, 'symbolEnt/hasAttributes/someGroupRef/(ref)', internal_1.cdmObjectType.attributeGroupDef, false);
        expect(cdmObjectTypeGuards_1.isAttributeGroupReference(groupRef))
            .toBeTruthy();
        const groupDef = corpus.resolveSymbolReference(resOpt, ent.inDocument, 'symbolEnt/hasAttributes/someGroupRef', internal_1.cdmObjectType.attributeGroupDef, false);
        expect(cdmObjectTypeGuards_1.isAttributeGroupDefinition(groupDef))
            .toBeTruthy();
        // calling fetchObjectDefinition on a symbol to a ref or def should both give the definition
        const groupRefDefinition = groupRef.fetchObjectDefinition(resOpt);
        const groupDefDefinition = groupDef.fetchObjectDefinition(resOpt);
        expect(groupRefDefinition)
            .toBe(groupDef);
        expect(groupDefDefinition)
            .toBe(groupDef);
        const typeAtt = corpus.resolveSymbolReference(resOpt, ent.inDocument, 'symbolEnt/hasAttributes/someGroupRef/members/someAttribute', internal_1.cdmObjectType.attributeGroupDef, false);
        expect(cdmObjectTypeGuards_1.isTypeAttributeDefinition(typeAtt))
            .toBeTruthy();
        done();
    }));
});
//# sourceMappingURL=symbolResolve.test.js.map