Skip to content

Commit

Permalink
add Regular Expression matching to SpecExpectation
Browse files Browse the repository at this point in the history
  • Loading branch information
connerk committed Jun 26, 2018
1 parent 275cfd1 commit b1a80e3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/SpecExpectation.cls
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,28 @@ Private Function Matches(Actual As Variant, Expected As Variant) As Variant
End If
End Function

Public Sub ToMatchRegEx(Expected As Variant)
Check MatchesRegEx(Me.Actual, Expected), "to match the pattern", Expected:=Expected
End Sub

Private Function MatchesRegEx(Actual As Variant, Expected As Variant) As Variant
Dim RE As Object, REMatches As Object

Set RE = CreateObject("vbscript.regexp")
With RE
.MultiLine = False
.Global = False
.IgnoreCase = False
.Pattern = Expected
End With

Set REMatches = RE.Execute(Actual)
If REMatches.Count > 0 Then
MatchesRegEx = True
Else
MatchesRegEx = False
End If
End Function
''
' Run custom matcher
'
Expand Down

0 comments on commit b1a80e3

Please sign in to comment.