def testDrawTable(self): self.assertEquals([], draw_table([])) self.assertEquals(['+--+', '| |', '+==+'], draw_table([['']])) self.assertEquals(['+-----+', '| Foo |', '+=====+'], draw_table([['Foo']])) self.assertEquals([ '+-----+----+', '| Foo | Mu |', '+=====+====+', '| x | y |', '+-----+----+' ], draw_table([['Foo', 'Mu'], ['x', 'y']]))
def reflow_table(): upper, lower, indent = get_table_bounds() slice = vim.current.buffer[upper - 1:lower] widths = get_column_widths_from_border_spec(slice) table = parse_table(slice) slice = draw_table(indent, table, widths) vim.current.buffer[upper - 1:lower] = slice
def testDrawMultiLineFields(self): input = [['Foo', 'Bar'], ['x', 'This is a long line\nthat is spread out\nover multiple lines']] expect = """\ +-----+---------------------+ | Foo | Bar | +=====+=====================+ | x | This is a long line | | | that is spread out | | | over multiple lines | +-----+---------------------+""".split('\n') self.assertEqual(expect, draw_table('', input))
def testCreateComplexTable(self): raw_lines = self.read_fixture('multiline-cells') # strip off the last (empty) line from raw_lines (since that line does # not belong to the table del raw_lines[-1] expect = """\ +----------------+---------------------------------------------------------------+ | Feature | Description | +================+===============================================================+ | Ease of use | Drop dead simple! | +----------------+---------------------------------------------------------------+ | Foo | Bar, qux, mux | +----------------+---------------------------------------------------------------+ | Predictability | Lorem ipsum dolor sit amet, consectetur adipiscing elit. | +----------------+---------------------------------------------------------------+ | | Nullam congue dapibus aliquet. Integer ut rhoncus leo. In hac | +----------------+---------------------------------------------------------------+ | | habitasse platea dictumst. Phasellus pretium iaculis. | +----------------+---------------------------------------------------------------+ """.rstrip().split('\n') self.assertEquals(expect, draw_table(parse_table(raw_lines)))
def reformat_table(): upper, lower, indent = get_table_bounds() slice = vim.current.buffer[upper - 1:lower] table = parse_table(slice) slice = draw_table(indent, table) vim.current.buffer[upper - 1:lower] = slice