• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    Lda,
23    VReg
24} from "../src/irnodes";
25import { checkInstructions, compileMainSnippet, SnippetCompiler } from "./utils/base";
26import { CmdOptions } from '../src/cmdOptions';
27
28describe("BuiltInsTest", function () {
29    it("Global Value Properties", function () {
30        let insns = compileMainSnippet(`NaN; Infinity; globalThis;`);
31        let expected = [
32            new Lda(new VReg()),
33            new Lda(new VReg()),
34            new Lda(new VReg()),
35
36            new Returnundefined()
37        ];
38        expect(checkInstructions(insns, expected)).to.be.true;
39    });
40});
41
42describe("FunctionToStringTest", function () {
43    it("func.toString()", function () {
44        CmdOptions.needRecordSourceCode = () => {return true};
45        let snippetCompiler = new SnippetCompiler();
46        snippetCompiler.compileAfter(`function foo() {return 123;}\nfunction bar() {return 321;}\n`, 'toStringTest.js');
47        CmdOptions.needRecordSourceCode = () => {return false};
48        let pandaGen = snippetCompiler.getPandaGenByName('UnitTest.foo');
49        let expected = "function foo() {return 123;}";
50        expect(pandaGen.getSourceCode() == expected).to.be.true;
51    })
52})
53