1/* 2 * Copyright (c) 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 16 17function foo(a: int): double { 18 return a.toDouble() + 10.5; 19} 20 21function main() { 22 let b: byte = 1 23 let c: char = c'a' 24 let s: short = 5 25 let i: int = 25 26 let l: long = 125 27 let f: float = 2.71f 28 let d: double = 3.14 29 30 // byte 31 assertEQ(b.toChar(), c'\u0001') 32 assertEQ(b.toShort(), 1 as short) 33 assertEQ(b.toInt(), 1 as int) 34 assertEQ(b.toLong(), 1 as long) 35 assertEQ(b.toFloat(), 1.0f) 36 assertEQ(b.toDouble(),1.0) 37 38 // short 39 assertEQ(s.toByte(), 5 as byte) 40 assertEQ(s.toChar(), c'\u0005') 41 assertEQ(s.toInt(), 5 as int) 42 assertEQ(s.toLong(), 5 as long) 43 assertEQ(s.toFloat(), 5.0f) 44 assertEQ(s.toDouble(),5.0) 45 46 // int 47 assertEQ(i.toByte(), 25 as byte) 48 assertEQ(i.toChar(), c'\u0019') 49 assertEQ(i.toShort(), 25 as short) 50 assertEQ(i.toLong(), 25 as long) 51 assertEQ(i.toFloat(), 25.0f) 52 assertEQ(i.toDouble(),25.0) 53 54 assertEQ(foo(i), 35.5) 55 56 // long 57 assertEQ(l.toByte(), 125 as byte) 58 assertEQ(l.toChar(), c'\u007d') 59 assertEQ(l.toShort(), 125 as short) 60 assertEQ(l.toInt(), 125 as int) 61 assertEQ(l.toFloat(), 125.0f) 62 assertEQ(l.toDouble(),125.0) 63 64 // float 65 assertEQ(f.toByte(), 2 as byte) 66 assertEQ(f.toShort(), 2 as short) 67 assertEQ(f.toInt(), 2 as int) 68 assertEQ(f.toLong(), 2.0 as long) 69 assertEQ(f.toDouble(),2.71f as double) 70 71 // double 72 assertEQ(d.toByte(), 3 as byte) 73 assertEQ(d.toShort(), 3 as short) 74 assertEQ(d.toInt(), 3 as int) 75 assertEQ(d.toLong(), 3.0 as long) 76 assertEQ(d.toFloat(), 3.14f) 77} 78