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 { generateVariableStatementDelcatation } from '../generate/generateVariableStatementDeclaration'; 18 19describe('generateVariableStatementDeclaration.ts file test', () => { 20 test('Test statementEntity.typeKind is SyntaxKind.TypeReference', () => { 21 const statementEntity = { 22 statementName: 'daltonizationState', 23 typeName: 'Config<boolean>', 24 typeKind: 173, 25 initializer: '', 26 } 27 const isInnerModule = false; 28 const result = generateVariableStatementDelcatation(statementEntity, isInnerModule); 29 expect(result).toBe('daltonizationState: Config,'); 30 }); 31 32 test('Test statementEntity.typeKind is SyntaxKind.NumberKeyword', () => { 33 const statementEntity = { 34 statementName: 'batteryTemperature', 35 typeName: 'number', 36 typeKind: 144, 37 initializer: '', 38 } 39 const isInnerModule = false; 40 const result = generateVariableStatementDelcatation(statementEntity, isInnerModule); 41 expect(result).toBe('batteryTemperature: 0,'); 42 }); 43 44 test('Test statementEntity.typeKind is SyntaxKind.StringKeyword', () => { 45 const statementEntity = { 46 statementName: 'technology', 47 typeName: 'string', 48 typeKind: 147, 49 initializer: '', 50 } 51 const isInnerModule = false; 52 const result = generateVariableStatementDelcatation(statementEntity, isInnerModule); 53 expect(result).toBe('technology: \'\','); 54 }); 55 56 test('Test statementEntity.typeKind is SyntaxKind.BooleanKeyword', () => { 57 const statementEntity = { 58 statementName: 'isBatteryPresent', 59 typeName: 'boolean', 60 typeKind: 131, 61 initializer: '', 62 } 63 const isInnerModule = false; 64 const result = generateVariableStatementDelcatation(statementEntity, isInnerModule); 65 expect(result).toBe('isBatteryPresent: true,'); 66 }); 67 68 test('Test statementEntity.typeKind is SyntaxKind.StringLiteral', () => { 69 const statementEntity = { 70 statementName: 'DATA_CHANGE_EVENT_ID', 71 typeName: '', 72 typeKind: 10, 73 initializer: 'cloud_data_change', 74 } 75 const isInnerModule = false; 76 const result = generateVariableStatementDelcatation(statementEntity, isInnerModule); 77 expect(result).toBe('DATA_CHANGE_EVENT_ID: cloud_data_change,'); 78 }); 79 80 test('Test statementEntity.typeKind is SyntaxKind.NumericLiteral', () => { 81 const statementEntity = { 82 statementName: 'MAX_KEY_LENGTH', 83 typeName: '', 84 typeKind: 8, 85 initializer: '1024', 86 } 87 const isInnerModule = false; 88 const result = generateVariableStatementDelcatation(statementEntity, isInnerModule); 89 expect(result).toBe('MAX_KEY_LENGTH: 1024,'); 90 }); 91 92 test('Test statementEntity.typeKind is SyntaxKind.LiteralType', () => { 93 const statementEntity = { 94 statementName: 'MAX_KEY_LENGTH', 95 typeName: '80', 96 typeKind: 191, 97 initializer: '', 98 } 99 const isInnerModule = false; 100 const result = generateVariableStatementDelcatation(statementEntity, isInnerModule); 101 expect(result).toBe('MAX_KEY_LENGTH: 80,'); 102 }); 103});