@@ -179,6 +179,130 @@ class CodeActionTest extends DottyTest:
179179 ctxx = ctxx
180180 )
181181
182+ @ Test def addNN1 =
183+ val ctxx = newContext
184+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
185+ checkCodeAction(
186+ code =
187+ """ val s: String|Null = ???
188+ | val t: String = s""" .stripMargin,
189+ title = " Add .nn" ,
190+ expected =
191+ """ val s: String|Null = ???
192+ | val t: String = s.nn""" .stripMargin,
193+ ctxx = ctxx
194+ )
195+
196+ @ Test def addNN2 =
197+ val ctxx = newContext
198+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
199+ checkCodeAction(
200+ code =
201+ """ implicit class infixOpTest(val s1: String) extends AnyVal {
202+ | def q(s2: String): String | Null = null
203+ |}
204+ | val s: String = ???
205+ | val t: String = s q s""" .stripMargin,
206+ title = " Add .nn" ,
207+ expected =
208+ """ implicit class infixOpTest(val s1: String) extends AnyVal {
209+ | def q(s2: String): String | Null = null
210+ |}
211+ | val s: String = ???
212+ | val t: String = (s q s).nn""" .stripMargin,
213+ ctxx = ctxx
214+ )
215+
216+ @ Test def addNN3 =
217+ val ctxx = newContext
218+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
219+ checkCodeAction(
220+ code =
221+ """ implicit class infixOpTest(val s1: String) extends AnyVal {
222+ | def q(s2: String, s3: String): String | Null = null
223+ |}
224+ | val s: String = ???
225+ | val t: String = s q (s, s)""" .stripMargin,
226+ title = " Add .nn" ,
227+ expected =
228+ """ implicit class infixOpTest(val s1: String) extends AnyVal {
229+ | def q(s2: String, s3: String): String | Null = null
230+ |}
231+ | val s: String = ???
232+ | val t: String = (s q (s, s)).nn""" .stripMargin,
233+ ctxx = ctxx
234+ )
235+
236+ @ Test def addNN4 =
237+ val ctxx = newContext
238+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
239+ checkCodeAction(
240+ code =
241+ """ implicit class infixOpTest(val s1: String) extends AnyVal {
242+ | def q(s2: String, s3: String): String | Null = null
243+ |}
244+ | val s: String = ???
245+ | val t: String = s.q(s, s)""" .stripMargin,
246+ title = " Add .nn" ,
247+ expected =
248+ """ implicit class infixOpTest(val s1: String) extends AnyVal {
249+ | def q(s2: String, s3: String): String | Null = null
250+ |}
251+ | val s: String = ???
252+ | val t: String = s.q(s, s).nn""" .stripMargin,
253+ ctxx = ctxx
254+ )
255+
256+ @ Test def addNN5 =
257+ val ctxx = newContext
258+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
259+ checkCodeAction(
260+ code =
261+ """ val s: String | Null = ???
262+ |val t: String = s match {
263+ | case _: String => "foo"
264+ | case _ => s
265+ |}""" .stripMargin,
266+ title = " Add .nn" ,
267+ expected =
268+ """ val s: String | Null = ???
269+ |val t: String = s match {
270+ | case _: String => "foo"
271+ | case _ => s.nn
272+ |}""" .stripMargin,
273+ ctxx = ctxx
274+ )
275+
276+ @ Test def addNN6 =
277+ val ctxx = newContext
278+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
279+ checkCodeAction(
280+ code =
281+ """ val s: String | Null = ???
282+ |val t: String = if (s != null) "foo" else s""" .stripMargin,
283+ title = " Add .nn" ,
284+ expected =
285+ """ val s: String | Null = ???
286+ |val t: String = if (s != null) "foo" else s.nn""" .stripMargin,
287+ ctxx = ctxx
288+ )
289+
290+ @ Test def addNN7 =
291+ val ctxx = newContext
292+ ctxx.setSetting(ctxx.settings.YexplicitNulls , true )
293+ checkCodeAction(
294+ code =
295+ """ given ctx: String | Null = null
296+ |def f(using c: String): String = c
297+ |val s: String = f(using ctx)""" .stripMargin,
298+ title = " Add .nn" ,
299+ expected =
300+ """ given ctx: String | Null = null
301+ |def f(using c: String): String = c
302+ |val s: String = f(using ctx.nn)""" .stripMargin,
303+ ctxx = ctxx
304+ )
305+
182306 // Make sure we're not using the default reporter, which is the ConsoleReporter,
183307 // meaning they will get reported in the test run and that's it.
184308 private def newContext =
0 commit comments