1/* 2 * Copyright (c) 2023-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 16enum Access { 17 READ = 1, 18 WRITE = 2, 19 READWRITE = 3 20} 21 22enum TestEnum { 23 A = 144, 24 B, 25 C = 795 26} 27 28function main(): void { 29 test_access_enum_bitwise(Access.WRITE); 30 assertEQ((Access.WRITE & Access.READWRITE), 2) 31 32 test_test_enum_bitwise(TestEnum.C); 33 assertEQ((TestEnum.B & TestEnum.A), 144) 34 35} 36 37function test_access_enum_bitwise(enum_val: Access): void { 38 assertEQ((enum_val & Access.READ), 0) 39 assertEQ((enum_val & Access.WRITE), 2) 40 assertEQ((enum_val | Access.READ), 3) 41 assertEQ((enum_val | Access.READWRITE), 3) 42 assertEQ((enum_val & Access.READWRITE), 2) 43} 44 45function test_test_enum_bitwise(enum_val: TestEnum): void { 46 assertEQ((enum_val & TestEnum.A), 16) 47 assertEQ((enum_val | TestEnum.A), 923) 48 assertEQ((enum_val & TestEnum.B), 17) 49 assertEQ((enum_val | TestEnum.B), 923) 50} 51