google / google/vim-maktaba

Add fluent maktaba#ensure#That API

Open
#93 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Vim Script
Stars
588
Forks
41
PR merge metrics
No merged PRs in 30d

Description

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

``` VimL
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](http://google.github.io/truth/) that makes ensure calls read more naturally:

``` VimL
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.