• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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/**---
16 description: >
17    when a namespace identifier is referenced as a NamespaceName it denotes a container of namespace and type names, and when a namespace identifier is referenced as a PrimaryExpression it denotes the singleton namespace instance.
18 module: ESNext
19 isCurrent: true
20 ---*/
21
22
23import { Assert } from '../../../../suite/assert.js'
24
25namespace A {
26   export interface TypeA {
27      AName: string;
28      Lv: number;
29      UID: number;
30   }
31   export var player: TypeA = { AName: "Player", Lv: 5, UID: 0x0000A0F0 };
32   export var playerRandom: TypeA = { AName: "playerRandom", Lv: getRandomNumber(99), UID: getRandomNumber(0xFFFFFFFF) };
33   function getRandomNumber(x: number): number {
34      return Math.floor(Math.random() * x);
35   }
36}
37var playerA = A.player;
38var playerB = A.playerRandom;
39var an = A;
40var playerC: A.TypeA = { AName: "PlayerC", Lv: 95, UID: 6250 };
41var playerD = an.player;
42Assert.equal(playerA.AName, "Player");
43Assert.equal(playerA.Lv, 5);
44Assert.equal(playerA.UID, 41200);
45Assert.equal(playerB.AName, "playerRandom");
46Assert.isNumber(playerB.Lv);
47Assert.isNumber(playerB.UID);
48Assert.equal(playerC.AName, "PlayerC");
49Assert.equal(playerC.Lv, 95);
50Assert.equal(playerC.UID, 6250);
51Assert.equal(playerD.AName, "Player");
52Assert.equal(playerD.Lv, 5);
53Assert.equal(playerD.UID, 41200);
54