Skip to content

Commit 6a240b3

Browse files
committed
Add tests for additional types of JSON parsing errors
1 parent 33faf3c commit 6a240b3

1 file changed

Lines changed: 151 additions & 1 deletion

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/SpecialRules/SA0002UnitTests.cs

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task TestInvalidSettingsAsync()
6868
}
6969

7070
[Fact]
71-
public async Task TestInvalidSettingValueAsync()
71+
public async Task TestInvalidSettingStringValueAsync()
7272
{
7373
this.settings = @"
7474
{
@@ -86,6 +86,156 @@ public async Task TestInvalidSettingValueAsync()
8686
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
8787
}
8888

89+
[Fact]
90+
public async Task TestInvalidSettingStringArrayElementValueAsync()
91+
{
92+
this.settings = @"
93+
{
94+
""settings"": {
95+
""namingRules"": {
96+
""allowedHungarianPrefixes"": [ 3 ]
97+
}
98+
}
99+
}
100+
";
101+
102+
// This diagnostic is reported without a location
103+
DiagnosticResult expected = this.CSharpDiagnostic();
104+
105+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
106+
}
107+
108+
[Fact]
109+
public async Task TestInvalidSettingBooleanValueAsync()
110+
{
111+
this.settings = @"
112+
{
113+
""settings"": {
114+
""documentationRules"": {
115+
""xmlHeader"": 3
116+
}
117+
}
118+
}
119+
";
120+
121+
// This diagnostic is reported without a location
122+
DiagnosticResult expected = this.CSharpDiagnostic();
123+
124+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
125+
}
126+
127+
[Fact]
128+
public async Task TestInvalidSettingIntegerValueAsync()
129+
{
130+
this.settings = @"
131+
{
132+
""settings"": {
133+
""indentation"": {
134+
""tabSize"": ""3""
135+
}
136+
}
137+
}
138+
";
139+
140+
// This diagnostic is reported without a location
141+
DiagnosticResult expected = this.CSharpDiagnostic();
142+
143+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
144+
}
145+
146+
[Fact]
147+
public async Task TestInvalidSettingEnumValueNotStringAsync()
148+
{
149+
this.settings = @"
150+
{
151+
""settings"": {
152+
""documentationRules"": {
153+
""fileNamingConvention"": 3
154+
}
155+
}
156+
}
157+
";
158+
159+
// This diagnostic is reported without a location
160+
DiagnosticResult expected = this.CSharpDiagnostic();
161+
162+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
163+
}
164+
165+
[Fact]
166+
public async Task TestInvalidSettingArrayElementEnumValueNotStringAsync()
167+
{
168+
this.settings = @"
169+
{
170+
""settings"": {
171+
""maintainabilityRules"": {
172+
""topLevelTypes"": [ 3 ]
173+
}
174+
}
175+
}
176+
";
177+
178+
// This diagnostic is reported without a location
179+
DiagnosticResult expected = this.CSharpDiagnostic();
180+
181+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
182+
}
183+
184+
[Fact]
185+
public async Task TestInvalidSettingArrayElementEnumValueNotRecognizedAsync()
186+
{
187+
this.settings = @"
188+
{
189+
""settings"": {
190+
""maintainabilityRules"": {
191+
""topLevelTypes"": [ ""Some incorrect value"" ]
192+
}
193+
}
194+
}
195+
";
196+
197+
// This diagnostic is reported without a location
198+
DiagnosticResult expected = this.CSharpDiagnostic();
199+
200+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
201+
}
202+
203+
[Fact]
204+
public async Task TestInvalidSettingArrayAsync()
205+
{
206+
this.settings = @"
207+
{
208+
""settings"": {
209+
""namingRules"": {
210+
""allowedHungarianPrefixes"": ""ah""
211+
}
212+
}
213+
}
214+
";
215+
216+
// This diagnostic is reported without a location
217+
DiagnosticResult expected = this.CSharpDiagnostic();
218+
219+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
220+
}
221+
222+
[Fact]
223+
public async Task TestInvalidSettingObjectAsync()
224+
{
225+
this.settings = @"
226+
{
227+
""settings"": {
228+
""namingRules"": true
229+
}
230+
}
231+
";
232+
233+
// This diagnostic is reported without a location
234+
DiagnosticResult expected = this.CSharpDiagnostic();
235+
236+
await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false);
237+
}
238+
89239
[Fact]
90240
public async Task TestInvalidSettingSyntaxAsync()
91241
{

0 commit comments

Comments
 (0)