public void RemoveAttributeWithValuesSpecifiedRemovesOnlyEntriesForTheAttributeWithSpecifiedValuesForMembers() { const string inputCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False Public Sub Foo(bar As String) Attribute Foo.VB_Ext_Key = ""Key"", ""Value"" Attribute Foo.VB_Ext_Key = ""OtherKey"", ""Value"" Attribute Foo.VB_Description = ""Desc"" bar = vbNullString End Sub "; const string expectedCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False Public Sub Foo(bar As String) Attribute Foo.VB_Ext_Key = ""OtherKey"", ""Value"" Attribute Foo.VB_Description = ""Desc"" bar = vbNullString End Sub "; var attributesToRemove = "Foo.VB_Ext_Key"; var valuesToRemove = new List <string> { "\"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 attributesUpdater = new AttributesUpdater(state); attributesUpdater.RemoveAttribute(rewriteSession, fooDeclaration, attributesToRemove, valuesToRemove); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }
public void RemoveAttributeWithoutValuesSpecifiedRemovesAllEntriesForTheAttributeForModules() { const string inputCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False Attribute VB_Ext_Key = ""Key"", ""Value"" Attribute VB_Ext_Key = ""OtherKey"", ""Value"" Public Sub Foo(bar As String) bar = vbNullString End Sub "; const string expectedCode = @"VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = ""ClassKeys"" Attribute VB_GlobalNameSpace = False Public Sub Foo(bar As String) bar = vbNullString End Sub "; var attributesToRemove = "VB_Ext_Key"; string actualCode; var(component, rewriteSession, state) = TestSetup(inputCode); using (state) { var moduleDeclaration = state.DeclarationFinder .UserDeclarations(DeclarationType.ProceduralModule) .First(); var attributesUpdater = new AttributesUpdater(state); attributesUpdater.RemoveAttribute(rewriteSession, moduleDeclaration, attributesToRemove); rewriteSession.TryRewrite(); actualCode = component.CodeModule.Content(); } Assert.AreEqual(expectedCode, actualCode); }