예제 #1
0
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
예제 #2
0
 def testParseValidTable(self):
     input = [
         '+-----+----+', '| Foo | Mu |', '+=====+====+', '| x   | y  |',
         '+-----+----+'
     ]
     expect = [['Foo', 'Mu'], ['x', 'y']]
     self.assertEquals(expect, parse_table(input))
예제 #3
0
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
예제 #4
0
 def testParseValidTable(self):
     input = ['+-----+----+',
              '| Foo | Mu |',
              '+=====+====+',
              '| x   | y  |',
              '+-----+----+']
     expect = [['Foo', 'Mu'], ['x', 'y']]
     self.assertEquals(expect, parse_table(input))
예제 #5
0
 def testParseTable(self):
     self.load_fixture_in_vim('default')
     expected = [
             ['Column 1', 'Column 2'],
             ['Foo', 'Put two (or more) spaces as a field separator.'],
             ['Bar', 'Even very very long lines like these are fine, as long as you do not put in line endings here.'],
             ['Qux', 'This is the last line.'],
             ]
     self.assertEqual(expected, parse_table(vim.current.buffer[2:6]))
예제 #6
0
    def testParseCorruptedTable(self):
        input = [
            '+---+---------+', '| Foo | Mu                   |',
            '+=====+====+', '| x   | This became somewhat larger  |',
            'blah   | A new line| ', '+-----+----+'
        ]
        expect = [['Foo', 'Mu'],
                  ['x\nblah', 'This became somewhat larger\nA new line']]
        self.assertEquals(expect, parse_table(input))

        input = [
            '+---+---------+', '| Foo | Mu                   |',
            '+=====+====+', '| x   | This became somewhat larger  |',
            'blah   | A new line|| ', '+-----+----+'
        ]
        expect = [['Foo', 'Mu'],
                  ['x\nblah', 'This became somewhat larger\nA new line']]
        self.assertEquals(expect, parse_table(input))
예제 #7
0
 def testParseTable(self):
     self.load_fixture_in_vim('default')
     expected = [
             ['Column 1', 'Column 2'],
             ['Foo', 'Put two (or more) spaces as a field separator.'],
             ['Bar', 'Even very very long lines like these are fine, as long as you do not put in line endings here.'],
             ['Qux', 'This is the last line.'],
             ]
     self.assertEquals(expected, parse_table(vim.current.buffer[2:6]))
예제 #8
0
    def testParseCorruptedTable(self):
        input = ['+---+---------+',
                 '| Foo | Mu                   |',
                 '+=====+====+',
                 '| x   | This became somewhat larger  |',
                 'blah   | A new line| ',
                 '+-----+----+']
        expect = [['Foo', 'Mu'],
                  ['x\nblah', 'This became somewhat larger\nA new line']]
        self.assertEquals(expect, parse_table(input))

        input = ['+---+---------+',
                 '| Foo | Mu                   |',
                 '+=====+====+',
                 '| x   | This became somewhat larger  |',
                 'blah   | A new line|| ',
                 '+-----+----+']
        expect = [['Foo', 'Mu'],
                  ['x\nblah', 'This became somewhat larger\nA new line']]
        self.assertEquals(expect, parse_table(input))
예제 #9
0
    def testParseMultiLineFields(self):
        input = """\
+-----+---------------------+
| Foo | Bar                 |
+=====+=====================+
| x   | This is a long line |
|     | that is spread out  |
|     | over multiple lines |
+-----+---------------------+""".split('\n')
        expect = [['Foo', 'Bar'],
                  ['x', 'This is a long line\nthat is spread out\nover multiple lines']]
        self.assertEqual(expect, parse_table(input))
예제 #10
0
    def testParseMultiLineFields(self):
        input = """\
+-----+---------------------+
| Foo | Bar                 |
+=====+=====================+
| x   | This is a long line |
|     | that is spread out  |
|     | over multiple lines |
+-----+---------------------+""".split('\n')
        expect = [['Foo', 'Bar'],
                  ['x', 'This is a long line\nthat is spread out\nover multiple lines']]
        self.assertEquals(expect, parse_table(input))
예제 #11
0
    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)))
예제 #12
0
    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)))
예제 #13
0
 def testParseDealsWithSpacesAtLineEnd(self):
     input = ['x  y     ', 'a  b ', 'only one']
     expected = [['x', 'y'], ['a', 'b'], ['only one', '']]
     self.assertEquals(expected, parse_table(input))
예제 #14
0
 def testParseDealsWithSpacesAtLineEnd(self):
     input = ['x  y     ', 'a  b ', 'only one']
     expected = [['x', 'y'], ['a', 'b'], ['only one', '']]
     self.assertEquals(expected, parse_table(input))
예제 #15
0
 def testParseTableUnifiesColumns(self):
     input = ['x  y', 'a  b    c', 'only one']
     expected = [['x', 'y', ''], ['a', 'b', 'c'], ['only one', '', '']]
     self.assertEquals(expected, parse_table(input))
예제 #16
0
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
예제 #17
0
 def testParseTableUnifiesColumns(self):
     input = ['x  y', 'a  b    c', 'only one']
     expected = [['x', 'y', ''], ['a', 'b', 'c'], ['only one', '', '']]
     self.assertEquals(expected, parse_table(input))
예제 #18
0
 def testParseSimpleTable(self):
     self.assertEquals([['x y z']], parse_table(['x y z']))
     self.assertEquals([['x', 'y z']], parse_table(['x  y z']))
     self.assertEquals([['x', 'y', 'z']], parse_table(['x  y          z']))
예제 #19
0
 def testParseSimpleTable(self):
     self.assertEquals([['x y z']], parse_table(['x y z']))
     self.assertEquals([['x', 'y z']], parse_table(['x  y z']))
     self.assertEquals([['x', 'y', 'z']], parse_table(['x  y          z']))
예제 #20
0
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