import unittest

import mwparserfromhell as mwp

from wikitables import ftag, WikiTable


class TestWikiTables(unittest.TestCase):
    def test_simple_table(self):
        source = """
{| class="wikitable"
|-
! Column 1 header !! Column 2 header
|-
| Row 1 Column 1 || Row 1 Column 2
|-
| Row 2 Column 1 || Row 2 Column 1
|}

"""
        raw_tables = mwp.parse(source).filter_tags(matches=ftag('table'))

        table = WikiTable("Test Table 2", raw_tables[0])

        self.assertEqual(len(table.rows), 2)
        self.assertEqual(list(table.rows[0].keys()), ['Column 1 header', 'Column 2 header'])


if __name__ == '__main__':
    unittest.main()

@@ -595,16 +595,735 @@
 der'%5D)%0A%0A
+    def test_complex_table(self):%0A        source = %22%22%22%0A%7B%7C class=%22wikitable sortable%22%0A! 2018%3Cbr%3Erank %0A! %5B%5BMunicipalities of Brazil%7CCity%5D%5D%0A! %5B%5BStates of Brazil%7CState%5D%5D%0A! 2018%3Cbr%3EEstimate%0A! 2010%3Cbr%3ECensus%0A! Change%0A%7C-%0A! 1%0A%7C'''''%5B%5BS%C3%A3o Paulo%5D%5D'''''%0A%7C %7B%7Bflag%7CS%C3%A3o Paulo%7D%7D%0A%7C %7B%7Bchange%7Cinvert=on%7C12176866%7C10659386%7D%7D %0A%7C-%0A! 2%0A%7C '''''%5B%5BRio de Janeiro%5D%5D'''''%0A%7C %7B%7Bflag%7CRio de Janeiro%7D%7D%0A%7C %7B%7Bchange%7Cinvert=on%7C6688927%7C5940224%7D%7D%0A%7C%7D%0A%22%22%22%0A        raw_tables = mwp.parse(source).filter_tags(matches=ftag('table'))%0A%0A        table = WikiTable(%22Test Table 2%22, raw_tables%5B0%5D)%0A%0A        self.assertEqual(len(table.rows), 2)%0A        self.assertEqual(list(table.rows%5B0%5D.keys()), %5B'2018rank', 'City', 'State', '2018Estimate', '2010Census', 'Change'%5D)%0A%0A
 %0Aif __na

add test for change-template