vim-maktaba icon indicating copy to clipboard operation
vim-maktaba copied to clipboard

Add fluent maktaba#ensure#That API

Open dbarnett opened this issue 11 years ago • 0 comments

Maktaba has a suite of maktaba#ensure# functions for throwing errors whenever certain conditions aren't satisfied. For instance:

call maktaba#ensure#IsTrue(g:foo)
call maktaba#ensure#IsEqual(5, g:foo)
call maktaba#ensure#IsIn(g:foo, [1, 2, 3])
call maktaba#ensure#Passes(g:foo, 'empty')

The order of arguments is a little arbitrary (I have to look up the order of arguments every time I use them) and is sometimes hard to understand at a glance in vroom tests.

We should consider adding a "fluent" API like the Java Truth library that makes ensure calls read more naturally:

call maktaba#ensure#That(g:foo).IsTrue()
call maktaba#ensure#That(g:foo).Equals(5)
call maktaba#ensure#That(g:foo).IsIn([1, 2, 3])
call maktaba#ensure#That(g:foo).Passes('empty')

We could add a parallel maktaba#check#That API to replace the corresponding maktaba#value# functions if the parallelism is worth the churn.

dbarnett avatar Oct 27 '14 19:10 dbarnett