13af6ab5fSopenharmony_ci/*
23af6ab5fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License.
53af6ab5fSopenharmony_ci * You may obtain a copy of the License at
63af6ab5fSopenharmony_ci *
73af6ab5fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
83af6ab5fSopenharmony_ci *
93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and
133af6ab5fSopenharmony_ci * limitations under the License.
143af6ab5fSopenharmony_ci */
153af6ab5fSopenharmony_ci
163af6ab5fSopenharmony_ciimport { describe, it } from 'mocha';
173af6ab5fSopenharmony_ciimport { TransformerManager } from '../../../src/transformers/TransformerManager';
183af6ab5fSopenharmony_ciimport { expect, assert } from 'chai';
193af6ab5fSopenharmony_ciimport { IOptions } from '../../../src/configs/IOptions';
203af6ab5fSopenharmony_ciimport ts, {
213af6ab5fSopenharmony_ci    TransformerFactory,
223af6ab5fSopenharmony_ci    Node,
233af6ab5fSopenharmony_ci    TransformationContext,
243af6ab5fSopenharmony_ci    factory,
253af6ab5fSopenharmony_ci    SyntaxKind,
263af6ab5fSopenharmony_ci    CallExpression,
273af6ab5fSopenharmony_ci    Expression,
283af6ab5fSopenharmony_ci    CompilerOptions,
293af6ab5fSopenharmony_ci    EmitHelper,
303af6ab5fSopenharmony_ci    EmitHint,
313af6ab5fSopenharmony_ci    FunctionDeclaration,
323af6ab5fSopenharmony_ci    Identifier,
333af6ab5fSopenharmony_ci    Statement,
343af6ab5fSopenharmony_ci    SourceFile,
353af6ab5fSopenharmony_ci    VariableDeclaration,
363af6ab5fSopenharmony_ci  } from 'typescript';
373af6ab5fSopenharmony_ciimport { NodeUtils } from '../../../src/utils/NodeUtils';
383af6ab5fSopenharmony_ciimport path from 'path';
393af6ab5fSopenharmony_ciimport secharmony from '../../../src/transformers/rename/VirtualConstructorTransformer';
403af6ab5fSopenharmony_ci
413af6ab5fSopenharmony_cidescribe('Tester Cases for <virtualConstructorTransformerFactory>.', function () {
423af6ab5fSopenharmony_ci  let options: IOptions;
433af6ab5fSopenharmony_ci  let context: TransformationContext = {
443af6ab5fSopenharmony_ci    requestEmitHelper: function (helper: EmitHelper): void {},
453af6ab5fSopenharmony_ci    readEmitHelpers: function (): EmitHelper[] | undefined {
463af6ab5fSopenharmony_ci      return undefined;
473af6ab5fSopenharmony_ci    },
483af6ab5fSopenharmony_ci    enableSubstitution: function (kind: SyntaxKind): void {},
493af6ab5fSopenharmony_ci    isSubstitutionEnabled: function (node: Node): boolean {
503af6ab5fSopenharmony_ci      throw new Error('Function not implemented.');
513af6ab5fSopenharmony_ci    },
523af6ab5fSopenharmony_ci    onSubstituteNode: function (hint: EmitHint, node: Node): Node {
533af6ab5fSopenharmony_ci      throw new Error('Function not implemented.');
543af6ab5fSopenharmony_ci    },
553af6ab5fSopenharmony_ci    enableEmitNotification: function (kind: SyntaxKind): void {},
563af6ab5fSopenharmony_ci    isEmitNotificationEnabled: function (node: Node): boolean {
573af6ab5fSopenharmony_ci      throw new Error('Function not implemented.');
583af6ab5fSopenharmony_ci    },
593af6ab5fSopenharmony_ci    onEmitNode: function (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void {
603af6ab5fSopenharmony_ci      throw new Error('Function not implemented.');
613af6ab5fSopenharmony_ci    },
623af6ab5fSopenharmony_ci    factory: ts.factory,
633af6ab5fSopenharmony_ci    getCompilerOptions: function (): CompilerOptions {
643af6ab5fSopenharmony_ci      throw new Error('Function not implemented.');
653af6ab5fSopenharmony_ci    },
663af6ab5fSopenharmony_ci    startLexicalEnvironment: function (): void {},
673af6ab5fSopenharmony_ci    suspendLexicalEnvironment: function (): void {},
683af6ab5fSopenharmony_ci    resumeLexicalEnvironment: function (): void {},
693af6ab5fSopenharmony_ci    endLexicalEnvironment: function (): Statement[] | undefined {
703af6ab5fSopenharmony_ci      return undefined;
713af6ab5fSopenharmony_ci    },
723af6ab5fSopenharmony_ci    hoistFunctionDeclaration: function (node: FunctionDeclaration): void {},
733af6ab5fSopenharmony_ci    hoistVariableDeclaration: function (node: Identifier): void {}
743af6ab5fSopenharmony_ci  };
753af6ab5fSopenharmony_ci
763af6ab5fSopenharmony_ci  describe('Tester Cases for <virtualConstructorTransformerFactory>.', function () {
773af6ab5fSopenharmony_ci    it('should return virtualConstructorTransformer', function () {
783af6ab5fSopenharmony_ci        const transfomerFactory = secharmony.transformerPlugin.createTransformerFactory(options);
793af6ab5fSopenharmony_ci        expect(transfomerFactory).to.not.be.undefined;
803af6ab5fSopenharmony_ci    });
813af6ab5fSopenharmony_ci  });
823af6ab5fSopenharmony_ci
833af6ab5fSopenharmony_ci  describe('Tester Cases for <virtualConstructorTransformer>.', function () {
843af6ab5fSopenharmony_ci    it('should return node if is not DETSFile', function () {
853af6ab5fSopenharmony_ci      const sourceCode = `let a:number = 1;`;
863af6ab5fSopenharmony_ci      let sourcefile = ts.createSourceFile("a.ts", sourceCode, ts.ScriptTarget.ES2022, false);
873af6ab5fSopenharmony_ci      const transfomerFactory = secharmony.transformerPlugin.createTransformerFactory(options);
883af6ab5fSopenharmony_ci      const node = transfomerFactory(context)(sourcefile);
893af6ab5fSopenharmony_ci      expect(node).to.be.equal(sourcefile);
903af6ab5fSopenharmony_ci    });
913af6ab5fSopenharmony_ci
923af6ab5fSopenharmony_ci    it('should return node if is DETSFile but not StructDeclaration', function () {
933af6ab5fSopenharmony_ci      const sourceCode = `let a:number = 1;`;
943af6ab5fSopenharmony_ci      let sourcefile = ts.createSourceFile("a.d.ets", sourceCode, ts.ScriptTarget.ES2022, false);
953af6ab5fSopenharmony_ci      const transfomerFactory = secharmony.transformerPlugin.createTransformerFactory(options);
963af6ab5fSopenharmony_ci      const node = transfomerFactory(context)(sourcefile);
973af6ab5fSopenharmony_ci      expect(node).to.be.equal(sourcefile);
983af6ab5fSopenharmony_ci    });
993af6ab5fSopenharmony_ci
1003af6ab5fSopenharmony_ci    it('should return update node if is StructDeclaration', function () {
1013af6ab5fSopenharmony_ci      const sourceCode = `struct Demo{ };`;
1023af6ab5fSopenharmony_ci      let sourcefile = ts.createSourceFile("a.d.ets", sourceCode, ts.ScriptTarget.ES2022, false);
1033af6ab5fSopenharmony_ci      const transfomerFactory = secharmony.transformerPlugin.createTransformerFactory(options);
1043af6ab5fSopenharmony_ci      const node = transfomerFactory(context)(sourcefile);
1053af6ab5fSopenharmony_ci      expect(node).to.not.be.equal(sourcefile);
1063af6ab5fSopenharmony_ci    });
1073af6ab5fSopenharmony_ci  });
1083af6ab5fSopenharmony_ci});