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 OuterNamespace { 17 export function outerFunction() { 18 return "Outer function"; 19 } 20 21 export namespace InnerNamespace { 22 export function innerFunction() { 23 return "Inner function"; 24 } 25 26 export let sharedValue = 50; 27 28 // Utility function to reset the state of InnerNamespace 29 export function resetState() { 30 sharedValue = 50; // Reset sharedValue to its initial state 31 } 32 } 33 34 // Utility function to reset the state of OuterNamespace 35 export function resetOuterState() { 36 InnerNamespace.resetState(); 37 } 38} 39 40function main() { 41 // Reset OuterNamespace and InnerNamespace state before running tests 42 OuterNamespace.resetOuterState(); 43 44 // Test access to outer and inner namespace members 45 assertEQ(OuterNamespace.outerFunction(), "Outer function", "Outer function failed") 46 assertEQ(OuterNamespace.InnerNamespace.innerFunction(), "Inner function", "Inner function failed") 47 48 // Test modification of shared value in inner namespace 49 OuterNamespace.InnerNamespace.sharedValue = OuterNamespace.InnerNamespace.sharedValue + 25; 50 assertEQ(OuterNamespace.InnerNamespace.sharedValue, 75, "Shared value update failed") 51}