Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

At this point I realized that I'd named my global procedure as if it were the test. So I renamed it to

ReplaceCharactersInAString

and I called my new test 

ReplaceCharactersInAString_VerifyResult

Then I realized that by creating the test via the Tests node in the Project Explorer I was getting a completely blank test; instead, I wanted a test already configured to use my procedure. So I decided to delete the test.

And I found that I couldn't delete just one test. I could delete the entire set, but not the one test. If someone knows a way to do this, please let me know. Perhaps it's a safety feature to prevent tests from being accidentally deleted. But I'd still like to be the one making that decision.

As a workaround I renamed the empty test I'd created. Then I right-clicked on my ReplaceCharactersInAString procedure and chose Create a unit test. 

I changed the new unit test's properties to specify the data types and a more meaningful name for the return value:

Image Added

When I tried running the test, however, I got an "Unable to assign the element" error. I had to change my code to copy the passed string to a local string, modify that, then return the local string. 

Code Block
PROCEDURE ReplaceCharactersInAString(baseString,newCharacters,startPos)
endPos is int
newString is string
newString = baseString
endPos = startPos + Length(newCharacters) - 1
newString[[startPos TO endPos]] = newCharacters
RESULT newString

I set up a few test iterations with different parameters. In particular I wondered what would happen with what seemed like invalid values. 

Image Added

The first three iterations all passed. The last two did not:

Image Added

This suggests to me that strings in WinDev are more like .NET strings than like Clarion strings. In .NET, strings are immutable, meaning you can't change them; when you make what appears to be a change to an existing string, you're actually creating a new string to contain the result. I'm thinking a similar process is at work in the W language. 

Resume your normal (string) route

As much as I like unit testing, I'm going to leave that for now and go back to the tutorial, which on page 57 is still on the subject of strings.

WinDev has the usual complement of string handling functions, including Upper(), Lower(), Left(), Right(), Length() etc. Trimming space characters is often important: the equivalent to a Clarion Clip(Left()) is NoSpace() which removes leading and trailing spaces. The string handling library is extensive - you can find a complete listing of functions here

Handling numeric values

Numeric values are assigned using the usual operators, and you can also concatenate strings and numerics directly without having to cast the numeric values. Since + is both the concatenation and the addition operator, if you want to do addition instead of concatenation you should enclose the operation in parentheses. 

As with strings, the online help lists the extensive numeric function library

And just like that, I'm out of time again. Friday is my regular day off in this series, so I'll back on Monday on page 60, and I hope not to stay on track for at least a couple of days!