-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathExportAPITests.swift
More file actions
86 lines (73 loc) · 2.06 KB
/
ExportAPITests.swift
File metadata and controls
86 lines (73 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import XCTest
import JavaScriptKit
@_extern(wasm, module: "BridgeJSRuntimeTests", name: "runJsWorks")
@_extern(c)
func runJsWorks() -> Void
@JS func roundTripVoid() -> Void {
return
}
@JS func roundTripInt(v: Int) -> Int {
return v
}
@JS func roundTripFloat(v: Float) -> Float {
return v
}
@JS func roundTripDouble(v: Double) -> Double {
return v
}
@JS func roundTripBool(v: Bool) -> Bool {
return v
}
@JS func roundTripString(v: String) -> String {
return v
}
@JS func roundTripSwiftHeapObject(v: Greeter) -> Greeter {
return v
}
@JS func roundTripJSObject(v: JSObject) -> JSObject {
return v
}
struct TestError: Error {
let message: String
}
@JS func throwsSwiftError(shouldThrow: Bool) throws(JSException) -> Void {
if shouldThrow {
throw JSException(JSError(message: "TestError").jsValue)
}
}
@JS func throwsWithIntResult() throws(JSException) -> Int { return 1 }
@JS func throwsWithStringResult() throws(JSException) -> String { return "Ok" }
@JS func throwsWithBoolResult() throws(JSException) -> Bool { return true }
@JS func throwsWithFloatResult() throws(JSException) -> Float { return 1.0 }
@JS func throwsWithDoubleResult() throws(JSException) -> Double { return 1.0 }
@JS func throwsWithSwiftHeapObjectResult() throws(JSException) -> Greeter { return Greeter(name: "Test") }
@JS func throwsWithJSObjectResult() throws(JSException) -> JSObject { return JSObject() }
@JS class Greeter {
var name: String
nonisolated(unsafe) static var onDeinit: () -> Void = {}
@JS init(name: String) {
self.name = name
}
@JS func greet() -> String {
return "Hello, \(name)!"
}
@JS func changeName(name: String) {
self.name = name
}
deinit {
Self.onDeinit()
}
}
@JS func takeGreeter(g: Greeter, name: String) {
g.changeName(name: name)
}
class ExportAPITests: XCTestCase {
func testAll() {
var hasDeinitGreeter = false
Greeter.onDeinit = {
hasDeinitGreeter = true
}
runJsWorks()
XCTAssertTrue(hasDeinitGreeter)
}
}