1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { 17 expect 18} from 'chai'; 19import 'mocha'; 20import { 21 Returnundefined, 22 Sttoglobalrecord, 23 Tryldglobalbyname, 24 Lda, 25 VReg, 26 Imm, 27 IRNode 28} from "../../src/irnodes"; 29import { checkInstructions, compileMainSnippet } from "../utils/base"; 30import { creatAstFromSnippet } from "../utils/asthelper" 31import { PandaGen } from '../../src/pandagen'; 32 33describe("ParenthesizedExpressionTest", function () { 34 it("(a)", function () { 35 let insns = compileMainSnippet("let a; (a);"); 36 IRNode.pg = new PandaGen("", creatAstFromSnippet("let a; (a);"), 0, undefined); 37 38 let a = new VReg(); 39 let expected = [ 40 new Lda(new VReg()), 41 new Sttoglobalrecord(new Imm(0), 'a'), 42 new Tryldglobalbyname(new Imm(1), 'a'), 43 new Returnundefined() 44 ]; 45 expect(checkInstructions(insns, expected)).to.be.true; 46 }); 47 48 it("(((a)))", function () { 49 let insns = compileMainSnippet("let a; (((a)))"); 50 IRNode.pg = new PandaGen("", creatAstFromSnippet("let a; (((a)))"), 0, undefined); 51 let a = new VReg(); 52 let expected = [ 53 new Lda(new VReg()), 54 new Sttoglobalrecord(new Imm(0), 'a'), 55 new Tryldglobalbyname(new Imm(1), 'a'), 56 new Returnundefined() 57 ]; 58 expect(checkInstructions(insns, expected)).to.be.true; 59 }); 60});