Public Function IsGoodWordWrap() As Boolean
' verify correct WordWrap returns, 20040913
' returns True if all tests are passed
Dim fFailed As Boolean
' replace "WordWrap01" with the name of your function to test
If WordWrap01("ab cdef ghi", 2) <> "ab " & vbCrLf & "cd" & vbCrLf & "ef " & vbCrLf & "gh" & vbCrLf & "i" Then Stop: fFailed = True
If WordWrap01("ab cdef ghi", 3) <> "ab " & vbCrLf & "cde" & vbCrLf & "f " & vbCrLf & "ghi" Then Stop: fFailed = True
If WordWrap01("ab cdef ghi", 4) <> "ab " & vbCrLf & "cdef " & vbCrLf & "ghi" Then Stop: fFailed = True
If WordWrap01("ab-cdef-ghi", 4) <> "ab-" & vbCrLf & "cdef-" & vbCrLf & "ghi" Then Stop: fFailed = True
If WordWrap01("ab-cdef-ghi ", 4) <> "ab-" & vbCrLf & "cdef-" & vbCrLf & "ghi " Then Stop: fFailed = True
If WordWrap01("abcde", 0) <> "" Then Stop: fFailed = True
If WordWrap01("abcde", 1) <> "a" & vbCrLf & "b" & vbCrLf & "c" & vbCrLf & "d" & vbCrLf & "e" Then Stop: fFailed = True
If WordWrap01("abcde", 2) <> "ab" & vbCrLf & "cd" & vbCrLf & "e" Then Stop: fFailed = True
If WordWrap01("abcde", 3) <> "abc" & vbCrLf & "de" Then Stop: fFailed = True
If WordWrap01("abcde", 4) <> "abcd" & vbCrLf & "e" Then Stop: fFailed = True
If WordWrap01("abcde", 5) <> "abcde" Then Stop: fFailed = True
If WordWrap01("abcde", 6) <> "abcde" Then Stop: fFailed = True
If WordWrap01("", 5) <> "" Then Stop: fFailed = True
' No line breaks at the very end of the output
If WordWrap01("a ", 1) <> "a " Then Stop: fFailed = True
' returned line count
Dim cntLines As Long
WordWrap01 "abcde", 1, cntLines: If cntLines <> 5 Then Stop: fFailed = True
WordWrap01 "abcde", 2, cntLines: If cntLines <> 3 Then Stop: fFailed = True
WordWrap01 "abcde", 6, cntLines: If cntLines <> 1 Then Stop: fFailed = True
WordWrap01 "abcde", 0, cntLines: If cntLines <> 0 Then Stop: fFailed = True
' well done
IsGoodWordWrap = Not fFailed
End Function
Back to WordWrap