Skip to content

Commit f6a351d

Browse files
committed
Fix ReplaceObsoleteCommentMarkerQuickFix - account for line continuations.
1 parent eb029c4 commit f6a351d

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

RetailCoder.VBE/Inspections/QuickFixes/ReplaceObsoleteCommentMarkerQuickFix.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ public override void Fix()
2828
var newComment = commentLine.Substring(0, Context.Start.Column) +
2929
Tokens.CommentMarker +
3030
comment.Substring(Tokens.Rem.Length, comment.Length - Tokens.Rem.Length);
31-
31+
32+
var lines = Selection.Selection.LineCount;
33+
if (lines > 1)
34+
{
35+
module.DeleteLines(start + 1, lines - 1);
36+
}
3237
module.ReplaceLine(start, newComment);
3338
}
3439
}

RubberduckTests/Inspections/ObsoleteCommentSyntaxInspectionTests.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,46 @@ public void ObsoleteCommentSyntax_QuickFixWorks_UpdateComment()
241241
Assert.AreEqual(expectedCode, actualCode);
242242
}
243243

244+
[TestMethod]
245+
[TestCategory("Inspections")]
246+
public void ObsoleteCommentSyntax_QuickFixWorks_UpdateCommentHasContinuation()
247+
{
248+
const string inputCode =
249+
@"Rem this is _
250+
a comment";
251+
252+
const string expectedCode =
253+
@"' this is _
254+
a comment";
255+
256+
//Arrange
257+
var settings = new Mock<IGeneralConfigService>();
258+
var config = GetTestConfig();
259+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
260+
261+
var builder = new MockVbeBuilder();
262+
IVBComponent component;
263+
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
264+
var project = vbe.Object.VBProjects[0];
265+
var module = project.VBComponents[0].CodeModule;
266+
var mockHost = new Mock<IHostApplication>();
267+
mockHost.SetupAllProperties();
268+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock<ISinks>().Object));
269+
270+
parser.Parse(new CancellationTokenSource());
271+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
272+
273+
var inspection = new ObsoleteCommentSyntaxInspection(parser.State);
274+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
275+
276+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
277+
278+
inspectionResults.First().QuickFixes.Single(s => s is ReplaceObsoleteCommentMarkerQuickFix).Fix();
279+
280+
var actualCode = module.Content();
281+
Assert.AreEqual(expectedCode, actualCode);
282+
}
283+
244284
[TestMethod]
245285
[TestCategory("Inspections")]
246286
public void ObsoleteCommentSyntax_QuickFixWorks_RemoveComment()
@@ -354,6 +394,46 @@ public void ObsoleteCommentSyntax_QuickFixWorks_UpdateComment_LineHasCode()
354394
Assert.AreEqual(expectedCode, actualCode);
355395
}
356396

397+
[TestMethod]
398+
[TestCategory("Inspections")]
399+
public void ObsoleteCommentSyntax_QuickFixWorks_UpdateComment_LineHasCodeAndContinuation()
400+
{
401+
const string inputCode =
402+
@"Dim Foo As Integer: Rem This is _
403+
a comment";
404+
405+
const string expectedCode =
406+
@"Dim Foo As Integer: ' This is _
407+
a comment";
408+
409+
//Arrange
410+
var settings = new Mock<IGeneralConfigService>();
411+
var config = GetTestConfig();
412+
settings.Setup(x => x.LoadConfiguration()).Returns(config);
413+
414+
var builder = new MockVbeBuilder();
415+
IVBComponent component;
416+
var vbe = builder.BuildFromSingleStandardModule(inputCode, out component);
417+
var project = vbe.Object.VBProjects[0];
418+
var module = project.VBComponents[0].CodeModule;
419+
var mockHost = new Mock<IHostApplication>();
420+
mockHost.SetupAllProperties();
421+
var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock<ISinks>().Object));
422+
423+
parser.Parse(new CancellationTokenSource());
424+
if (parser.State.Status >= ParserState.Error) { Assert.Inconclusive("Parser Error"); }
425+
426+
var inspection = new ObsoleteCommentSyntaxInspection(parser.State);
427+
var inspector = new Inspector(settings.Object, new IInspection[] { inspection });
428+
429+
var inspectionResults = inspector.FindIssuesAsync(parser.State, CancellationToken.None).Result;
430+
431+
inspectionResults.First().QuickFixes.Single(s => s is ReplaceObsoleteCommentMarkerQuickFix).Fix();
432+
433+
var actualCode = module.Content();
434+
Assert.AreEqual(expectedCode, actualCode);
435+
}
436+
357437
[TestMethod]
358438
[TestCategory("Inspections")]
359439
public void ObsoleteCommentSyntax_QuickFixWorks_RemoveComment_LineHasCode()

0 commit comments

Comments
 (0)