Skip to content

Commit b083415

Browse files
committed
Add test with nullable argument
1 parent 72c73a6 commit b083415

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.usvm.samples.lang
2+
3+
import org.jacodb.ets.model.EtsScene
4+
import org.usvm.api.TsTestValue
5+
import org.usvm.util.TsMethodTestRunner
6+
import org.usvm.util.eq
7+
import kotlin.test.Test
8+
9+
class Optional : TsMethodTestRunner() {
10+
private val tsPath = "/samples/lang/Optional.ts"
11+
12+
override val scene: EtsScene = loadScene(tsPath)
13+
14+
@Test
15+
fun `test nullableArgument`() {
16+
val method = getMethod("nullableArgument")
17+
discoverProperties<TsTestValue, TsTestValue.TsNumber>(
18+
method = method,
19+
{ x, r -> (r eq 0) && (x is TsTestValue.TsUndefined) },
20+
{ x, r -> (r eq 0) && (x is TsTestValue.TsNull) },
21+
{ x, r -> (r eq 1) && (x is TsTestValue.TsNumber) && (x eq 1) },
22+
{ x, r -> (r eq 2) && (x is TsTestValue.TsNumber) && (x eq 2) },
23+
{ x, r -> (r eq 10) && (x is TsTestValue.TsNumber) },
24+
)
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @ts-nocheck
2+
// noinspection JSUnusedGlobalSymbols
3+
4+
class Optional {
5+
nullableArgument(x: number | null): number {
6+
let value: number = 42;
7+
if (x === undefined) return 0;
8+
if (x !== null) {
9+
if (x === 1) return x; // 1
10+
value = x;
11+
if (x === 2) return value; // 2
12+
return 10;
13+
}
14+
return 0;
15+
}
16+
}

0 commit comments

Comments
 (0)