• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16type T0 = Object|null|undefined
17type F1<T> = (a:T, b:T) => void
18type F2<T> = null|undefined|(a:T, b:T) => void
19
20function equ<T>(a: T, b:T){
21  return a == b
22}
23
24function equs<T>(a: T, b:T){
25  return a === b
26}
27
28function nequ<T>(a: T, b:T){
29  return a != b
30}
31
32function nequs<T>(a: T, b:T){
33  return a !== b
34}
35
36class A {}
37
38function main() {
39  assertEQ(equ<T0>(null, undefined), true)
40  assertEQ(equs<T0>(null, undefined), false)
41
42  assertEQ(nequ<T0>(null, undefined), false)
43  assertEQ(nequs<T0>(null, undefined), true)
44
45  assertTrue(null == undefined)
46  assertNE(null, undefined)
47
48  assertTrue(!(null != undefined))
49  assertTrue(null !== undefined)
50
51  let f1 = (a:Int, b:Int) => { a=a-b; }
52  let f2 = (a:Int, b:Int) => { a=a+b; }
53
54  assertEQ(equ<F1<Int>>(f1, f1), true)
55  assertEQ(equ<F1<Int>>(f1, f2), false)
56  assertEQ(equs<F1<Int>>(f1, f1), true)
57  assertEQ(equs<F1<Int>>(f1, f2), false)
58
59  let a1 = new A()
60  let a2 = new A()
61
62  assertEQ(equs<T0>(a1, a1), true)
63  assertEQ(nequs<T0>(a1, a1), false)
64  assertEQ(equs<T0>(a1, a2), false)
65  assertEQ(nequs<T0>(a1, a2), true)
66
67  assertTrue(10 === 10)
68}
69