Skip to content

Commit 518b77c

Browse files
JSMonkSpace Team
authored andcommitted
[K/JS] Add a test for the ^KT-75606 issue
Merge-request: KT-MR-20438 Merged-by: Artem Kobzar <Artem.Kobzar@jetbrains.com>
1 parent 74fa833 commit 518b77c

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// MODULE: lib
2+
// FILE: lib.kt
3+
package foo
4+
5+
import kotlinx.js.JsPlainObject
6+
7+
@JsPlainObject
8+
external interface User {
9+
var name: String
10+
val age: Int
11+
}
12+
13+
@JsPlainObject
14+
external interface Admin {
15+
var email: String
16+
val level: Int
17+
}
18+
19+
// MODULE: main(lib)
20+
// FILE: main.kt
21+
package foo
22+
23+
fun box(): String {
24+
val user = User(name = "Name", age = 10)
25+
26+
if (user.name != "Name") return "Fail: problem with `name` property"
27+
if (user.age != 10) return "Fail: problem with `age` property"
28+
29+
val userJson = js("JSON.stringify(user)")
30+
if (userJson != "{\"name\":\"Name\",\"age\":10}") return "Fail: got the next json: $userJson"
31+
32+
val admin = Admin(email = "admin@admin.com", level = 0)
33+
34+
if (admin.email != "admin@admin.com") return "Fail: problem with `email` property"
35+
if (admin.level != 0) return "Fail: problem with `level` property"
36+
37+
val adminJson = js("JSON.stringify(admin)")
38+
if (adminJson != "{\"email\":\"admin@admin.com\",\"level\":0}") return "Fail: got the next json: $adminJson"
39+
40+
return "OK"
41+
}

plugins/js-plain-objects/compiler-plugin/tests-gen/org/jetbrains/kotlinx/jspo/runners/FirJsPlainObjectsIrJsBoxTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)