From 6ec38efd97e9deb8fb362890f670ba9571f60e10 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 24 May 2012 09:40:23 -0400 Subject: Fixed some edge-case bugs having to do with inserting an element into a tag it's already inside, and replacing one of a tag's children with another. [bug=997529] --- bs4/tests/test_tree.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'bs4/tests/test_tree.py') diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 9a10edf..1e24c29 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -821,6 +821,18 @@ class TestTreeModification(SoupTest): self.assertEqual(the.next_element, c_tag) self.assertEqual(c_tag.previous_element, the) + def test_append_child_thats_already_at_the_end(self): + data = "" + soup = self.soup(data) + soup.a.append(soup.b) + self.assertEquals(data, soup.decode()) + + def test_move_tag_to_beginning_of_parent(self): + data = "" + soup = self.soup(data) + soup.a.insert(0, soup.d) + self.assertEqual("", soup.decode()) + def test_insert_works_on_empty_element_tag(self): # This is a little strange, since most HTML parsers don't allow # markup like this to come through. But in general, we don't @@ -882,6 +894,18 @@ class TestTreeModification(SoupTest): self.assertEqual(no.next_element, "no") self.assertEqual(no.next_sibling, " business") + def test_replace_first_child(self): + data = "" + soup = self.soup(data) + soup.b.replace_with(soup.c) + self.assertEqual("", soup.decode()) + + def test_replace_last_child(self): + data = "" + soup = self.soup(data) + soup.c.replace_with(soup.b) + self.assertEqual("", soup.decode()) + def test_nested_tag_replace_with(self): soup = self.soup( """Wereservetherighttorefuseservice""") -- cgit v1.2.3