• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-2025 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
16namespace BasicNamespace {
17    // Exported members
18    export function greet() {
19        return "Hello, BasicNamespace!";
20    }
21
22    export let counter = 0;
23    export const maxCounter = 100;
24
25    export function incrementCounter() {
26        if (counter < maxCounter) {
27            counter++;
28        }
29    }
30}
31
32function main() {
33    // Reset counter to ensure clean state for each execution
34    BasicNamespace.counter = 0;
35
36    // Test access to namespace members
37    assertEQ(BasicNamespace.greet(), "Hello, BasicNamespace!",  "Namespace function failed")
38    assertEQ(BasicNamespace.counter, 0,  "Initial counter value is incorrect")
39
40    // Test function usage and variable updates
41    BasicNamespace.incrementCounter();
42    assertEQ(BasicNamespace.counter, 1,  "Counter increment failed")
43}
44