-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgrammingToolsTestModule.bas
More file actions
191 lines (156 loc) · 5.48 KB
/
ProgrammingToolsTestModule.bas
File metadata and controls
191 lines (156 loc) · 5.48 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
Attribute VB_Name = "ProgrammingToolsTestModule"
Option Explicit
Option Private Module
'@TestModule
'@Folder("Tests")
Private Assert As Object
Private Fakes As Object
'@ModuleInitialize
Private Sub ModuleInitialize()
'this method runs once per module.
Set Assert = CreateObject("Rubberduck.AssertClass")
Set Fakes = CreateObject("Rubberduck.FakesProvider")
End Sub
'@ModuleCleanup
Private Sub ModuleCleanup()
'this method runs once per module.
Set Assert = Nothing
Set Fakes = Nothing
End Sub
'@TestInitialize
Private Sub TestInitialize()
'This method runs before every test in the module..
End Sub
'@TestCleanup
Private Sub TestCleanup()
'this method runs after every test in the module.
End Sub
'@TestMethod("Uncategorized")
Private Sub TestCodepointToVBACode()
On Error GoTo TestFail
'Arrange:
'Act:
'Assert:
Assert.AreEqual ProgrammingTools.CodepointToVBACode(0), "vbNullChar"
Assert.AreEqual ProgrammingTools.CodepointToVBACode(8), "vbBack"
Assert.AreEqual ProgrammingTools.CodepointToVBACode(9), "vbTab"
Assert.AreEqual ProgrammingTools.CodepointToVBACode(&HA), "vbLf"
Assert.AreEqual ProgrammingTools.CodepointToVBACode(&HC), "vbFormFeed"
Assert.AreEqual ProgrammingTools.CodepointToVBACode(&HD), "vbCr"
Assert.AreEqual ProgrammingTools.CodepointToVBACode(&HB), "vbVerticalTab"
Assert.AreEqual ProgrammingTools.CodepointToVBACode(&H3000), "ChrW$(&H3000)"
TestExit:
Exit Sub
TestFail:
Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
Resume TestExit
End Sub
'@TestMethod("Uncategorized")
Private Sub TestConvertUnicodeTextToVBACode() 'TODO Rename test
On Error GoTo TestFail
'Arrange:
Dim inputs As New Collection
Dim outputs As New Collection
Dim expectedOutputs As New Collection
Dim sld As Slide
Dim shp As Shape
Dim testTable As Table
Dim i As Long
'get the table containing the relevant results
Set sld = ActivePresentation.Slides.Item(8)
For Each shp In sld.Shapes.Range
If shp.HasTable Then Set testTable = shp.Table
Next shp
For i = 2 To testTable.Rows.Count
inputs.Add testTable.Rows(i).Cells(2).Shape.TextFrame2.TextRange.text
expectedOutputs.Add testTable.Rows(i).Cells(3).Shape.TextFrame2.TextRange.text
Next i
'Act:
For i = 1 To inputs.Count
outputs.Add ProgrammingTools.ConvertUnicodeTextToVBACode(inputs.Item(i))
Next i
'Assert:
Assert.IsNotNothing testTable, "Failed to find test data"
For i = 1 To inputs.Count
Assert.AreEqual outputs.Item(i), expectedOutputs.Item(i), "Failed on input: " & inputs.Item(i) & " | Expected: " & expectedOutputs.Item(i) & "| Output: " & outputs.Item(i)
Next i
TestExit:
Exit Sub
TestFail:
Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
Resume TestExit
End Sub
'@TestMethod("Uncategorized")
Private Sub TestAscWLong()
On Error GoTo TestFail
'Arrange:
Dim inputs As New Collection
Dim outputs As New Collection
Dim expectedOutputs As New Collection
Dim sld As Slide
Dim shp As Shape
Dim testTable As Table
Dim i As Long
'get the table containing the relevant results
Set sld = ActivePresentation.Slides.Item(9)
For Each shp In sld.Shapes.Range
If shp.HasTable Then Set testTable = shp.Table
Next shp
inputs.Add vbNullChar
expectedOutputs.Add 0&
inputs.Add "A"
expectedOutputs.Add &H41&
inputs.Add testTable.Rows(4).Cells(2).Shape.TextFrame2.TextRange.text
expectedOutputs.Add &H3001&
inputs.Add testTable.Rows(5).Cells(2).Shape.TextFrame2.TextRange.text
expectedOutputs.Add &HFFE5&
'Act:
For i = 1 To inputs.Count
outputs.Add ProgrammingTools.AscWLong(inputs.Item(i))
Next i
'Assert:
Assert.IsNotNothing testTable, "Failed to find test data"
For i = 1 To inputs.Count
Assert.AreEqual outputs.Item(i), expectedOutputs.Item(i), "Failed on input: " & inputs.Item(i)
Next i
TestExit:
Exit Sub
TestFail:
Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
Resume TestExit
End Sub
'@TestMethod("Uncategorized")
Private Sub TestConvertChrWCallsToUnicode()
On Error GoTo TestFail
'Arrange:
Dim inputs As New Collection
Dim outputs As New Collection
Dim expectedOutputs As New Collection
Dim sld As Slide
Dim shp As Shape
Dim testTable As Table
Dim i As Long
'get the table containing the relevant results
Set sld = ActivePresentation.Slides.Item(10)
For Each shp In sld.Shapes.Range
If shp.HasTable Then Set testTable = shp.Table
Next shp
For i = 2 To testTable.Rows.Count
inputs.Add testTable.Rows(i).Cells(2).Shape.TextFrame2.TextRange.text
expectedOutputs.Add testTable.Rows(i).Cells(3).Shape.TextFrame2.TextRange.text
Next i
'Act:
For i = 1 To inputs.Count
outputs.Add ProgrammingTools.ConvertChrWCallsToUnicode(inputs.Item(i))
Next i
'Assert:
Assert.IsNotNothing testTable, "Failed to find test data"
For i = 1 To inputs.Count
Assert.AreEqual outputs.Item(i), expectedOutputs.Item(i), "Failed on input: " & inputs.Item(i) & " | Expected: " & expectedOutputs.Item(i) & "| Output: " & outputs.Item(i)
Next i
TestExit:
Exit Sub
TestFail:
Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
Resume TestExit
End Sub