1/*
2 * Copyright (c) 2023-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
16function main(): void {
17  {
18    let a: byte = 10;
19    let b = ++a;
20    assert a == 11;
21    assert b == 11;
22
23    assert ++a == 12;
24    assert a == 12;
25    assert b == 11;
26  }
27
28  {
29    let a: int = 20;
30    let b = a++;
31    assert a == 21;
32    assert b == 20;
33
34    assert a++ == 21;
35    assert a == 22;
36    assert b == 20;
37  }
38
39  {
40    let a: Double = new Double(30.0);
41    let b = ++a;
42    assert a == 31.0;
43    assert a.doubleValue() == 31.0;
44    assert b == 31.0;
45    assert b.doubleValue() == 31.0;
46
47    assert (++a).doubleValue() == 32.0;
48    assert a == 32.0;
49    assert a.doubleValue() == 32.0;
50    assert b == 31.0;
51    assert b.doubleValue() == 31.0;
52  }
53
54  {
55    let a: Int = new Int(40);
56    let b = a++;
57    assert a == 41;
58    assert a.intValue() == 41;
59    assert b == 40;
60    assert b.intValue() == 40;
61
62    assert (a++).intValue() == 41;
63    assert a == 42;
64    assert a.intValue() == 42;
65    assert b == 40;
66    assert b.intValue() == 40;
67  }
68
69  {
70    let fn: (x: Int) => Int = (x: Int): Int => { return x; };
71    let a: Int = new Int(50);
72    let b = fn(a++);
73    assert a == 51;
74    assert a.intValue() == 51;
75    assert b == 50;
76    assert b.intValue() == 50;
77
78    assert fn(++a) == 52;
79    assert a == 52;
80  }
81
82  {
83    let b: byte = 127;
84    assert ++b as int == -128;
85    assert --b as int == 127;
86
87    let c: char = 65535;
88    assert ++c as int == 0;
89    assert --c as int == 65535;
90
91    let s: short = 32767;
92    assert ++s as int == -32768;
93    assert --s as int == 32767;
94  }
95
96  {
97    let b: Int[] = [1, 2]
98    assert ++b[1] == 3
99    assert --b[1] == 2
100  }
101}
102