[K/JS] Prepare JS Plain Objects plugin to publication
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
import kotlinx.js.JsPlainObject
|
||||
|
||||
@JsPlainObject
|
||||
external interface User {
|
||||
var name: String
|
||||
val age: Int
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val user = User(name = "Name", age = 10)
|
||||
val copy = user.copy(age = 11)
|
||||
|
||||
if (copy === user) return "Fail: mutation instead of immutable copy"
|
||||
|
||||
val json = js("JSON.stringify(copy)")
|
||||
|
||||
if (copy.name != "Name") return "Fail: problem with copied `name` property"
|
||||
if (copy.age != 11) return "Fail: problem with copied `age` property"
|
||||
|
||||
if (json != "{\"age\":11,\"name\":\"Name\"}") return "Fail: got the next json for the copy: $json"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
import kotlinx.js.JsPlainObject
|
||||
|
||||
@JsPlainObject
|
||||
external interface User {
|
||||
var name: String
|
||||
val age: Int
|
||||
val email: String?
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val user = User(name = "Name", age = 10)
|
||||
|
||||
if (user.name != "Name") return "Fail: problem with `name` property"
|
||||
if (user.age != 10) return "Fail: problem with `age` property"
|
||||
|
||||
val json = js("JSON.stringify(user)")
|
||||
if (json != "{\"email\":null,\"age\":10,\"name\":\"Name\"}") return "Fail: got the next json: $json"
|
||||
|
||||
val withEmail = User(name = "Name", age = 10, email = "test@test")
|
||||
|
||||
if (withEmail.name != "Name") return "Fail: problem with emailed `name` property"
|
||||
if (withEmail.age != 10) return "Fail: problem with emailed `age` property"
|
||||
if (withEmail.email != "test@test") return "Fail: problem with emailed `email` property"
|
||||
|
||||
val jsonWithEmail = js("JSON.stringify(withEmail)")
|
||||
if (jsonWithEmail != "{\"email\":\"test@test\",\"age\":10,\"name\":\"Name\"}") return "Fail: got the next emailed json: $jsonWithEmail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
import kotlinx.js.JsPlainObject
|
||||
|
||||
@JsPlainObject
|
||||
external interface User {
|
||||
var name: String
|
||||
val age: Int
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val user = User(name = "Name", age = 10)
|
||||
|
||||
if (user.name != "Name") return "Fail: problem with `name` property"
|
||||
if (user.age != 10) return "Fail: problem with `age` property"
|
||||
|
||||
val json = js("JSON.stringify(user)")
|
||||
if (json != "{\"age\":10,\"name\":\"Name\"}") return "Fail: got the next json: $json"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
import kotlinx.js.JsPlainObject
|
||||
|
||||
@JsPlainObject
|
||||
external interface User {
|
||||
var name: String
|
||||
val age: Int
|
||||
}
|
||||
|
||||
@JsPlainObject
|
||||
external interface ExtendedUser : User {
|
||||
val email: String
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
val user = ExtendedUser(name = "Name", age = 10, email = "test@test")
|
||||
|
||||
if (user.name != "Name") return "Fail: problem with `name` property"
|
||||
if (user.age != 10) return "Fail: problem with `age` property"
|
||||
if (user.email != "test@test") return "Fail: problem with `email` property"
|
||||
|
||||
val json = js("JSON.stringify(user)")
|
||||
if (json != "{\"age\":10,\"name\":\"Name\",\"email\":\"test@test\"}") return "Fail: got the next json: $json"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package foo
|
||||
|
||||
import kotlinx.js.JsPlainObject
|
||||
|
||||
@JsPlainObject
|
||||
external interface User {
|
||||
var name: String
|
||||
val age: Int
|
||||
}
|
||||
|
||||
@JsPlainObject
|
||||
external interface Role {
|
||||
val role: String
|
||||
}
|
||||
|
||||
@JsPlainObject
|
||||
external interface ExtendedUser : User, Role {
|
||||
val email: String
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val user = ExtendedUser(name = "Name", age = 10, email = "test@test", role = "Admin")
|
||||
|
||||
if (user.name != "Name") return "Fail: problem with `name` property"
|
||||
if (user.age != 10) return "Fail: problem with `age` property"
|
||||
if (user.email != "test@test") return "Fail: problem with `email` property"
|
||||
if (user.role != "Admin") return "Fail: problem with `role` property"
|
||||
|
||||
val json = js("JSON.stringify(user)")
|
||||
if (json != "{\"age\":10,\"name\":\"Name\",\"role\":\"Admin\",\"email\":\"test@test\"}") return "Fail: got the next json: $json"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
|
||||
// FILE: test.kt
|
||||
import kotlinx.js.JsPlainObject
|
||||
|
||||
external interface A
|
||||
|
||||
external interface B
|
||||
|
||||
external interface C
|
||||
|
||||
@JsPlainObject
|
||||
external interface D : <!JS_PLAIN_OBJECT_CAN_EXTEND_ONLY_OTHER_JS_PLAIN_OBJECTS!>A<!>, <!JS_PLAIN_OBJECT_CAN_EXTEND_ONLY_OTHER_JS_PLAIN_OBJECTS!>B<!>, <!JS_PLAIN_OBJECT_CAN_EXTEND_ONLY_OTHER_JS_PLAIN_OBJECTS!>C<!>
|
||||
|
||||
@JsPlainObject
|
||||
external interface E
|
||||
|
||||
@JsPlainObject
|
||||
external interface F
|
||||
|
||||
@JsPlainObject
|
||||
external interface DEF: D, E, F
|
||||
|
||||
external interface G: A, C, <!IMPLEMENTING_OF_JS_PLAIN_OBJECT_IS_NOT_SUPPORTED!>E<!>
|
||||
|
||||
class Foo : A, <!IMPLEMENTING_OF_JS_PLAIN_OBJECT_IS_NOT_SUPPORTED!>D<!>, B
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
|
||||
// FILE: test.kt
|
||||
import kotlinx.js.JsPlainObject
|
||||
|
||||
@JsPlainObject
|
||||
external interface Foo {
|
||||
val foo: String
|
||||
val bar: Int?
|
||||
val fn: () -> String
|
||||
val fnOptional: (() -> String)?
|
||||
|
||||
<!METHODS_ARE_NOT_ALLOWED_INSIDE_JS_PLAIN_OBJECT!>fun test(): String<!>
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// FIR_IDENTICAL
|
||||
// SKIP_TXT
|
||||
|
||||
// FILE: test.kt
|
||||
import kotlinx.js.JsPlainObject
|
||||
|
||||
<!NON_EXTERNAL_DECLARATIONS_NOT_SUPPORTED("class")!>@JsPlainObject
|
||||
class Regular1<!>
|
||||
|
||||
@JsPlainObject
|
||||
<!NON_EXTERNAL_DECLARATIONS_NOT_SUPPORTED("object")!>object Regular2<!>
|
||||
|
||||
<!NON_EXTERNAL_DECLARATIONS_NOT_SUPPORTED("enum class")!>@JsPlainObject
|
||||
enum class Regular3<!>
|
||||
|
||||
<!ONLY_INTERFACES_ARE_SUPPORTED("class")!>@JsPlainObject
|
||||
external class External1<!>
|
||||
|
||||
@JsPlainObject
|
||||
external <!ONLY_INTERFACES_ARE_SUPPORTED("object")!>object External2<!>
|
||||
|
||||
@JsPlainObject
|
||||
external interface External3
|
||||
|
||||
external class Nested {
|
||||
@JsPlainObject
|
||||
interface Inner
|
||||
}
|
||||
Reference in New Issue
Block a user