9
9
10
10
namespace RubberduckTests . AutoComplete
11
11
{
12
- [ TestFixture ]
13
- public class SelfClosingPairHandlerTests
12
+ public class SelfClosingPairTestInfo
14
13
{
15
- private bool Run ( CodeString original , CodeString prettified , char input , CodeString rePrettified , out TestCodeString testResult , bool isControlKeyDown = false , bool isDeleteKey = false )
16
- {
17
- var service = new Mock < SelfClosingPairCompletionService > ( ) ;
18
- return Run ( service , original , prettified , input , rePrettified , out testResult , isControlKeyDown , isDeleteKey ) ;
19
- }
14
+ public SelfClosingPairTestInfo ( CodeString original , char input , CodeString rePrettified )
15
+ : this ( new Mock < SelfClosingPairCompletionService > ( ) , original , original , input , rePrettified ) { }
20
16
21
- private bool Run ( Mock < SelfClosingPairCompletionService > service , CodeString original , CodeString prettified , char input , CodeString rePrettified , out TestCodeString testResult , bool isControlKeyDown = false , bool isDeleteKey = false )
17
+ public SelfClosingPairTestInfo ( CodeString original , char input )
18
+ : this ( new Mock < SelfClosingPairCompletionService > ( ) , original , original , input , original ) { }
19
+
20
+ public SelfClosingPairTestInfo ( CodeString original , CodeString prettified , char input )
21
+ : this ( new Mock < SelfClosingPairCompletionService > ( ) , original , prettified , input , prettified ) { }
22
+
23
+ public SelfClosingPairTestInfo ( Mock < SelfClosingPairCompletionService > service , CodeString original , CodeString prettified , char input , CodeString rePrettified , bool isControlKeyDown = false , bool isDeleteKey = false )
22
24
{
23
- var module = new Mock < ICodeModule > ( ) ;
24
- var handler = new Mock < ICodePaneHandler > ( ) ;
25
- handler . Setup ( e => e . GetCurrentLogicalLine ( module . Object ) ) . Returns ( original ) ;
26
- handler . SetupSequence ( e => e . Prettify ( module . Object , It . IsAny < CodeString > ( ) ) )
25
+ Original = original ;
26
+ Prettified = prettified ;
27
+ Input = input ;
28
+ RePrettified = rePrettified ;
29
+ Settings = AutoCompleteSettings . AllEnabled ;
30
+
31
+ Service = service ;
32
+ Module = new Mock < ICodeModule > ( ) ;
33
+ Handler = new Mock < ICodePaneHandler > ( ) ;
34
+ Handler . Setup ( e => e . GetCurrentLogicalLine ( Module . Object ) ) . Returns ( original ) ;
35
+ Handler . SetupSequence ( e => e . Prettify ( Module . Object , It . IsAny < CodeString > ( ) ) )
27
36
. Returns ( prettified )
28
37
. Returns ( rePrettified ) ;
29
38
30
- var settings = AutoCompleteSettings . AllEnabled ;
39
+ Args = new AutoCompleteEventArgs ( Module . Object , input , isControlKeyDown , isDeleteKey ) ;
40
+ }
41
+
42
+ public Mock < ICodeModule > Module { get ; set ; }
43
+ public Mock < SelfClosingPairCompletionService > Service { get ; set ; }
44
+ public Mock < ICodePaneHandler > Handler { get ; set ; }
45
+ public CodeString Original { get ; set ; }
46
+ public CodeString Prettified { get ; set ; }
47
+ public char Input { get ; set ; }
48
+ public CodeString RePrettified { get ; set ; }
49
+ public AutoCompleteEventArgs Args { get ; set ; }
50
+ public AutoCompleteSettings Settings { get ; set ; }
31
51
32
- var args = new AutoCompleteEventArgs ( module . Object , input , isControlKeyDown , isDeleteKey ) ;
33
- var sut = new SelfClosingPairHandler ( handler . Object , service . Object ) ;
52
+ public TestCodeString Result { get ; set ; }
53
+ }
34
54
35
- if ( sut . Handle ( args , settings , out var result ) )
55
+ [ TestFixture ]
56
+ public class SelfClosingPairHandlerTests
57
+ {
58
+ private bool Run ( SelfClosingPairTestInfo info )
59
+ {
60
+ var sut = new SelfClosingPairHandler ( info . Handler . Object , info . Service . Object ) ;
61
+ if ( sut . Handle ( info . Args , info . Settings , out var result ) )
36
62
{
37
- testResult = new TestCodeString ( result ) ;
63
+ info . Result = new TestCodeString ( result ) ;
38
64
return true ;
39
65
}
40
66
41
- testResult = null ;
67
+ info . Result = null ;
42
68
return false ;
43
69
}
44
70
@@ -47,9 +73,10 @@ public void GivenInvalidInput_ResultIsNull()
47
73
{
48
74
var input = 'A' ; // note: not a self-closing pair opening or closing character, not a handled key (e.g. '\b').
49
75
var original = "DoSomething |" . ToCodeString ( ) ;
76
+ var info = new SelfClosingPairTestInfo ( original , input ) ;
50
77
51
- Assert . IsFalse ( Run ( original , original , input , original , out var result ) ) ;
52
- Assert . IsNull ( result ) ;
78
+ Assert . IsFalse ( Run ( info ) ) ;
79
+ Assert . IsNull ( info . Result ) ;
53
80
}
54
81
55
82
[ Test ]
@@ -58,20 +85,23 @@ public void GivenValidInput_InvokesSCP()
58
85
var input = '"' ; // note: not a self-closing pair opening or closing character, not a handled key (e.g. '\b').
59
86
var original = "DoSomething |" . ToCodeString ( ) ;
60
87
var rePrettified = @"DoSomething ""|""" . ToCodeString ( ) ;
88
+ var info = new SelfClosingPairTestInfo ( original , input , rePrettified ) ;
61
89
62
- Assert . IsTrue ( Run ( original , original , input , rePrettified , out var result ) ) ;
63
- Assert . IsNotNull ( result ) ;
90
+ Assert . IsTrue ( Run ( info ) ) ;
91
+ Assert . IsNotNull ( info . Result ) ;
64
92
}
65
93
66
94
[ Test ]
67
- public void GivenOpeningParenthesisOnOtherwiseNonEmptyLine_ReturnsFalse ( )
95
+ public void GivenOpeningParenthesisOnOtherwiseNonEmptyLine_ReturnsFalseAndSwallowsKeypress ( )
68
96
{
69
97
var input = '(' ;
70
98
var original = "foo = DateSerial(Year|)" . ToCodeString ( ) ;
71
99
var rePrettified = "foo = DateSerial(Year(|))" . ToCodeString ( ) ;
100
+ var info = new SelfClosingPairTestInfo ( original , input , rePrettified ) ;
72
101
73
- Assert . IsFalse ( Run ( original , original , input , rePrettified , out var result ) ) ;
74
- Assert . IsNull ( result ) ;
102
+ Assert . IsFalse ( Run ( info ) ) ;
103
+ Assert . IsNull ( info . Result ) ;
104
+ Assert . IsTrue ( info . Args . Handled ) ;
75
105
}
76
106
}
77
107
}
0 commit comments