• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# coding=utf-8
2#
3# Copyright (c) 2025 Huawei Device Co., Ltd.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from taihe.codegen.abi.mangle import DeclKind, decode, encode
17
18
19def test_name_mangler():
20    """Comprehensive test suite for NameMangler."""
21    test_cases = [
22        (["a", "b_c", "d", "e_f_g"], DeclKind.FUNC),
23        (["x", "y", "z"], DeclKind.TYPE),
24        (["a_b_c"], DeclKind.FUNC),
25        (["a"], DeclKind.FUNC),
26        (["a_b", "c_d_e"], DeclKind.FUNC),
27        (["test", "with____multiple", "consecutive"], DeclKind.FUNC),
28    ]
29
30    for segments, kind in test_cases:
31        try:
32            mangled = encode(segments, kind)
33            decoded = decode(mangled)
34            pass
35            print(f"Success: {segments} -> {mangled} -> {decoded}")
36        except Exception as e:
37            print(f"Error testing {segments}: {e!s}")