Forum Discussion
MarkRoddy
16 years agoVisitor
It's kind of a long story. I'm working on brstest (new release this weekend, I swear), which examines source files to find test fixtures (which are really just function). I have some tests place which executes the inspection code to see if returns a reference to the expected function. The comparison is done by using a function 'assertEqual()'.
Previously, assertEqual() was something along the lines of:
Sub assertEqual(val1, val2)
If val1 <> val2 then
m.DoSomethingToHandleTestFailure()
End If
End Sub
This was fine for strings, floats, ints, and apparently functions, but I wanted to extend it to handle other more common data types (lists, dictionaries, arrays, etc). So what I did was write a comparison function for each 'type', built a dispatch table mapping the string identifier of the type to the function that does the comparison, and add an addition function which does the dispatching (this is how my previous question on the dot operator came up). When I put this in place the test described above started failing as the dispatch table didn't have an entry for roFunction objects. This was pretty easy to add (since all it takes is an '=' comparison), but I wanted to confirm the semantics of function comparison before I did my next release.
-Mark
Previously, assertEqual() was something along the lines of:
Sub assertEqual(val1, val2)
If val1 <> val2 then
m.DoSomethingToHandleTestFailure()
End If
End Sub
This was fine for strings, floats, ints, and apparently functions, but I wanted to extend it to handle other more common data types (lists, dictionaries, arrays, etc). So what I did was write a comparison function for each 'type', built a dispatch table mapping the string identifier of the type to the function that does the comparison, and add an addition function which does the dispatching (this is how my previous question on the dot operator came up). When I put this in place the test described above started failing as the dispatch table didn't have an entry for roFunction objects. This was pretty easy to add (since all it takes is an '=' comparison), but I wanted to confirm the semantics of function comparison before I did my next release.
-Mark