def testParseValidTable(self): input = [ '+-----+----+', '| Foo | Mu |', '+=====+====+', '| x | y |', '+-----+----+' ] expect = [['Foo', 'Mu'], ['x', 'y']] self.assertEqual(expect, parse_table(input))
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.assertEqual(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.assertEqual(expect, parse_table(input))
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]))
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\n' 'over multiple lines')]] self.assertEqual(expect, parse_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 ūt rhoncus leo. In hac | +----------------+---------------------------------------------------------------+ | | habitasse platea dictumst. Phasellus pretium iaculis. | +----------------+---------------------------------------------------------------+ """.rstrip().splitlines() #expect pt = parse_table(raw_lines) dt = draw_table('', pt) self.assertEqual(expect, dt)
def testParseDealsWithSpacesAtLineEnd(self): input = ['x y ', 'a b ', 'only one'] expected = [['x', 'y'], ['a', 'b'], ['only one', '']] self.assertEqual(expected, parse_table(input))
def testParseTableUnifiesColumns(self): input = ['x y', 'a b c', 'only one'] expected = [['x', 'y', ''], ['a', 'b', 'c'], ['only one', '', '']] self.assertEqual(expected, parse_table(input))
def testParseSimpleTable(self): self.assertEqual([['x y z']], parse_table(['x y z'])) self.assertEqual([['x', 'y z']], parse_table(['x y z'])) self.assertEqual([['x', 'y', 'z']], parse_table(['x y z']))