public void NoResultGivenMemberDescriptionAttribute_WithAnnotation() { const string testModuleName = "Test"; const string inputCode = @" VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = """ + testModuleName + @""" ' (ignored) Attribute VB_GlobalNameSpace = False ' (ignored) Attribute VB_Creatable = False ' (ignored) Attribute VB_PredeclaredId = False ' Must be False Attribute VB_Exposed = False ' Must be False Option Explicit '@Description(""Does something"") Sub DoSomething() Attribute DoSomething.VB_Description = ""Does something"" End Sub "; var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, testModuleName, ComponentType.ClassModule, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new MissingAnnotationInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; Assert.IsFalse(inspectionResults.Any()); }
public void HasResultGivenPredeclaredIdAttribute_NoAnnotation() { const string testModuleName = "Test"; const string inputCode = @" VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = """ + testModuleName + @""" ' (ignored) Attribute VB_GlobalNameSpace = False ' (ignored) Attribute VB_Creatable = False ' (ignored) Attribute VB_PredeclaredId = True ' Must be True Attribute VB_Exposed = False ' Must be False Option Explicit "; var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, testModuleName, ComponentType.ClassModule, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new MissingAnnotationInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var inspectionResults = inspector.FindIssuesAsync(state, CancellationToken.None).Result; Assert.AreEqual(1, inspectionResults.Count()); }
public void AddsMissingDescriptionAnnotation() { const string testModuleName = "Test"; const string inputCode = @" VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = """ + testModuleName + @""" ' (ignored) Option Explicit Sub DoSomething() Attribute DoSomething.VB_Description = ""Does something"" End Sub"; const string expectedCode = @" VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = """ + testModuleName + @""" ' (ignored) Option Explicit '@Description(""Does something"") Sub DoSomething() Attribute DoSomething.VB_Description = ""Does something"" End Sub"; var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, testModuleName, ComponentType.ClassModule, out _); var state = MockParser.CreateAndParse(vbe.Object); var inspection = new MissingAnnotationInspection(state); var inspector = InspectionsHelper.GetInspector(inspection); var result = inspector.FindIssuesAsync(state, CancellationToken.None).Result?.SingleOrDefault(); if (result?.Context.GetType() != typeof(VBAParser.AttributeStmtContext)) { Assert.Inconclusive("Inspection failed to return a result."); } var fix = new SynchronizeAttributesQuickFix(state); fix.Fix(result); var rewriter = state.GetRewriter(result.QualifiedSelection.QualifiedName); var actual = rewriter.GetText(); Assert.AreEqual(expectedCode, actual); }