|
1 | 1 | import Testing |
2 | 2 | import JavaScriptKit |
3 | 3 |
|
| 4 | +@JSClass struct AsyncImportImports { |
| 5 | + @JSFunction static func jsAsyncRoundTripVoid() async throws(JSException) |
| 6 | + @JSFunction static func jsAsyncRoundTripNumber(_ v: Double) async throws(JSException) -> Double |
| 7 | + @JSFunction static func jsAsyncRoundTripBool(_ v: Bool) async throws(JSException) -> Bool |
| 8 | + @JSFunction static func jsAsyncRoundTripString(_ v: String) async throws(JSException) -> String |
| 9 | + @JSFunction static func jsAsyncRoundTripOptionalString(_ v: String?) async throws(JSException) -> String? |
| 10 | + @JSFunction static func jsAsyncRoundTripOptionalNumber(_ v: Double?) async throws(JSException) -> Double? |
| 11 | + @JSFunction static func jsAsyncRoundTripBoolArray(_ values: [Bool]) async throws(JSException) -> [Bool] |
| 12 | + @JSFunction static func jsAsyncRoundTripIntArray(_ values: [Double]) async throws(JSException) -> [Double] |
| 13 | + @JSFunction static func jsAsyncRoundTripStringArray(_ values: [String]) async throws(JSException) -> [String] |
| 14 | + @JSFunction static func jsAsyncRoundTripFeatureFlag(_ v: FeatureFlag) async throws(JSException) -> FeatureFlag |
| 15 | + @JSFunction static func fetchWeatherData(_ city: String) async throws(JSException) -> WeatherData |
| 16 | +} |
| 17 | + |
4 | 18 | @Suite struct AsyncImportTests { |
5 | 19 | @Test func asyncRoundTripVoid() async throws { |
6 | | - try await jsAsyncRoundTripVoid() |
| 20 | + try await AsyncImportImports.jsAsyncRoundTripVoid() |
7 | 21 | } |
8 | 22 |
|
9 | 23 | @Test(arguments: [0.0, 1.0, -1.0, Double.pi, Double.infinity]) |
10 | 24 | func asyncRoundTripNumber(v: Double) async throws { |
11 | | - try #expect(await jsAsyncRoundTripNumber(v) == v) |
| 25 | + try #expect(await AsyncImportImports.jsAsyncRoundTripNumber(v) == v) |
12 | 26 | } |
13 | 27 |
|
14 | 28 | @Test(arguments: [true, false]) |
15 | 29 | func asyncRoundTripBool(v: Bool) async throws { |
16 | | - try #expect(await jsAsyncRoundTripBool(v) == v) |
| 30 | + try #expect(await AsyncImportImports.jsAsyncRoundTripBool(v) == v) |
17 | 31 | } |
18 | 32 |
|
19 | 33 | @Test(arguments: ["", "Hello, world!", "🧑🧑🧒"]) |
20 | 34 | func asyncRoundTripString(v: String) async throws { |
21 | | - try #expect(await jsAsyncRoundTripString(v) == v) |
| 35 | + try #expect(await AsyncImportImports.jsAsyncRoundTripString(v) == v) |
22 | 36 | } |
23 | 37 |
|
24 | 38 | // MARK: - Stack ABI types |
25 | 39 |
|
26 | 40 | @Test(arguments: ["hello" as String?, nil, "🧑🧑🧒" as String?]) |
27 | 41 | func asyncRoundTripOptionalString(v: String?) async throws { |
28 | | - try #expect(await jsAsyncRoundTripOptionalString(v) == v) |
| 42 | + try #expect(await AsyncImportImports.jsAsyncRoundTripOptionalString(v) == v) |
29 | 43 | } |
30 | 44 |
|
31 | 45 | @Test(arguments: [42.0 as Double?, nil, 0.0 as Double?]) |
32 | 46 | func asyncRoundTripOptionalNumber(v: Double?) async throws { |
33 | | - try #expect(await jsAsyncRoundTripOptionalNumber(v) == v) |
| 47 | + try #expect(await AsyncImportImports.jsAsyncRoundTripOptionalNumber(v) == v) |
34 | 48 | } |
35 | 49 |
|
36 | 50 | @Test func asyncRoundTripBoolArray() async throws { |
37 | 51 | let values: [Bool] = [true, false, true] |
38 | | - try #expect(await jsAsyncRoundTripBoolArray(values) == values) |
39 | | - try #expect(await jsAsyncRoundTripBoolArray([]) == []) |
| 52 | + try #expect(await AsyncImportImports.jsAsyncRoundTripBoolArray(values) == values) |
| 53 | + try #expect(await AsyncImportImports.jsAsyncRoundTripBoolArray([]) == []) |
40 | 54 | } |
41 | 55 |
|
42 | 56 | @Test func asyncRoundTripIntArray() async throws { |
43 | 57 | let values: [Double] = [1, 2, 3, 4, 5] |
44 | | - try #expect(await jsAsyncRoundTripIntArray(values) == values) |
45 | | - try #expect(await jsAsyncRoundTripIntArray([]) == []) |
| 58 | + try #expect(await AsyncImportImports.jsAsyncRoundTripIntArray(values) == values) |
| 59 | + try #expect(await AsyncImportImports.jsAsyncRoundTripIntArray([]) == []) |
46 | 60 | } |
47 | 61 |
|
48 | 62 | @Test func asyncRoundTripStringArray() async throws { |
49 | 63 | let values = ["Hello", "World", "🎉"] |
50 | | - try #expect(await jsAsyncRoundTripStringArray(values) == values) |
51 | | - try #expect(await jsAsyncRoundTripStringArray([]) == []) |
| 64 | + try #expect(await AsyncImportImports.jsAsyncRoundTripStringArray(values) == values) |
| 65 | + try #expect(await AsyncImportImports.jsAsyncRoundTripStringArray([]) == []) |
52 | 66 | } |
53 | 67 |
|
54 | 68 | @Test(arguments: [FeatureFlag.foo, .bar]) |
55 | 69 | func asyncRoundTripFeatureFlag(v: FeatureFlag) async throws { |
56 | | - try #expect(await jsAsyncRoundTripFeatureFlag(v) == v) |
| 70 | + try #expect(await AsyncImportImports.jsAsyncRoundTripFeatureFlag(v) == v) |
57 | 71 | } |
58 | 72 |
|
59 | 73 | // MARK: - Structured return type |
60 | 74 |
|
61 | 75 | @Test func fetchWeatherData() async throws { |
62 | | - let weather = try await BridgeJSRuntimeTests.fetchWeatherData("London") |
| 76 | + let weather = try await AsyncImportImports.fetchWeatherData("London") |
63 | 77 | #expect(try weather.temperature == 15.5) |
64 | 78 | #expect(try weather.description == "Cloudy") |
65 | 79 | #expect(try weather.humidity == 80) |
66 | 80 |
|
67 | | - let weather2 = try await BridgeJSRuntimeTests.fetchWeatherData("Tokyo") |
| 81 | + let weather2 = try await AsyncImportImports.fetchWeatherData("Tokyo") |
68 | 82 | #expect(try weather2.temperature == 25.0) |
69 | 83 | #expect(try weather2.description == "Sunny") |
70 | 84 | #expect(try weather2.humidity == 40) |
|
0 commit comments