public void AnnotateDeclarationRefactoringAction_AdjustAttributeSet_AttributeNotThere_AdjustsAttribute_ModuleVariable()
        {
            const string code         = @"
Public MyVariable As Variant
Attribute MyVariable.VB_VarDescription = ""NotMyDesc""

Public Sub Foo()
End Sub
";
            const string expectedCode = @"
'@VariableDescription ""MyDesc""
Public MyVariable As Variant
Attribute MyVariable.VB_VarDescription = ""MyDesc""

Public Sub Foo()
End Sub
";
            Func <RubberduckParserState, AnnotateDeclarationModel> modelBuilder = (state) =>
            {
                var declaration = state.DeclarationFinder
                                  .UserDeclarations(DeclarationType.Variable)
                                  .Single();
                var annotation = new VariableDescriptionAnnotation();
                var arguments  = new List <TypedAnnotationArgument>
                {
                    new TypedAnnotationArgument(AnnotationArgumentType.Text, "MyDesc")
                };

                return(new AnnotateDeclarationModel(declaration, annotation, arguments, true));
            };

            var refactoredCode = RefactoredCode(code, modelBuilder);

            Assert.AreEqual(expectedCode, refactoredCode);
        }
        public void AnnotateDeclarationRefactoringAction_AdjustAttributeSet_NoAttributeContext_LocalVariable_Throws()
        {
            const string code = @"

Public Sub Foo()
    Dim MyVariable As Variant
End Sub
";
            Func <RubberduckParserState, AnnotateDeclarationModel> modelBuilder = (state) =>
            {
                var declaration = state.DeclarationFinder
                                  .UserDeclarations(DeclarationType.Variable)
                                  .Single();
                var annotation = new VariableDescriptionAnnotation();
                var arguments  = new List <TypedAnnotationArgument>
                {
                    new TypedAnnotationArgument(AnnotationArgumentType.Text, "MyDesc")
                };

                return(new AnnotateDeclarationModel(declaration, annotation, arguments, true));
            };

            Assert.Throws <AttributeRewriteSessionNotSupportedException>(() => RefactoredCode(code, modelBuilder));
        }
Esempio n. 3
0
        public void VariableDescriptionAnnotation_TypeIsModuleDescription()
        {
            var annotation = new VariableDescriptionAnnotation(new QualifiedSelection(), null, new[] { "Desc" });

            Assert.AreEqual(AnnotationType.VariableDescription, annotation.AnnotationType);
        }