Skip to content

Commit fb3cb6a

Browse files
committed
Add negative tests for non-public in Support
1 parent 6c8f3ce commit fb3cb6a

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

tests/Lucene.Net.Tests.CodeAnalysis.Dev/TestLuceneDev1005_LuceneNetSupportPublicTypesCSCodeAnalyzer.cs

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace Lucene.Net.Support;
6161
[TestCase("record")]
6262
[TestCase("record struct")]
6363
[TestCase("enum")]
64-
public void TestDiagnostic_FileScopedNamespace_NegativeTest(string typeKind)
64+
public void TestDiagnostic_FileScopedNamespace_NegativeTest_PublicInAnotherNamespace(string typeKind)
6565
{
6666
string typeKindDesc = typeKind[0].ToString().ToUpper() + typeKind[1..];
6767
string typeName = $"Public{typeKindDesc.Replace(" ", "")}";
@@ -75,6 +75,27 @@ namespace Lucene.Net.SomethingElse;
7575
VerifyCSharpDiagnostic(test);
7676
}
7777

78+
[Test]
79+
[TestCase("class")]
80+
[TestCase("struct")]
81+
[TestCase("interface")]
82+
[TestCase("record")]
83+
[TestCase("record struct")]
84+
[TestCase("enum")]
85+
public void TestDiagnostic_FileScopedNamespace_NegativeTest_NonPublicInSupport(string typeKind)
86+
{
87+
string typeKindDesc = typeKind[0].ToString().ToUpper() + typeKind[1..];
88+
string typeName = $"Public{typeKindDesc.Replace(" ", "")}";
89+
90+
string test =
91+
$"""
92+
namespace Lucene.Net.Support.Bar;
93+
internal {typeKind} {typeName};
94+
""";
95+
96+
VerifyCSharpDiagnostic(test);
97+
}
98+
7899
[Test]
79100
public void TestDiagnostic_FileScopedNamespace_Delegate_PositiveTest()
80101
{
@@ -99,7 +120,7 @@ namespace Lucene.Net.Support;
99120
}
100121

101122
[Test]
102-
public void TestDiagnostic_FileScopedNamespace_Delegate_NegativeTest()
123+
public void TestDiagnostic_FileScopedNamespace_Delegate_NegativeTest_PublicInAnotherNamespace()
103124
{
104125
const string test =
105126
"""
@@ -110,6 +131,18 @@ namespace Lucene.Net.SomethingElse;
110131
VerifyCSharpDiagnostic(test);
111132
}
112133

134+
[Test]
135+
public void TestDiagnostic_FileScopedNamespace_Delegate_NegativeTest_NonPublicInSupport()
136+
{
137+
const string test =
138+
"""
139+
namespace Lucene.Net.Support;
140+
internal delegate void PublicDelegate();
141+
""";
142+
143+
VerifyCSharpDiagnostic(test);
144+
}
145+
113146
[Test]
114147
[TestCase("class")]
115148
[TestCase("struct")]
@@ -151,7 +184,7 @@ namespace Lucene.Net.Support
151184
[TestCase("record")]
152185
[TestCase("record struct")]
153186
[TestCase("enum")]
154-
public void TestDiagnostic_BlockScopedNamespace_NegativeTest(string typeKind)
187+
public void TestDiagnostic_BlockScopedNamespace_NegativeTest_PublicInAnotherNamespace(string typeKind)
155188
{
156189
string typeKindDesc = typeKind[0].ToString().ToUpper() + typeKind[1..];
157190
string typeName = $"Public{typeKindDesc.Replace(" ", "")}";
@@ -167,6 +200,29 @@ namespace Lucene.Net.SomethingElse
167200
VerifyCSharpDiagnostic(test);
168201
}
169202

203+
[Test]
204+
[TestCase("class")]
205+
[TestCase("struct")]
206+
[TestCase("interface")]
207+
[TestCase("record")]
208+
[TestCase("record struct")]
209+
[TestCase("enum")]
210+
public void TestDiagnostic_BlockScopedNamespace_NegativeTest_NonPublicInSupport(string typeKind)
211+
{
212+
string typeKindDesc = typeKind[0].ToString().ToUpper() + typeKind[1..];
213+
string typeName = $"Public{typeKindDesc.Replace(" ", "")}";
214+
215+
string test =
216+
$$"""
217+
namespace Lucene.Net.Support.Foo
218+
{
219+
internal {{typeKind}} {{typeName}};
220+
}
221+
""";
222+
223+
VerifyCSharpDiagnostic(test);
224+
}
225+
170226
[Test]
171227
public void TestDiagnostic_BlockScopedNamespace_Delegate_PositiveTest()
172228
{
@@ -193,7 +249,7 @@ namespace Lucene.Net.Support
193249
}
194250

195251
[Test]
196-
public void TestDiagnostic_BlockScopedNamespace_Delegate_NegativeTest()
252+
public void TestDiagnostic_BlockScopedNamespace_Delegate_NegativeTest_PublicInAnotherNamespace()
197253
{
198254
const string test =
199255
"""
@@ -205,5 +261,19 @@ namespace Lucene.Net.SomethingElse
205261

206262
VerifyCSharpDiagnostic(test);
207263
}
264+
265+
[Test]
266+
public void TestDiagnostic_BlockScopedNamespace_Delegate_NegativeTest_NonPublicInSupport()
267+
{
268+
const string test =
269+
"""
270+
namespace Lucene.Net.Support
271+
{
272+
internal delegate void PublicDelegate();
273+
}
274+
""";
275+
276+
VerifyCSharpDiagnostic(test);
277+
}
208278
}
209279
}

0 commit comments

Comments
 (0)