Skip to content

Commit 6f415f1

Browse files
committed
Add tests for relaxed JSON syntax supported by Json.NET
1 parent 0f795db commit 6f415f1

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/Settings/SettingsUnitTests.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,88 @@ public async Task VerifyInvalidReferenceBehaviorAsync()
139139
Assert.Equal("[InvalidReference]", styleCopSettings.DocumentationRules.CopyrightText);
140140
}
141141

142+
/// <summary>
143+
/// Verifies that the settings successfully parse line comments.
144+
/// </summary>
145+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
146+
[Fact]
147+
public async Task VerifySettingsSupportsLineCommentsAsync()
148+
{
149+
var settings = @"
150+
{
151+
// Set value for company name
152+
""settings"": {
153+
""documentationRules"": {
154+
""companyName"": ""TestCompany""
155+
}
156+
}
157+
}
158+
";
159+
var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false);
160+
161+
var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None);
162+
163+
Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName);
164+
Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.CopyrightText);
165+
}
166+
167+
/// <summary>
168+
/// Verifies that the settings successfully parse block comments.
169+
/// </summary>
170+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
171+
[Fact]
172+
public async Task VerifySettingsSupportsBlockCommentsAsync()
173+
{
174+
var settings = @"
175+
{
176+
/*
177+
* Set value for company name
178+
*/
179+
""settings"": {
180+
""documentationRules"": {
181+
""companyName"": ""TestCompany""
182+
}
183+
}
184+
}
185+
";
186+
var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false);
187+
188+
var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None);
189+
190+
Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName);
191+
Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.CopyrightText);
192+
}
193+
194+
/// <summary>
195+
/// Verifies that the settings successfully parse trailing commas.
196+
/// </summary>
197+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
198+
[Fact]
199+
public async Task VerifySettingsSupportsTrailingCommasAsync()
200+
{
201+
var settings = @"
202+
{
203+
""settings"": {
204+
""documentationRules"": {
205+
""companyName"": ""TestCompany"",
206+
},
207+
""namingRules"": {
208+
""allowedHungarianPrefixes"": [ ""a"", ],
209+
},
210+
}
211+
}
212+
";
213+
var context = await CreateAnalysisContextAsync(settings).ConfigureAwait(false);
214+
215+
var styleCopSettings = context.GetStyleCopSettings(CancellationToken.None);
216+
217+
Assert.Equal("TestCompany", styleCopSettings.DocumentationRules.CompanyName);
218+
Assert.Equal("Copyright (c) TestCompany. All rights reserved.", styleCopSettings.DocumentationRules.CopyrightText);
219+
220+
Assert.Equal(1, styleCopSettings.NamingRules.AllowedHungarianPrefixes.Length);
221+
Assert.Equal("a", styleCopSettings.NamingRules.AllowedHungarianPrefixes[0]);
222+
}
223+
142224
[Fact]
143225
public async Task VerifyInvalidJsonBehaviorAsync()
144226
{

0 commit comments

Comments
 (0)