Skip to content
代码片段 群组 项目
提交 dd0ddb3c 编辑于 作者: Jason Malinowski's avatar Jason Malinowski
浏览文件

Add more tests for .editorconfig manipulation

上级 9fb83beb
No related branches found
No related tags found
无相关合并请求
......@@ -1657,6 +1657,78 @@ public async Task TestAddingEditorConfigFileWithDiagnosticSeverity()
Assert.Equal(ReportDiagnostic.Error, newSyntaxTree.DiagnosticOptions["CA1234"]);
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public async Task TestAddingAndRemovingEditorConfigFileWithDiagnosticSeverity()
{
var solution = CreateSolution();
var projectId = ProjectId.CreateNewId();
var sourceDocumentId = DocumentId.CreateNewId(projectId);
solution = solution.AddProject(projectId, "Test", "Test.dll", LanguageNames.CSharp);
solution = solution.AddDocument(sourceDocumentId, "Test.cs", "// Hello, world!", filePath: @"Z:\Test.cs");
var editorConfigDocumentId = DocumentId.CreateNewId(projectId);
solution = solution.AddAnalyzerConfigDocuments(ImmutableArray.Create(
DocumentInfo.Create(
editorConfigDocumentId,
".editorconfig",
filePath: @"Z:\.editorconfig",
loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.cs]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
var syntaxTreeAfterAddingEditorConfig = await solution.GetDocument(sourceDocumentId).GetSyntaxTreeAsync();
Assert.Single(syntaxTreeAfterAddingEditorConfig.DiagnosticOptions);
Assert.Equal(ReportDiagnostic.Error, syntaxTreeAfterAddingEditorConfig.DiagnosticOptions["CA1234"]);
solution = solution.RemoveAnalyzerConfigDocument(editorConfigDocumentId);
var syntaxTreeAfterRemovingEditorConfig = await solution.GetDocument(sourceDocumentId).GetSyntaxTreeAsync();
Assert.Empty(syntaxTreeAfterRemovingEditorConfig.DiagnosticOptions);
var finalCompilation = await solution.GetProject(projectId).GetCompilationAsync();
Assert.True(finalCompilation.ContainsSyntaxTree(syntaxTreeAfterRemovingEditorConfig));
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public async Task TestChangingAnEditorConfigFile()
{
var solution = CreateSolution();
var projectId = ProjectId.CreateNewId();
var sourceDocumentId = DocumentId.CreateNewId(projectId);
solution = solution.AddProject(projectId, "Test", "Test.dll", LanguageNames.CSharp);
solution = solution.AddDocument(sourceDocumentId, "Test.cs", "// Hello, world!", filePath: @"Z:\Test.cs");
var editorConfigDocumentId = DocumentId.CreateNewId(projectId);
solution = solution.AddAnalyzerConfigDocuments(ImmutableArray.Create(
DocumentInfo.Create(
editorConfigDocumentId,
".editorconfig",
filePath: @"Z:\.editorconfig",
loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.cs]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
var syntaxTreeBeforeEditorConfigChange = await solution.GetDocument(sourceDocumentId).GetSyntaxTreeAsync();
Assert.Single(syntaxTreeBeforeEditorConfigChange.DiagnosticOptions);
Assert.Equal(ReportDiagnostic.Error, syntaxTreeBeforeEditorConfigChange.DiagnosticOptions["CA1234"]);
solution = solution.WithAnalyzerConfigDocumentTextLoader(
editorConfigDocumentId,
TextLoader.From(TextAndVersion.Create(SourceText.From("[*.cs]\r\n\r\ndotnet_diagnostic.CA6789.severity = error"), VersionStamp.Default)),
PreservationMode.PreserveValue);
var syntaxTreeAfterEditorConfigChange = await solution.GetDocument(sourceDocumentId).GetSyntaxTreeAsync();
Assert.Single(syntaxTreeAfterEditorConfigChange.DiagnosticOptions);
Assert.Equal(ReportDiagnostic.Error, syntaxTreeAfterEditorConfigChange.DiagnosticOptions["CA6789"]);
var finalCompilation = await solution.GetProject(projectId).GetCompilationAsync();
Assert.True(finalCompilation.ContainsSyntaxTree(syntaxTreeAfterEditorConfigChange));
}
private static void GetMultipleProjects(
out Project csBrokenProject,
out Project vbNormalProject,
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册