@@ -52,7 +52,88 @@ class CodeActionTest extends DottyTest:
52
52
// TODO look into trying to remove the extra space that is left behind
53
53
""" |final class Test
54
54
|""" .stripMargin
55
+ )
56
+
57
+ @ Test def insertMissingCases =
58
+ checkCodeAction(
59
+ code =
60
+ """ |enum Tree:
61
+ | case Node(l: Tree, r: Tree)
62
+ | case Leaf(v: String)
63
+ |
64
+ |object Test:
65
+ | def foo(tree: Tree) = tree match {
66
+ | case Tree.Node(_, _) => ???
67
+ | }
68
+ |""" .stripMargin,
69
+ title = " Insert missing cases (1)" ,
70
+ expected =
71
+ """ |enum Tree:
72
+ | case Node(l: Tree, r: Tree)
73
+ | case Leaf(v: String)
74
+ |
75
+ |object Test:
76
+ | def foo(tree: Tree) = tree match {
77
+ | case Tree.Node(_, _) => ???
78
+ | case Tree.Leaf(_) => ???
79
+ | }
80
+ |""" .stripMargin,
81
+ afterPhase = " patternMatcher"
82
+ )
55
83
84
+ @ Test def insertMissingCasesForUnionStringType =
85
+ checkCodeAction(
86
+ code =
87
+ """ object Test:
88
+ | def foo(text: "Alice" | "Bob") = text match {
89
+ | case "Alice" => ???
90
+ | }
91
+ |""" .stripMargin,
92
+ title = " Insert missing cases (1)" ,
93
+ expected =
94
+ """ object Test:
95
+ | def foo(text: "Alice" | "Bob") = text match {
96
+ | case "Alice" => ???
97
+ | case "Bob" => ???
98
+ | }
99
+ |""" .stripMargin,
100
+ afterPhase = " patternMatcher"
101
+ )
102
+
103
+ @ Test def insertMissingCasesForUnionIntType =
104
+ checkCodeAction(
105
+ code =
106
+ """ object Test:
107
+ | def foo(text: 1 | 2) = text match {
108
+ | case 2 => ???
109
+ | }
110
+ |""" .stripMargin,
111
+ title = " Insert missing cases (1)" ,
112
+ expected =
113
+ """ object Test:
114
+ | def foo(text: 1 | 2) = text match {
115
+ | case 2 => ???
116
+ | case 1 => ???
117
+ | }
118
+ |""" .stripMargin,
119
+ afterPhase = " patternMatcher"
120
+ )
121
+
122
+ @ Test def insertMissingCasesUsingBracelessSyntax =
123
+ checkCodeAction(
124
+ code =
125
+ """ object Test:
126
+ | def foo(text: 1 | 2) = text match
127
+ | case 2 => ???
128
+ |""" .stripMargin,
129
+ title = " Insert missing cases (1)" ,
130
+ expected =
131
+ """ object Test:
132
+ | def foo(text: 1 | 2) = text match
133
+ | case 2 => ???
134
+ | case 1 => ???
135
+ |""" .stripMargin,
136
+ afterPhase = " patternMatcher"
56
137
)
57
138
58
139
// Make sure we're not using the default reporter, which is the ConsoleReporter,
@@ -61,16 +142,16 @@ class CodeActionTest extends DottyTest:
61
142
val rep = new StoreReporter (null ) with UniqueMessagePositions with HideNonSensicalMessages
62
143
initialCtx.setReporter(rep).withoutColors
63
144
64
- private def checkCodeAction (code : String , title : String , expected : String ) =
145
+ private def checkCodeAction (code : String , title : String , expected : String , afterPhase : String = " typer " ) =
65
146
ctx = newContext
66
147
val source = SourceFile .virtual(" test" , code).content
67
- val runCtx = checkCompile(" typer " , code) { (_, _) => () }
148
+ val runCtx = checkCompile(afterPhase , code) { (_, _) => () }
68
149
val diagnostics = runCtx.reporter.removeBufferedMessages
69
- assertEquals(1 , diagnostics.size)
150
+ assertEquals(" Expected exactly one diagnostic " , 1 , diagnostics.size)
70
151
71
152
val diagnostic = diagnostics.head
72
153
val actions = diagnostic.msg.actions.toList
73
- assertEquals(1 , actions.size)
154
+ assertEquals(" Expected exactly one action " , 1 , actions.size)
74
155
75
156
// TODO account for more than 1 action
76
157
val action = actions.head
0 commit comments