Crunch

Crunch (GitHub: arecarn / crunch) by Ryan Carney is a plugin for performing calculations. Typing :Crunch <args> will evaluate a mathematical expression, and :Crunch displays a prompt. :CrunchLine calculates expressions on the current line, and this also works with visual selections. :CrunchBlock works on paragraphs.

The supported expressions are easier to write than the default mathematical syntax. For example, you can use 2sin(1) instead of 2*sin(1), and it has implicit integer to float conversion. If you're in Normal mode and type "=1/2<Enter>p you should see 0 inserted, while "=1.0/2.0<Enter>p would have printed 0.5. With Crunch you can just type :Crunch 1/2.

I was looking at the tests for the project, and I believe Ryan has used VimTAP (GitHub: vim-scripts / VimTAP), which is a Vim script that implements the Test Anything Protocol:

call vimtest#StartTap()
call vimtap#Plan(2)

call vimtap#Is(g:crunch_calc_prompt , 'Calc >> ', "g:crunch_calc_prompt")
call vimtap#Is(g:crunch_calc_comment, '"'       , "g:crunch_calc_comment")

call vimtest#Quit()

This test library uses "plans" to express the expected number of assertions, which allows it to work well in various situations where assertions could be silently missed.

The documentation doesn't mention the tests, but it's otherwise easy to follow. The author notes the projects he's used to help him write Crunch, including VimCalc.

blog comments powered by Disqus