public void AnnotateDeclarationRefactoringAction_NumberArgument() { const string code = @" Public Sub Foo() End Sub "; const string expectedCode = @" '@MemberAttribute VB_UserMemId, 0 Public Sub Foo() End Sub "; Func <RubberduckParserState, AnnotateDeclarationModel> modelBuilder = (state) => { var module = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .Single(); var annotation = new MemberAttributeAnnotation(); var arguments = new List <TypedAnnotationArgument> { new TypedAnnotationArgument(AnnotationArgumentType.Attribute, "VB_UserMemId"), new TypedAnnotationArgument(AnnotationArgumentType.Number, "0") }; return(new AnnotateDeclarationModel(module, annotation, arguments)); }; var refactoredCode = RefactoredCode(code, modelBuilder); Assert.AreEqual(expectedCode, refactoredCode); }
public void UpdateAnnotationReplacesEntireAnnotation() { const string inputCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete @Description ""Desc"" @DefaultMember Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete @MemberAttribute VB_ExtKey, ""Key"", ""Value"" @DefaultMember Public Sub Foo(bar As String) bar = vbNullString End Sub "; var newAnnotation = new MemberAttributeAnnotation(); var newAnnotationValues = new List <string> { "VB_ExtKey", "\"Key\"", "\"Value\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var fooDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .First(decl => decl.IdentifierName == "Foo"); var annotationToUpdate = fooDeclaration.Annotations.First(pta => pta.Annotation is DescriptionAnnotation); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.UpdateAnnotation(rewriteSession, annotationToUpdate, newAnnotation, newAnnotationValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void AddAnnotationDoesNotAddMemberAnnotationsToModules() { const string inputCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"'@PredeclaredId Option Explicit '@Folder ""folder"" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; var annotationToAdd = new MemberAttributeAnnotation(); var annotationValues = new List <string> { "VB_Ext_Key", "\"Key\"", "\"Value\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var moduleDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.ProceduralModule) .First(); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.AddAnnotation(rewriteSession, moduleDeclaration, annotationToAdd, annotationValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void AddAnnotationAddsMemberAnnotationRightAboveMember() { const string inputCode = @" Private Sub FooBar() End Sub '@Obsolete Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @" Private Sub FooBar() End Sub '@Obsolete '@MemberAttribute VB_Ext_Key, ""Key"", ""Value"" Public Sub Foo(bar As String) bar = vbNullString End Sub "; var annotationToAdd = new MemberAttributeAnnotation(); var annotationValues = new List <string> { "VB_Ext_Key", "\"Key\"", "\"Value\"" }; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var fooDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.Procedure) .First(decl => decl.IdentifierName == "Foo"); var annotationUpdater = new AnnotationUpdater(); annotationUpdater.AddAnnotation(rewriteSession, fooDeclaration, annotationToAdd, annotationValues); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void MemberAttributeAnnotation_TypeIsMemberAttribute() { var annotation = new MemberAttributeAnnotation(new QualifiedSelection(), null, new[] { "Attribute", "Value" }); Assert.AreEqual(AnnotationType.MemberAttribute, annotation.AnnotationType); }