import unittest from htmlnode import LeafNode, ParentNode, HTMLNode class TestHTMLNode(unittest.TestCase): def test_to_html_props(self): node = HTMLNode( "div", "Hello, world!", None, {"class": "greeting", "href": "https://boot.dev"}, ) self.assertEqual( node.props_to_html(), ' class="greeting" href="https://boot.dev"', ) def test_to_html_no_children(self): node = LeafNode("p", "Hello, world!") self.assertEqual(node.to_html(), "

Hello, world!

") def test_to_html_no_tag(self): node = LeafNode(None, "Hello, world!") self.assertEqual(node.to_html(), "Hello, world!") def test_to_html_with_children(self): child_node = LeafNode("span", "child") parent_node = ParentNode("div", [child_node]) self.assertEqual(parent_node.to_html(), "
child
") def test_to_html_with_grandchildren(self): grandchild_node = LeafNode("b", "grandchild") child_node = ParentNode("span", [grandchild_node]) parent_node = ParentNode("div", [child_node]) self.assertEqual( parent_node.to_html(), "
grandchild
", ) def test_to_html_many_children(self): node = ParentNode( "p", [ LeafNode("b", "Bold text"), LeafNode(None, "Normal text"), LeafNode("i", "italic text"), LeafNode(None, "Normal text"), ], ) self.assertEqual( node.to_html(), "

Bold textNormal textitalic textNormal text

", ) def test_headings(self): node = ParentNode( "h2", [ LeafNode("b", "Bold text"), LeafNode(None, "Normal text"), LeafNode("i", "italic text"), LeafNode(None, "Normal text"), ], ) self.assertEqual( node.to_html(), "

Bold textNormal textitalic textNormal text

", ) if __name__ == "__main__": unittest.main()