Skip to content

Commit 67ff8e6

Browse files
committed
Use namespaced import
1 parent 695a715 commit 67ff8e6

File tree

7 files changed

+650
-962
lines changed

7 files changed

+650
-962
lines changed

Tests/BridgeJSRuntimeTests/AsyncImportTests.swift

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,84 @@
11
import Testing
22
import JavaScriptKit
33

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+
418
@Suite struct AsyncImportTests {
519
@Test func asyncRoundTripVoid() async throws {
6-
try await jsAsyncRoundTripVoid()
20+
try await AsyncImportImports.jsAsyncRoundTripVoid()
721
}
822

923
@Test(arguments: [0.0, 1.0, -1.0, Double.pi, Double.infinity])
1024
func asyncRoundTripNumber(v: Double) async throws {
11-
try #expect(await jsAsyncRoundTripNumber(v) == v)
25+
try #expect(await AsyncImportImports.jsAsyncRoundTripNumber(v) == v)
1226
}
1327

1428
@Test(arguments: [true, false])
1529
func asyncRoundTripBool(v: Bool) async throws {
16-
try #expect(await jsAsyncRoundTripBool(v) == v)
30+
try #expect(await AsyncImportImports.jsAsyncRoundTripBool(v) == v)
1731
}
1832

1933
@Test(arguments: ["", "Hello, world!", "🧑‍🧑‍🧒"])
2034
func asyncRoundTripString(v: String) async throws {
21-
try #expect(await jsAsyncRoundTripString(v) == v)
35+
try #expect(await AsyncImportImports.jsAsyncRoundTripString(v) == v)
2236
}
2337

2438
// MARK: - Stack ABI types
2539

2640
@Test(arguments: ["hello" as String?, nil, "🧑‍🧑‍🧒" as String?])
2741
func asyncRoundTripOptionalString(v: String?) async throws {
28-
try #expect(await jsAsyncRoundTripOptionalString(v) == v)
42+
try #expect(await AsyncImportImports.jsAsyncRoundTripOptionalString(v) == v)
2943
}
3044

3145
@Test(arguments: [42.0 as Double?, nil, 0.0 as Double?])
3246
func asyncRoundTripOptionalNumber(v: Double?) async throws {
33-
try #expect(await jsAsyncRoundTripOptionalNumber(v) == v)
47+
try #expect(await AsyncImportImports.jsAsyncRoundTripOptionalNumber(v) == v)
3448
}
3549

3650
@Test func asyncRoundTripBoolArray() async throws {
3751
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([]) == [])
4054
}
4155

4256
@Test func asyncRoundTripIntArray() async throws {
4357
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([]) == [])
4660
}
4761

4862
@Test func asyncRoundTripStringArray() async throws {
4963
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([]) == [])
5266
}
5367

5468
@Test(arguments: [FeatureFlag.foo, .bar])
5569
func asyncRoundTripFeatureFlag(v: FeatureFlag) async throws {
56-
try #expect(await jsAsyncRoundTripFeatureFlag(v) == v)
70+
try #expect(await AsyncImportImports.jsAsyncRoundTripFeatureFlag(v) == v)
5771
}
5872

5973
// MARK: - Structured return type
6074

6175
@Test func fetchWeatherData() async throws {
62-
let weather = try await BridgeJSRuntimeTests.fetchWeatherData("London")
76+
let weather = try await AsyncImportImports.fetchWeatherData("London")
6377
#expect(try weather.temperature == 15.5)
6478
#expect(try weather.description == "Cloudy")
6579
#expect(try weather.humidity == 80)
6680

67-
let weather2 = try await BridgeJSRuntimeTests.fetchWeatherData("Tokyo")
81+
let weather2 = try await AsyncImportImports.fetchWeatherData("Tokyo")
6882
#expect(try weather2.temperature == 25.0)
6983
#expect(try weather2.description == "Sunny")
7084
#expect(try weather2.humidity == 40)

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,6 @@ extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {}
4343

4444
@JSFunction func runAsyncWorks() async throws(JSException) -> Void
4545

46-
@JSFunction func jsAsyncRoundTripVoid() async throws(JSException) -> Void
47-
48-
@JSFunction func jsAsyncRoundTripNumber(_ v: Double) async throws(JSException) -> Double
49-
50-
@JSFunction func jsAsyncRoundTripBool(_ v: Bool) async throws(JSException) -> Bool
51-
52-
@JSFunction func jsAsyncRoundTripString(_ v: String) async throws(JSException) -> String
53-
54-
@JSFunction func fetchWeatherData(_ city: String) async throws(JSException) -> WeatherData
55-
56-
@JSClass struct WeatherData {
57-
@JSGetter var temperature: Double
58-
@JSSetter func setTemperature(_ value: Double) throws(JSException)
59-
@JSGetter var description: String
60-
@JSSetter func setDescription(_ value: String) throws(JSException)
61-
@JSGetter var humidity: Double
62-
@JSSetter func setHumidity(_ value: Double) throws(JSException)
63-
}
64-
65-
@JSFunction func jsAsyncRoundTripOptionalString(_ v: Optional<String>) async throws(JSException) -> Optional<String>
66-
67-
@JSFunction func jsAsyncRoundTripOptionalNumber(_ v: Optional<Double>) async throws(JSException) -> Optional<Double>
68-
69-
@JSFunction func jsAsyncRoundTripBoolArray(_ v: [Bool]) async throws(JSException) -> [Bool]
70-
71-
@JSFunction func jsAsyncRoundTripIntArray(_ v: [Double]) async throws(JSException) -> [Double]
72-
73-
@JSFunction func jsAsyncRoundTripStringArray(_ v: [String]) async throws(JSException) -> [String]
74-
75-
@JSFunction func jsAsyncRoundTripFeatureFlag(_ v: FeatureFlag) async throws(JSException) -> FeatureFlag
76-
7746
@JSFunction(jsName: "$jsWeirdFunction") func _jsWeirdFunction() throws(JSException) -> Double
7847

7948
@JSClass(jsName: "$WeirdClass") struct _WeirdClass {

0 commit comments

Comments
 (0)