assertThat(me, is_(aBlogPost()).and_(is_(interesting())) :-)
A few days ago I found Hamcrest on the web. It's a framework, which lets you write validation rules in almost plain english:
Dim value as Variant value = "Hallo" Call assertThat(value, is_( not_( equalTo("Hallo") ) ).and_(is_(ofType("String")))
Resulting in output like this:
Assertion failure: expected: is not equal to Hallo and is of type STRING; got: (STRING) Hallo (bold is from the Matcher (second argument to assertThat), rest from the Error, which the assertThat method throws) The Implementation is quite easy: you have a IMatcher abstract Class with several concrete matcher implementation and a static method, which returns a object of that matcher. The IsMatcher (just to have proper english sentences and the static method looks like this: Public Function is_(matcher As IMatcher) As IMatcher Set is_ = New IsMatcher(matcher) End Function
Class IsMatcher As IMatcher Private fMatcher As IMatcher Sub new(matcher As IMatcher) Set fMatcher = matcher End Sub Public Function matchesSafely( value As Variant) As Boolean matchesSafely = fMatcher.matches(value) End Function
Public Function describeMeTo(description As Description) description.appendText("is") Call fMatcher.describeTo(description) End Function End Class
The testThat (just returns a boolean, assertThat uses that to throw the error) is just: Public Function testThat(value As Variant, matcher As IMatcher) As Boolean testThat = matcher.matches(value) End Functio
IMatcher.matches(variant) is a wrapper to get the IMatcher.and_(IMatcher) and IMatcher.Or_(IMatcher) methods working. In the end it returns the logical result of all included Matchers. The IMatcher.decribeMeTo(Description) is again the internal method (describeTo(...) is the wrapper to get AND and OR working) used to get the plain english description from the matcher composite (the bold Text above). Dim oDescription As New Description Call matcher.describeTo(oDescription) print oDescription.toString()
Implemented Matchers up to now: is, not, equalTo, ofType, instanceOf, like. Feel free to add some matchers or leave a comment for other ideas  Here is the script lib as it is up to now (BleedYellow seems to not allow any Notes/Domino related content: no *.lss, no *.nsf):
Edited, as I can upload now: LS-Hamcrest.lss
|
assertThat(me, is_(aBlogPost()).and_(is_(interesti...
|
1 Chris Whisonant Permalink Jan, you may now upload .lss, .nsf, AND .ntf. I completely overlooked that this is a "Yellow" site and the those pesky developers may want to upload "Yellow" files! ;)
I also added .zip and .rar.