Nemerle, NUnit and custom operators
Nemerle allows the definition of new operators. I always feel annoyed having to write code like “Assert.AreEqual(42, myVal)” when unit testing with NUnit.
So I created this operator for use in my project’s test library:
namespace Equin.Vectorization.Library.Tests module Utilities public static @=!=[T](x : T, y : T) : void Assert.AreEqual(x, y)
Now in my test cases I can use it like this:
[Test] public PixelAtTopLeft() : void using (bmp = CreateBitmap(Size(10, 10), [Pt(0,0)])) def ps = PixelSelector(bmp, Color.Black) def pixels = ps.GetPixels() mutable count = 0 mutable aPoint : Pt[int] = null foreach (pt in pixels) count++ aPoint = pt 1 =!= count 0 =!= aPoint.X 0 =!= aPoint.Y
It’s just sugar, I know, but it makes the assertions really jump out at me. It’s less to type as well :)
I could even make it a macro instead of a method call, that would then let me create a pretty message string as well…