Skip to content

Commit 73c72aa

Browse files
committed
add behaviours for getting extracted declaration
1 parent 837ae9f commit 73c72aa

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

RetailCoder.VBE/Refactorings/ExtractMethod/IExtractMethodRule.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ public class ExtractMethodRuleExternalReference : IExtractMethodRule
3636
{
3737
public void setValidFlag(ref byte flags, IdentifierReference reference, Selection selection)
3838
{
39+
var decStartLine = reference.Declaration.Selection.StartLine;
3940
if (reference.Selection.StartLine > selection.EndLine &&
40-
selection.StartLine <= reference.Declaration.Selection.StartLine &&
41-
reference.Declaration.Selection.StartLine <= selection.EndLine)
41+
selection.StartLine <= decStartLine && decStartLine <= selection.EndLine)
4242
{
43-
4443
flags = (byte)(flags | (byte)ExtractMethodRuleFlags.IsExternallyReferenced);
4544
}
4645
}

RubberduckTests/Refactoring/ExtractMethod/ExtractMethodModelTests.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,65 @@
1111

1212
namespace RubberduckTests.Refactoring.ExtractMethod
1313
{
14+
[TestClass]
15+
public class ExtractMethodRuleExternalReferenceTests
16+
{
17+
18+
[TestClass]
19+
public class WhenSetValidFlagIsCalledWhenTheReferenceIsInternal: ExtractMethodRuleExternalReferenceTests
20+
{
21+
[TestMethod]
22+
[TestCategory("ExtractMethodRuleTests")]
23+
public void shouldSetTheFlag()
24+
{
25+
byte flag = new byte();
26+
var usedSelection = new Selection(4, 1, 7, 10);
27+
var referenceSelection = new Selection(8, 1, 8, 10);
28+
29+
var decQualifiedMemberName = new QualifiedMemberName(new QualifiedModuleName(),"");
30+
var decSelection = new Selection(5,1,5,10);
31+
var referenceDeclaration = new Declaration(decQualifiedMemberName, null, "", "", "",
32+
false, false, Accessibility.Friend, DeclarationType.ClassModule,
33+
context: null, selection: decSelection, isArray: false, asTypeContext: null);
34+
35+
IdentifierReference reference = new IdentifierReference(new QualifiedModuleName(), null, null, "a", referenceSelection, null, referenceDeclaration);
36+
37+
var SUT = new ExtractMethodRuleExternalReference();
38+
SUT.setValidFlag(ref flag, reference, usedSelection);
39+
var expected = ((byte)ExtractMethodRuleFlags.IsExternallyReferenced);
40+
Assert.AreEqual(expected, flag);
41+
}
42+
}
43+
44+
[TestClass]
45+
public class WhenSetValidFlagIsCalledWhenTheReferenceIsUsedInternallyOnly : ExtractMethodRuleExternalReferenceTests
46+
{
47+
[TestMethod]
48+
[TestCategory("ExtractMethodRuleTests")]
49+
public void shouldNotSetFlag()
50+
{
51+
byte flag = new byte();
52+
var usedSelection = new Selection(4, 1, 7, 10);
53+
54+
var referenceSelection = new Selection(7, 1, 7, 10);
55+
56+
var decQualifiedMemberName = new QualifiedMemberName(new QualifiedModuleName(),"");
57+
var decSelection = new Selection(5,1,5,10);
58+
var referenceDeclaration = new Declaration(decQualifiedMemberName, null, "", "", "",
59+
false, false, Accessibility.Friend, DeclarationType.ClassModule,
60+
context: null, selection: decSelection, isArray: false, asTypeContext: null);
61+
62+
IdentifierReference reference = new IdentifierReference(new QualifiedModuleName(), null, null, "a", referenceSelection, null, referenceDeclaration);
63+
64+
var SUT = new ExtractMethodRuleExternalReference();
65+
SUT.setValidFlag(ref flag, reference, usedSelection);
66+
67+
Assert.AreEqual(0, flag);
68+
69+
}
70+
}
71+
}
72+
1473
[TestClass]
1574
public class ExtractMethodRuleInSelectionTests
1675
{

0 commit comments

Comments
 (0)