diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/eval/printf_spec.lua | 58 | ||||
-rw-r--r-- | test/functional/legacy/035_increment_and_decrement_spec.lua | 26 | ||||
-rw-r--r-- | test/functional/legacy/057_sort_spec.lua | 35 |
3 files changed, 109 insertions, 10 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) diff --git a/test/functional/legacy/035_increment_and_decrement_spec.lua b/test/functional/legacy/035_increment_and_decrement_spec.lua index 20c0cc4206..e6252c384b 100644 --- a/test/functional/legacy/035_increment_and_decrement_spec.lua +++ b/test/functional/legacy/035_increment_and_decrement_spec.lua @@ -11,34 +11,40 @@ describe('increment and decrement commands', function() it('should work', function() -- Insert some numbers in various bases. insert([[ - 100 0x100 077 0 - 100 0x100 077 + 0b101 100 0x100 077 0 + 0b101 100 0x100 077 100 0x100 077 0xfF 0xFf - 100 0x100 077]]) + 100 0x100 077 + 0x0b101 0b1101]]) -- Increment and decrement numbers in the first row, interpreting the -- numbers as decimal, octal or hexadecimal. - execute('set nrformats=octal,hex', '1') - feed('102ll64128$') + execute('set nrformats=bin,octal,hex', '1') + feed('63l102ll64128$') -- For the second row, treat the numbers as decimal or octal. -- 0x100 should be interpreted as decimal 0, the character x, and decimal 100. execute('set nrformats=octal', '2') - feed('0102l2w65129blx6lD') + feed('0w102l2w65129blx6lD') -- For the third row, treat the numbers as decimal or hexadecimal. -- 077 should be interpreted as decimal 77. execute('set nrformats=hex', '3') feed('0101l257Txldt ') - -- For the last row, interpret all numbers as decimal. + -- For the fourth row, interpret all numbers as decimal. execute('set nrformats=', '4') feed('0200l100w78') + -- For the last row, interpret as binary and hexadecimal. + execute('set nrformats=bin,hex', '5') + feed('010065l6432') + expect([[ - 0 0x0ff 0000 -1 - 0 1x100 0777777 + 0b011 0 0x0ff 0000 -1 + 1b101 0 1x100 0777777 -1 0x0 078 0xFE 0xfe - -100 -100x100 000]]) + -100 -100x100 000 + 0x0b0de 0b0101101]]) end) end) diff --git a/test/functional/legacy/057_sort_spec.lua b/test/functional/legacy/057_sort_spec.lua index 585b391198..65defbae96 100644 --- a/test/functional/legacy/057_sort_spec.lua +++ b/test/functional/legacy/057_sort_spec.lua @@ -600,4 +600,39 @@ describe(':sort', function() eq('Vim(sort):E474: Invalid argument', eval('tmpvar')) expect(text) end) + + it('binary', function() + insert([[ + 0b111000 + 0b101100 + 0b101001 + 0b101001 + 0b101000 + 0b000000 + 0b001000 + 0b010000 + 0b101000 + 0b100000 + 0b101010 + 0b100010 + 0b100100 + 0b100010]]) + execute([[sort b]]) + expect([[ + 0b000000 + 0b001000 + 0b010000 + 0b100000 + 0b100010 + 0b100010 + 0b100100 + 0b101000 + 0b101000 + 0b101001 + 0b101001 + 0b101010 + 0b101100 + 0b111000]]) + end) + end) |