diff options
author | Jason Schulz <jason@schulz.name> | 2015-12-29 15:17:16 -0800 |
---|---|---|
committer | Jason Schulz <jason@schulz.name> | 2016-01-15 18:21:06 -0800 |
commit | 7ad3f077dc68a83b2cdfb7b1d04de9266d7978a9 (patch) | |
tree | aaa485d0853be6b46865cf2d87064ec0299f0cde /test/functional/eval/printf_spec.lua | |
parent | dddbf9c5fa061cb03d6b6240ac6610b68b9304f5 (diff) | |
download | rneovim-7ad3f077dc68a83b2cdfb7b1d04de9266d7978a9.tar.gz rneovim-7ad3f077dc68a83b2cdfb7b1d04de9266d7978a9.tar.bz2 rneovim-7ad3f077dc68a83b2cdfb7b1d04de9266d7978a9.zip |
Add support for binary numbers
Diffstat (limited to 'test/functional/eval/printf_spec.lua')
-rw-r--r-- | test/functional/eval/printf_spec.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/functional/eval/printf_spec.lua b/test/functional/eval/printf_spec.lua new file mode 100644 index 0000000000..00afb30e17 --- /dev/null +++ b/test/functional/eval/printf_spec.lua @@ -0,0 +1,58 @@ +local helpers = require('test.functional.helpers') +local clear = helpers.clear +local eq = helpers.eq +local funcs = helpers.funcs +local exc_exec = helpers.exc_exec + +describe('printf()', function() + it('works with zero and %b', function() + eq('0', funcs.printf('%lb', 0)) + eq('0', funcs.printf('%llb', 0)) + eq('0', funcs.printf('%zb', 0)) + end) + it('works with one and %b', function() + eq('1', funcs.printf('%b', 1)) + eq('1', funcs.printf('%lb', 1)) + eq('1', funcs.printf('%llb', 1)) + eq('1', funcs.printf('%zb', 1)) + end) + it('works with 0xff and %b', function() + eq('11111111', funcs.printf('%b', 0xff)) + eq('11111111', funcs.printf('%lb', 0xff)) + eq('11111111', funcs.printf('%llb', 0xff)) + eq('11111111', funcs.printf('%zb', 0xff)) + end) + it('accepts width modifier with %b', function() + eq(' 1', funcs.printf('%3b', 1)) + end) + it('accepts prefix modifier with %b', function() + eq('0b1', funcs.printf('%#b', 1)) + end) + it('writes capital B with %B', function() + eq('0B1', funcs.printf('%#B', 1)) + end) + it('accepts prefix, zero-fill and width modifiers with %b', function() + eq('0b001', funcs.printf('%#05b', 1)) + end) + it('accepts prefix and width modifiers with %b', function() + eq(' 0b1', funcs.printf('%#5b', 1)) + end) + it('does not write prefix for zero with prefix and width modifier used with %b', function() + eq(' 0', funcs.printf('%#5b', 0)) + end) + it('accepts precision modifier with %b', function() + eq('00000', funcs.printf('%.5b', 0)) + end) + it('accepts all modifiers with %b at once', function() + -- zero-fill modifier is ignored when used with left-align + -- force-sign and add-blank are ignored + -- use-grouping-characters modifier is ignored always + eq('0b00011 ', funcs.printf('% \'+#0-10.5b', 3)) + end) + it('errors out when %b modifier is used for a list', function() + eq('Vim(call):E745: Using a List as a Number', exc_exec('call printf("%b", [])')) + end) + it('errors out when %b modifier is used for a float', function() + eq('Vim(call):E805: Using a Float as a Number', exc_exec('call printf("%b", 3.1415926535)')) + end) +end) |