• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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
16import {describe, expect, test} from '@jest/globals';
17import { generateEnumDeclaration } from '../generate/generateEnumDeclaration';
18
19describe('generateEnumDeclaration.ts file test', (): void => {
20  test('Test the generateEnumDeclaration function', (): void => {
21    const enumDeclaration = {
22      enumName: 'ErrorCode',
23      exportModifiers: [92],
24      enumMembers: [
25        {
26          enumKind: 214,
27          enumValue: '-3',
28          enumValueName: 'PERMISSION_DENY'
29        },
30        {
31          enumKind: 214,
32          enumValue: '-2',
33          enumValueName: 'ABILITY_NOT_FOUND'
34        },
35        {
36          enumKind: 214,
37          enumValue: '-1',
38          enumValueName: 'INVALID_PARAMETER'
39        },
40        {
41          enumKind: 8,
42          enumValue: '0',
43          enumValueName: 'NO_ERROR'
44        }
45      ]
46    };
47    const result = generateEnumDeclaration('', enumDeclaration);
48    const expectedResult = `export const ErrorCode = {
49PERMISSION_DENY: -3,
50ABILITY_NOT_FOUND: -2,
51INVALID_PARAMETER: -1,
52NO_ERROR: 0,
53}
54`;
55    expect(result).toBe(expectedResult);
56  });
57});
58