-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathUntypedFunctionUsageQuickFixTests.cs
66 lines (56 loc) · 2.34 KB
/
UntypedFunctionUsageQuickFixTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Linq;
using System.Threading;
using NUnit.Framework;
using Rubberduck.CodeAnalysis.Inspections.Concrete;
using Rubberduck.CodeAnalysis.QuickFixes.Concrete;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor.SafeComWrappers;
using RubberduckTests.Mocks;
namespace RubberduckTests.QuickFixes
{
[TestFixture]
public class UntypedFunctionUsageQuickFixTests
{
[Test]
[Category("QuickFixes")]
[Ignore("Broken feature - passes locally but not in AV. See FIXME in the notes")]
public void UntypedFunctionUsage_QuickFixWorks()
{
const string inputCode =
@"Sub Foo()
Dim str As String
str = Left(""test"", 1)
End Sub";
const string expectedCode =
@"Sub Foo()
Dim str As String
str = Left$(""test"", 1)
End Sub";
var builder = new MockVbeBuilder();
var project = builder.ProjectBuilder("VBAProject", ProjectProtection.Unprotected)
.AddComponent("MyClass", ComponentType.ClassModule, inputCode)
.AddReference(ReferenceLibrary.VBA)
.Build();
var vbe = builder.AddProject(project).Build();
var component = project.Object.VBComponents[0];
var (parser, rewriteManager) = MockParser.CreateWithRewriteManager(vbe.Object);
using (var state = parser.State)
{
// FIXME reinstate and unignore tests
// refers to "UntypedFunctionUsageInspectionTests.GetBuiltInDeclarations()"
//GetBuiltInDeclarations().ForEach(d => parser.State.AddDeclaration(d));
parser.Parse(new CancellationTokenSource());
if (state.Status >= ParserState.Error)
{
Assert.Inconclusive("Parser Error");
}
var inspection = new UntypedFunctionUsageInspection(state);
var inspectionResults = inspection.GetInspectionResults(CancellationToken.None);
var rewriteSession = rewriteManager.CheckOutCodePaneSession();
new UntypedFunctionUsageQuickFix().Fix(inspectionResults.First(), rewriteSession);
var actualCode = rewriteSession.CheckOutModuleRewriter(component.QualifiedModuleName).GetText();
Assert.AreEqual(expectedCode, actualCode);
}
}
}
}