@@ -252,4 +252,193 @@ public void Method2() { }
252252
253253 await test . RunAsync ( ) ;
254254 }
255+
256+ [ Test ]
257+ public async Task PublicTypeInSupport_WithLicenseHeader_PreservesHeader ( )
258+ {
259+ const string testCode =
260+ """
261+ /*
262+ * Licensed to the Apache Software Foundation (ASF) under one or more
263+ * contributor license agreements. See the NOTICE file distributed with
264+ * this work for additional information regarding copyright ownership.
265+ * The ASF licenses this file to You under the Apache License, Version 2.0
266+ * (the "License"); you may not use this file except in compliance with
267+ * the License. You may obtain a copy of the License at
268+ *
269+ * http://www.apache.org/licenses/LICENSE-2.0
270+ *
271+ * Unless required by applicable law or agreed to in writing, software
272+ * distributed under the License is distributed on an "AS IS" BASIS,
273+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
274+ * See the License for the specific language governing permissions and
275+ * limitations under the License.
276+ */
277+
278+ namespace Lucene.Net.Support;
279+
280+ public class MyClass
281+ {
282+ }
283+ """ ;
284+
285+ const string fixedCode =
286+ """
287+ /*
288+ * Licensed to the Apache Software Foundation (ASF) under one or more
289+ * contributor license agreements. See the NOTICE file distributed with
290+ * this work for additional information regarding copyright ownership.
291+ * The ASF licenses this file to You under the Apache License, Version 2.0
292+ * (the "License"); you may not use this file except in compliance with
293+ * the License. You may obtain a copy of the License at
294+ *
295+ * http://www.apache.org/licenses/LICENSE-2.0
296+ *
297+ * Unless required by applicable law or agreed to in writing, software
298+ * distributed under the License is distributed on an "AS IS" BASIS,
299+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
300+ * See the License for the specific language governing permissions and
301+ * limitations under the License.
302+ */
303+
304+ namespace Lucene.Net.Support;
305+
306+ internal class MyClass
307+ {
308+ }
309+ """ ;
310+
311+ var expected = new DiagnosticResult ( Descriptors . LuceneDev1005_LuceneNetSupportPublicTypes )
312+ . WithSeverity ( DiagnosticSeverity . Warning )
313+ . WithMessageFormat ( Descriptors . LuceneDev1005_LuceneNetSupportPublicTypes . MessageFormat )
314+ . WithArguments ( "Class" , "MyClass" )
315+ . WithLocation ( 20 , 1 ) ;
316+
317+ var test = new InjectableCodeFixTest (
318+ ( ) => new LuceneDev1005_LuceneNetSupportPublicTypesCSCodeAnalyzer ( ) ,
319+ ( ) => new LuceneDev1005_LuceneNetSupportPublicTypesCSCodeFixProvider ( ) )
320+ {
321+ TestCode = testCode . ReplaceLineEndings ( ) ,
322+ FixedCode = fixedCode . ReplaceLineEndings ( ) ,
323+ ExpectedDiagnostics = { expected }
324+ } ;
325+
326+ await test . RunAsync ( ) ;
327+ }
328+
329+ [ Test ]
330+ public async Task PublicTypeInSupport_WithLicenseHeaderInsideNamespace_PreservesHeader ( )
331+ {
332+ const string testCode =
333+ """
334+ namespace Lucene.Net.Support
335+ {
336+ /*
337+ * Licensed to the Apache Software Foundation (ASF) under one or more
338+ * contributor license agreements. See the NOTICE file distributed with
339+ * this work for additional information regarding copyright ownership.
340+ * The ASF licenses this file to You under the Apache License, Version 2.0
341+ * (the "License"); you may not use this file except in compliance with
342+ * the License. You may obtain a copy of the License at
343+ *
344+ * http://www.apache.org/licenses/LICENSE-2.0
345+ *
346+ * Unless required by applicable law or agreed to in writing, software
347+ * distributed under the License is distributed on an "AS IS" BASIS,
348+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
349+ * See the License for the specific language governing permissions and
350+ * limitations under the License.
351+ */
352+
353+ public class MyClass
354+ {
355+ }
356+ }
357+ """ ;
358+
359+ const string fixedCode =
360+ """
361+ namespace Lucene.Net.Support
362+ {
363+ /*
364+ * Licensed to the Apache Software Foundation (ASF) under one or more
365+ * contributor license agreements. See the NOTICE file distributed with
366+ * this work for additional information regarding copyright ownership.
367+ * The ASF licenses this file to You under the Apache License, Version 2.0
368+ * (the "License"); you may not use this file except in compliance with
369+ * the License. You may obtain a copy of the License at
370+ *
371+ * http://www.apache.org/licenses/LICENSE-2.0
372+ *
373+ * Unless required by applicable law or agreed to in writing, software
374+ * distributed under the License is distributed on an "AS IS" BASIS,
375+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
376+ * See the License for the specific language governing permissions and
377+ * limitations under the License.
378+ */
379+
380+ internal class MyClass
381+ {
382+ }
383+ }
384+ """ ;
385+
386+ var expected = new DiagnosticResult ( Descriptors . LuceneDev1005_LuceneNetSupportPublicTypes )
387+ . WithSeverity ( DiagnosticSeverity . Warning )
388+ . WithMessageFormat ( Descriptors . LuceneDev1005_LuceneNetSupportPublicTypes . MessageFormat )
389+ . WithArguments ( "Class" , "MyClass" )
390+ . WithLocation ( 20 , 5 ) ;
391+
392+ var test = new InjectableCodeFixTest (
393+ ( ) => new LuceneDev1005_LuceneNetSupportPublicTypesCSCodeAnalyzer ( ) ,
394+ ( ) => new LuceneDev1005_LuceneNetSupportPublicTypesCSCodeFixProvider ( ) )
395+ {
396+ TestCode = testCode . ReplaceLineEndings ( ) ,
397+ FixedCode = fixedCode . ReplaceLineEndings ( ) ,
398+ ExpectedDiagnostics = { expected }
399+ } ;
400+
401+ await test . RunAsync ( ) ;
402+ }
403+
404+ [ Test ]
405+ public async Task PublicTypeInSupport_WithTrailingTrivia_PreservesTrailingTrivia ( )
406+ {
407+ const string testCode =
408+ """
409+ namespace Lucene.Net.Support
410+ {
411+ public class MyClass
412+ {
413+ } // Important trailing comment
414+ }
415+ """ ;
416+
417+ const string fixedCode =
418+ """
419+ namespace Lucene.Net.Support
420+ {
421+ internal class MyClass
422+ {
423+ } // Important trailing comment
424+ }
425+ """ ;
426+
427+ var expected = new DiagnosticResult ( Descriptors . LuceneDev1005_LuceneNetSupportPublicTypes )
428+ . WithSeverity ( DiagnosticSeverity . Warning )
429+ . WithMessageFormat ( Descriptors . LuceneDev1005_LuceneNetSupportPublicTypes . MessageFormat )
430+ . WithArguments ( "Class" , "MyClass" )
431+ . WithLocation ( 3 , 5 ) ;
432+
433+ var test = new InjectableCodeFixTest (
434+ ( ) => new LuceneDev1005_LuceneNetSupportPublicTypesCSCodeAnalyzer ( ) ,
435+ ( ) => new LuceneDev1005_LuceneNetSupportPublicTypesCSCodeFixProvider ( ) )
436+ {
437+ TestCode = testCode . ReplaceLineEndings ( ) ,
438+ FixedCode = fixedCode . ReplaceLineEndings ( ) ,
439+ ExpectedDiagnostics = { expected }
440+ } ;
441+
442+ await test . RunAsync ( ) ;
443+ }
255444}
0 commit comments