Skip to content

Commit 4db13d9

Browse files
[NFC] BridgeJS: Split out OptionalSupportTests.swift (#583)
BridgeJS: Split out OptionalSupportTests.swift
1 parent f56d72f commit 4db13d9

File tree

12 files changed

+4108
-3900
lines changed

12 files changed

+4108
-3900
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ let package = Package(
183183
"bridge-js.d.ts",
184184
"bridge-js.global.d.ts",
185185
"Generated/JavaScript",
186+
"JavaScript",
186187
],
187188
swiftSettings: [
188189
.enableExperimentalFeature("Extern")

Package@swift-6.2.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ let package = Package(
194194
"bridge-js.d.ts",
195195
"bridge-js.global.d.ts",
196196
"Generated/JavaScript",
197+
"JavaScript",
197198
],
198199
swiftSettings: [
199200
.enableExperimentalFeature("Extern")

Tests/BridgeJSRuntimeTests/ExportAPITests.swift

Lines changed: 8 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -515,123 +515,6 @@ enum ComplexResult {
515515
return result
516516
}
517517

518-
// MARK: - Optionals
519-
520-
@JS func roundTripOptionalString(name: String?) -> String? {
521-
return name
522-
}
523-
524-
@JS func roundTripOptionalInt(value: Int?) -> Int? {
525-
return value
526-
}
527-
528-
@JS func roundTripOptionalBool(flag: Bool?) -> Bool? {
529-
return flag
530-
}
531-
532-
@JS func roundTripOptionalFloat(number: Float?) -> Float? {
533-
return number
534-
}
535-
536-
@JS func roundTripOptionalDouble(precision: Double?) -> Double? {
537-
return precision
538-
}
539-
540-
@JS func roundTripOptionalSyntax(name: Optional<String>) -> Optional<String> {
541-
return name
542-
}
543-
544-
@JS func roundTripOptionalMixSyntax(name: String?) -> Optional<String> {
545-
return name
546-
}
547-
548-
@JS func roundTripOptionalSwiftSyntax(name: Swift.Optional<String>) -> Swift.Optional<String> {
549-
return name
550-
}
551-
552-
@JS func roundTripOptionalWithSpaces(value: Optional<Double>) -> Optional<Double> {
553-
return value
554-
}
555-
556-
typealias OptionalAge = Int?
557-
@JS func roundTripOptionalTypeAlias(age: OptionalAge) -> OptionalAge {
558-
return age
559-
}
560-
561-
@JS func roundTripOptionalStatus(value: Status?) -> Status? {
562-
return value
563-
}
564-
565-
@JS func roundTripOptionalTheme(value: Theme?) -> Theme? {
566-
return value
567-
}
568-
569-
@JS func roundTripOptionalHttpStatus(value: HttpStatus?) -> HttpStatus? {
570-
return value
571-
}
572-
573-
@JS func roundTripOptionalTSDirection(value: TSDirection?) -> TSDirection? {
574-
return value
575-
}
576-
577-
@JS func roundTripOptionalTSTheme(value: TSTheme?) -> TSTheme? {
578-
return value
579-
}
580-
581-
@JS func roundTripOptionalNetworkingAPIMethod(_ method: Networking.API.Method?) -> Networking.API.Method? {
582-
return method
583-
}
584-
585-
@JS func roundTripOptionalAPIResult(value: APIResult?) -> APIResult? {
586-
return value
587-
}
588-
589-
@JS enum TypedPayloadResult {
590-
case precision(Precision)
591-
case direction(Direction)
592-
case optPrecision(Precision?)
593-
case optDirection(Direction?)
594-
case empty
595-
}
596-
597-
@JS func roundTripTypedPayloadResult(_ result: TypedPayloadResult) -> TypedPayloadResult {
598-
return result
599-
}
600-
601-
@JS func roundTripOptionalTypedPayloadResult(_ result: TypedPayloadResult?) -> TypedPayloadResult? {
602-
return result
603-
}
604-
605-
@JS func compareAPIResults(_ r1: APIResult?, _ r2: APIResult?) -> String {
606-
let r1Str: String
607-
switch r1 {
608-
case .none: r1Str = "nil"
609-
case .some(.success(let msg)): r1Str = "success:\(msg)"
610-
case .some(.failure(let code)): r1Str = "failure:\(code)"
611-
case .some(.info): r1Str = "info"
612-
case .some(.flag(let b)): r1Str = "flag:\(b)"
613-
case .some(.rate(let r)): r1Str = "rate:\(r)"
614-
case .some(.precise(let p)): r1Str = "precise:\(p)"
615-
}
616-
617-
let r2Str: String
618-
switch r2 {
619-
case .none: r2Str = "nil"
620-
case .some(.success(let msg)): r2Str = "success:\(msg)"
621-
case .some(.failure(let code)): r2Str = "failure:\(code)"
622-
case .some(.info): r2Str = "info"
623-
case .some(.flag(let b)): r2Str = "flag:\(b)"
624-
case .some(.rate(let r)): r2Str = "rate:\(r)"
625-
case .some(.precise(let p)): r2Str = "precise:\(p)"
626-
}
627-
628-
return "r1:\(r1Str),r2:\(r2Str)"
629-
}
630-
631-
@JS func roundTripOptionalComplexResult(_ result: ComplexResult?) -> ComplexResult? {
632-
return result
633-
}
634-
635518
@JS
636519
enum AllTypesResult {
637520
case structPayload(Address)
@@ -644,76 +527,19 @@ enum AllTypesResult {
644527
}
645528

646529
@JS func roundTripAllTypesResult(_ result: AllTypesResult) -> AllTypesResult {
647-
return result
648-
}
649-
650-
@JS func roundTripOptionalAllTypesResult(_ result: AllTypesResult?) -> AllTypesResult? {
651-
return result
530+
result
652531
}
653532

654-
@JS
655-
enum OptionalAllTypesResult {
656-
case optStruct(Address?)
657-
case optClass(Greeter?)
658-
case optJSObject(JSObject?)
659-
case optNestedEnum(APIResult?)
660-
case optArray([Int]?)
661-
case optJsClass(Foo?)
533+
@JS enum TypedPayloadResult {
534+
case precision(Precision)
535+
case direction(Direction)
536+
case optPrecision(Precision?)
537+
case optDirection(Direction?)
662538
case empty
663539
}
664540

665-
@JS func roundTripOptionalPayloadResult(_ result: OptionalAllTypesResult) -> OptionalAllTypesResult {
666-
return result
667-
}
668-
669-
@JS func roundTripOptionalPayloadResultOpt(_ result: OptionalAllTypesResult?) -> OptionalAllTypesResult? {
670-
return result
671-
}
672-
673-
@JS func roundTripOptionalClass(value: Greeter?) -> Greeter? {
674-
return value
675-
}
676-
677-
@JS func roundTripOptionalGreeter(_ value: Greeter?) -> Greeter? {
678-
value
679-
}
680-
681-
@JS func applyOptionalGreeter(_ value: Greeter?, _ transform: (Greeter?) -> Greeter?) -> Greeter? {
682-
transform(value)
683-
}
684-
685-
@JS class OptionalHolder {
686-
@JS var nullableGreeter: Greeter?
687-
@JS var undefinedNumber: JSUndefinedOr<Double>
688-
689-
@JS init(nullableGreeter: Greeter?, undefinedNumber: JSUndefinedOr<Double>) {
690-
self.nullableGreeter = nullableGreeter
691-
self.undefinedNumber = undefinedNumber
692-
}
693-
}
694-
695-
@JS func makeOptionalHolder(nullableGreeter: Greeter?, undefinedNumber: JSUndefinedOr<Double>) -> OptionalHolder {
696-
OptionalHolder(nullableGreeter: nullableGreeter, undefinedNumber: undefinedNumber)
697-
}
698-
699-
@JS class OptionalPropertyHolder {
700-
@JS var optionalName: String?
701-
@JS var optionalAge: Int? = nil
702-
@JS var optionalGreeter: Greeter? = nil
703-
704-
@JS init(optionalName: String?) {
705-
self.optionalName = optionalName
706-
}
707-
}
708-
709-
@JS
710-
enum APIOptionalResult {
711-
case success(String?)
712-
case failure(Int?, Bool?)
713-
case status(Bool?, Int?, String?)
714-
}
715-
@JS func roundTripOptionalAPIOptionalResult(result: APIOptionalResult?) -> APIOptionalResult? {
716-
return result
541+
@JS func roundTripTypedPayloadResult(_ result: TypedPayloadResult) -> TypedPayloadResult {
542+
result
717543
}
718544

719545
// MARK: - Property Tests

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
@JSFunction func jsRoundTripString(_ v: String) throws(JSException) -> String
1616

17-
@JSFunction func jsRoundTripOptionalNumberNull(_ v: Optional<Double>) throws(JSException) -> Optional<Double>
18-
19-
@JSFunction func jsRoundTripOptionalNumberUndefined(_ v: JSUndefinedOr<Double>) throws(JSException) -> JSUndefinedOr<Double>
20-
2117
@JSFunction func jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue
2218

2319
@JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void

0 commit comments

Comments
 (0)