Of course, any API is a leaky abstraction. Funny stuff from
JavaScript tends to leak through our API's no matter how we try. So
I've been writing unit tests about stuff I figure already works, and
about 10% of the time I find a surprise.
Just for example, I pose an arithmetic axiom:
a + (b - a) == b
for all a and b of the same type and addition and subtraction are meaningful
So, where do we get leaks? I want this to work for dates. Naturally,
JavaScript lets me do the math without complaint. (b - a) works
great, returning effectively:
b.getTime() - a.getTime()
Then the addition operation runs. JavaScript (in Safari at least)
doesn't seem to understand how to add a lapse back into a date, so it
casts (a) and (b - a) to Strings and concatenates them. Lame,
especially since JavaScript doesn't have any problem doing:
new Date(a.getTime() + (b - a))
which returns the value I would expect.
So, I've modified my wrappers for these operators. You can trust this axiom:
eq(add(a, sub(b, a)), b)
Meanwhile, I found some bugs. For example:
bool({}) and bool([])
should be false since they're empty. Everything else was going well
but these two cases. I fixed them a while back.
Kris