| | 102 | def test_empty_stream(self): |
| | 103 | lines = list(_group_lines([])) |
| | 104 | self.assertEqual(len(lines), 0) |
| | 105 | |
| | 106 | def test_text_only_stream(self): |
| | 107 | input = [(TEXT, "test", (None, -1, -1))] |
| | 108 | lines = list(_group_lines(input)) |
| | 109 | self.assertEquals(len(lines), 1) |
| | 110 | self.assertTrue(isinstance(lines[0], Stream)) |
| | 111 | self.assertEquals(lines[0].events, input) |
| | 112 | |
| | 113 | def test_simplespan(self): |
| | 114 | input = HTMLParser(StringIO("<span>test</span>")) |
| | 115 | lines = list(_group_lines(input)) |
| | 116 | self.assertEquals(len(lines), 1) |
| | 117 | self.assertTrue(isinstance(lines[0], Stream)) |
| | 118 | for (a, b) in zip(lines[0], input): |
| | 119 | self.assertEqual(a, b) |
| | 120 | |
| | 121 | def test_empty_text_stream(self): |
| | 122 | """ |
| | 123 | http://trac.edgewall.org/ticket/4336 |
| | 124 | """ |
| | 125 | input = [(TEXT, "", (None, -1, -1))] |
| | 126 | lines = list(_group_lines(input)) |
| | 127 | self.assertEquals(len(lines), 1) |
| | 128 | self.assertTrue(isinstance(lines[0], Stream)) |
| | 129 | self.assertEquals(lines[0].events, input) |
| | 130 | |
| | 131 | def test_empty_text_in_span(self): |
| | 132 | """ |
| | 133 | http://trac.edgewall.org/ticket/4336 |
| | 134 | """ |
| | 135 | ns = Namespace('http://www.w3.org/1999/xhtml') |
| | 136 | input = [(START, (ns.span, Attrs([])), (None, -1, -1)), |
| | 137 | (TEXT, "", (None, -1, -1)), |
| | 138 | (END, ns.span, (None, -1, -1)), |
| | 139 | ] |
| | 140 | lines = list(_group_lines(input)) |
| | 141 | self.assertEqual(len(lines), 1) |
| | 142 | self.assertEqual(lines[0].render('html'), "<span></span>") |
| | 143 | |
| | 144 | def test_newline(self): |
| | 145 | """ |
| | 146 | If the text element does not end with a newline, it's not properly |
| | 147 | closed. |
| | 148 | """ |
| | 149 | input = HTMLParser(StringIO('<span class="c">a\nb</span>')) |
| | 150 | expected = ['<span class="c">a</span>', |
| | 151 | '<span class="c">b</span>', |
| | 152 | ] |
| | 153 | lines = list(_group_lines(input)) |
| | 154 | self.assertEquals(len(lines), len(expected)) |
| | 155 | for a, b in zip(lines, expected): |
| | 156 | self.assertEquals(a.render('xml'), b) |
| | 157 | |
| | 158 | def test_multinewline(self): |
| | 159 | """ |
| | 160 | ditto. |
| | 161 | """ |
| | 162 | input = HTMLParser(StringIO('<span class="c">\n\n\na</span>')) |
| | 163 | expected = ['<span class="c"></span>', |
| | 164 | '<span class="c"></span>', |
| | 165 | '<span class="c"></span>', |
| | 166 | '<span class="c">a</span>', |
| | 167 | ] |
| | 168 | lines = list(_group_lines(input)) |
| | 169 | self.assertEquals(len(lines), len(expected)) |
| | 170 | for a, b in zip(lines, expected): |
| | 171 | self.assertEquals(a.render('xml'), b) |
| | 172 | |
| | 173 | |