VBA-tools / vba-test

Add testing and TDD to VBA on Windows and Mac
MIT License
205 stars 46 forks source link

ArrayIncludes() cannot handle multi-dimension arrays #30

Open connerk opened 6 years ago

connerk commented 6 years ago

example test:

Tests.test("range should contain value").Includes myRange.value2, "myValue"

an error occurs because myRange.Value2 is a 2 dimensional array.

in ArrayIncludes(), called by Includes() VBA.IsArray(Value(i)) causes an error if Value() is multidimensional

connerk commented 6 years ago

quick fix without editing the vba-test library is to run all multi-dimensional arrays through this

Public Function ArrayToFlatCollection(a As Variant) As Collection
    Dim c As New Collection
    Dim item As Variant
    If VBA.TypeName(a) Like "*()" Then
        For Each item In a
          c.Add item
        Next item
    Else
        c.Add a
    End If
    Set ArrayToFlatCollection = c
End Function

as such

Tests.test("range should contain value").Includes ArrayToFlatCollection(myRange.value2), "myValue"