Skip to content

Commit 29e30f5

Browse files
More tests
1 parent eb10985 commit 29e30f5

File tree

1 file changed

+108
-28
lines changed

1 file changed

+108
-28
lines changed

Tests/SwiftParserTest/translated/InitDeinitTests.swift

Lines changed: 108 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ final class InitDeinitTests: XCTestCase {
419419
func testInitDeinit28() {
420420
assertParse(
421421
"""
422-
init(_ foo: T) 1️⃣-> Int where T: Comparable {}
422+
init(_ foo: T) 1️⃣-> Int where T: Comparable {}
423423
""",
424424
diagnostics: [
425425
DiagnosticSpec(message: "initializers cannot have a result type")
@@ -438,34 +438,26 @@ final class InitDeinitTests: XCTestCase {
438438
substructure: Syntax(DeinitializerDeclSyntax())
439439
)
440440
}
441-
442-
func testDeinitAsyncThrows() {
441+
442+
func testDeinitAsync() {
443443
assertParse(
444444
"""
445445
class FooClassDeinitializerA {
446-
deinit async 1️⃣throws {}
446+
deinit async {}
447447
}
448-
""",
449-
diagnostics: [
450-
DiagnosticSpec(locationMarker: "1️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'throws'"])
451-
],
452-
fixedSource: """
453-
class FooClassDeinitializerA {
454-
deinit async {}
455-
}
456-
"""
448+
"""
457449
)
458450
}
459-
460-
func testDeinitThrowsAsync() {
451+
452+
func testDeinitAwait() {
461453
assertParse(
462454
"""
463455
class FooClassDeinitializerA {
464-
deinit 1️⃣throws async {}
456+
deinit 1️⃣await {}
465457
}
466458
""",
467459
diagnostics: [
468-
DiagnosticSpec(locationMarker: "1️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'throws'"])
460+
DiagnosticSpec(locationMarker: "1️⃣", message: "expected async specifier; did you mean 'async'?", fixIts: ["replace 'await' with 'async'"])
469461
],
470462
fixedSource: """
471463
class FooClassDeinitializerA {
@@ -475,15 +467,15 @@ final class InitDeinitTests: XCTestCase {
475467
)
476468
}
477469

478-
func testDeinitThrowsAsyncRethrows() {
470+
func testDeinitReasync() {
479471
assertParse(
480472
"""
481473
class FooClassDeinitializerA {
482-
deinit 1️⃣throws async rethrows {}
474+
deinit 1️⃣reasync {}
483475
}
484476
""",
485477
diagnostics: [
486-
DiagnosticSpec(locationMarker: "1️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'throws' and 'rethrows'"])
478+
DiagnosticSpec(locationMarker: "1️⃣", message: "expected async specifier; did you mean 'async'?", fixIts: ["replace 'reasync' with 'async'"])
487479
],
488480
fixedSource: """
489481
class FooClassDeinitializerA {
@@ -493,42 +485,65 @@ final class InitDeinitTests: XCTestCase {
493485
)
494486
}
495487

496-
func testDeinitReasync() {
488+
func testDeinitThrows() {
497489
assertParse(
498490
"""
499491
class FooClassDeinitializerA {
500-
deinit 1️⃣reasync {}
492+
deinit 1️⃣throws {}
501493
}
502494
""",
503495
diagnostics: [
504-
DiagnosticSpec(locationMarker: "1️⃣", message: "expected async specifier; did you mean 'async'?", fixIts: ["replace 'reasync' with 'async'"])
496+
DiagnosticSpec(locationMarker: "1️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'throws'"])
505497
],
506498
fixedSource: """
507499
class FooClassDeinitializerA {
508-
deinit async {}
500+
deinit {}
509501
}
510502
"""
511503
)
512504
}
513505

514-
func testDeinitAwait() {
506+
func testDeinitRethrows() {
515507
assertParse(
516508
"""
517509
class FooClassDeinitializerA {
518-
deinit 1️⃣await {}
510+
deinit 1️⃣rethrows {}
519511
}
520512
""",
521513
diagnostics: [
522-
DiagnosticSpec(locationMarker: "1️⃣", message: "expected async specifier; did you mean 'async'?", fixIts: ["replace 'await' with 'async'"])
514+
DiagnosticSpec(locationMarker: "1️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'rethrows'"])
523515
],
524516
fixedSource: """
525517
class FooClassDeinitializerA {
526-
deinit async {}
518+
deinit {}
527519
}
528520
"""
529521
)
530522
}
531523

524+
func testDeinitAsyncAsync() {
525+
assertParse(
526+
"""
527+
class FooClassDeinitializerA {
528+
deinit ℹ️async 1️⃣async {}
529+
}
530+
""",
531+
diagnostics: [
532+
DiagnosticSpec(
533+
locationMarker: "1️⃣",
534+
message: "'async' has already been specified",
535+
notes: [NoteSpec(message: "'async' declared here")],
536+
fixIts: ["remove redundant 'async'"]
537+
)
538+
],
539+
fixedSource: """
540+
class FooClassDeinitializerA {
541+
deinit async {}
542+
}
543+
"""
544+
)
545+
}
546+
532547
func testDeinitAsyncAwait() {
533548
assertParse(
534549
"""
@@ -574,6 +589,60 @@ final class InitDeinitTests: XCTestCase {
574589
)
575590
}
576591

592+
func testDeinitAsyncThrows() {
593+
assertParse(
594+
"""
595+
class FooClassDeinitializerA {
596+
deinit async 1️⃣throws {}
597+
}
598+
""",
599+
diagnostics: [
600+
DiagnosticSpec(locationMarker: "1️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'throws'"])
601+
],
602+
fixedSource: """
603+
class FooClassDeinitializerA {
604+
deinit async {}
605+
}
606+
"""
607+
)
608+
}
609+
610+
func testDeinitThrowsAsync() {
611+
assertParse(
612+
"""
613+
class FooClassDeinitializerA {
614+
deinit 1️⃣throws async {}
615+
}
616+
""",
617+
diagnostics: [
618+
DiagnosticSpec(locationMarker: "1️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'throws'"])
619+
],
620+
fixedSource: """
621+
class FooClassDeinitializerA {
622+
deinit async {}
623+
}
624+
"""
625+
)
626+
}
627+
628+
func testDeinitThrowsAsyncRethrows() {
629+
assertParse(
630+
"""
631+
class FooClassDeinitializerA {
632+
deinit 1️⃣throws async rethrows {}
633+
}
634+
""",
635+
diagnostics: [
636+
DiagnosticSpec(locationMarker: "1️⃣", message: "deinitializers cannot throw", fixIts: ["remove 'throws' and 'rethrows'"])
637+
],
638+
fixedSource: """
639+
class FooClassDeinitializerA {
640+
deinit async {}
641+
}
642+
"""
643+
)
644+
}
645+
577646
func testDeinitNameAwait() {
578647
assertParse(
579648
"""
@@ -696,4 +765,15 @@ final class InitDeinitTests: XCTestCase {
696765
"""
697766
)
698767
}
768+
769+
func testAsyncDeinit() {
770+
// TODO: Investigate why this produces no diagnostics
771+
assertParse(
772+
"""
773+
class FooClassDeinitializerA {
774+
async deinit {}
775+
}
776+
"""
777+
)
778+
}
699779
}

0 commit comments

Comments
 (0)