3 Dim passCount
As Integer
4 Dim failCount
As Integer
7 Function doUnitTest() As String
8 result
= verify_testReplace()
9 If failCount
<> 0 And passCount
> 0 Then
16 Function verify_testReplace() as String
20 result
= "Test Results" & Chr
$(10) & "============" & Chr
$(10)
22 Dim testName
As String
23 Dim srcStr
, destStr
, repStr
, start
, count
, retStr
24 testName
= "Test Replace function"
25 On Error GoTo errorHandler
29 retStr
= Replace(srcStr
, destStr
, repStr
)
30 TestLog_ASSERT retStr
= "aefefdBc", "common string:" & retStr
31 retStr
= Replace("abcbcdbc", destStr
, repStr
)
32 TestLog_ASSERT retStr
= "aefefdef", "expression string:" & retStr
33 retStr
= Replace(srcStr
, destStr
, repStr
, 1, -1, vbBinaryCompare
)
34 TestLog_ASSERT retStr
= "aefefdBc", "binanary compare:" & retStr
35 retStr
= Replace(srcStr
, destStr
, repStr
, 1, -1, vbTextCompare
)
36 TestLog_ASSERT retStr
= "aefefdef", "text compare:" & retStr
37 retStr
= Replace(srcStr
, destStr
, repStr
, compare:=vbTextCompare
)
38 TestLog_ASSERT retStr
= "aefefdef", "text compare:" & retStr
39 retStr
= Replace(srcStr
, destStr
, repStr
, 3, -1, vbBinaryCompare
)
40 TestLog_ASSERT retStr
= "cefdBc", "start = 3:" & retStr
41 retStr
= Replace(srcStr
, destStr
, repStr
, 1, 2, vbBinaryCompare
)
42 TestLog_ASSERT retStr
= "aefefdBc", "count = 2: " & retStr
43 retStr
= Replace(srcStr
, destStr
, repStr
, 1, 0, vbBinaryCompare
)
44 TestLog_ASSERT retStr
= "abcbcdBc", "start = 1, count = 0, not support in Unix: " & retStr
45 result
= result
& Chr
$(10) & "Tests passed: " & passCount
& Chr
$(10) & "Tests failed: " & failCount
& Chr
$(10)
46 verify_testReplace
= result
50 TestLog_ASSERT (False), testName
& ": hit error handler"
53 Sub TestLog_ASSERT(assertion
As Boolean, Optional testId
As String, Optional testComment
As String)
55 If assertion
= True Then
56 passCount
= passCount
+ 1
59 If Not IsMissing(testId
) Then
60 testMsg
= testMsg
+ " : " + testId
62 If Not IsMissing(testComment
) And Not (testComment
= "") Then
63 testMsg
= testMsg
+ " (" + testComment
+ ")"
66 result
= result
& Chr
$(10) & " Failed: " & testMsg
67 failCount
= failCount
+ 1