Skip to content

Use Scripting.Dictionary to support Word #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ End Function
Public Function Add(ParamArray Values() As Variant) As Double
Dim i As Integer
Add = 0

For i = LBound(Values) To UBound(Values)
Add = Add + Values(i)
Next i
Expand All @@ -57,10 +57,27 @@ For an advanced example of what is possible with vba-test, check out the [tests

1. Download the [latest release (v2.0.0-beta.3)](https://github.com/vba-tools/vba-test/releases)
2. Add `src/TestSuite.cls`, `src/TestCase.cls`, add `src/ImmediateReporter.cls` to your project
3. If you're starting from scratch with Excel, you can use `vba-test-blank.xlsm`

If you're starting from scratch with Excel, you can use `vba-test-blank.xlsm`

If you're updating from Excel-TDD v1, follow these [upgrade details](https://github.com/VBA-tools/vba-test/pull/23#issuecomment-416606307).

### Microsoft Word (how to fix `Dictionary` errors)

If you are using this project on Word, or otherwise see error messages
related to `Dictionary`:

- Easy option: add [@timhall's Dictionary class](https://github.com/VBA-tools/VBA-Dictionary/blob/master/Dictionary.cls)
to your project.

- Slightly more complicated option for Windows: in the VBA Editor:
- select Tools | References and make sure `Microsoft Scripting Runtime` is checked
- select Tools | Project Properties. In the `Conditional Compilation
Arguments` box, add `VBA_Test_Scripting_Dictionary=1`.

The more complicated option uses the native `Scripting.Dictionary`, so does
not require an additional VBA dependency. Take your pick!

## TestSuite

A test suite groups tests together, runs test hooks for actions that should be run before and after tests, and is responsible for passing test results to reporters.
Expand Down Expand Up @@ -108,17 +125,17 @@ With Suite.Test("specific part of your application")
.NotIncludes Array(1, 2, 3), 4
.IsApproximate 1.001, 1.002, 2
.NotApproximate 1.001, 1.009, 3

On Error Resume Next

Err.Raise vbObjectError + 1, Description:="Uh oh."
.IsError Description:="Uh oh."

Err.Clear
.NotError

.Pass
.Fail "e.g. should not have gotten here"
.Fail "e.g. should not have gotten here"
.Plan 4 ' Should only be 4 assertions, more or less fails
.Skip ' skip this test
End With
Expand Down
9 changes: 9 additions & 0 deletions src/TestCase.cls
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ Private pFailures As VBA.Collection
' --------------------------------------------- '

Public Name As String
#If VBA_Test_Scripting_Dictionary=1 Then
Public Context As Scripting.Dictionary
#Else
Public Context As Dictionary
#End If

Public Planned As Long
Public Successes As Long
Expand Down Expand Up @@ -575,7 +579,12 @@ Private Function Indent(Optional Indentation As Long)
End Function

Private Sub Class_Initialize()
#If VBA_Test_Scripting_Dictionary=1 Then
Set Me.Context = New Scripting.Dictionary
#Else
Set Me.Context = New Dictionary
#End If

Set pFailures = New VBA.Collection
End Sub

Expand Down
16 changes: 16 additions & 0 deletions tests/Tests_TestCase.bas
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,19 @@ Sub PassingAssertions(Suite As TestSuite)

.IsEqual A, B

#If VBA_Test_Scripting_Dictionary=1 Then
Set A = New Scripting.Dictionary
#Else
Set A = New Dictionary
#End If
A("a") = 1
A("b") = 2

#If VBA_Test_Scripting_Dictionary=1 Then
Set B = New Scripting.Dictionary
#Else
Set B = New Dictionary
#End If
B("a") = 1
B("b") = 2

Expand All @@ -136,11 +144,19 @@ Sub PassingAssertions(Suite As TestSuite)

.NotEqual A, B

#If VBA_Test_Scripting_Dictionary=1 Then
Set A = New Scripting.Dictionary
#Else
Set A = New Dictionary
#End If
A("a") = 1
A("b") = 2

#If VBA_Test_Scripting_Dictionary=1 Then
Set B = New Scripting.Dictionary
#Else
Set B = New Dictionary
#End If
B("a") = 2
B("b") = 1

Expand Down