def test_process_next_line(self): c = Compiler() c.text = "div\ndiv" c.process_next_line() self.assertEqual(c.inner_text, None) c = Compiler() c.text = "div <asdf>\ndiv" c.process_next_line() self.assertEqual(c.inner_text, "asdf") c = Compiler() c.text = "div <<%= val %> asdf>\ndiv" c.process_next_line() self.assertEqual(c.inner_text, "<%= val %> asdf") c = Compiler() c.text = "div href=# <asdf \n asdf ;lkj <%= val %>>\ndiv" c.process_next_line() self.assertEqual(c.inner_text, "asdf asdf ;lkj <%= val %>") c = Compiler() c.indent_token = " " c.text = "div \-\ a href=# <asdf>" c.process_next_line() self.assertEqual(c.output, '<div>\n <a href="#">asdf</a>\n') c = Compiler() c.indent_token = " " c.text = "div \-\ a href=# target=_blank \-\ span <asdf>" c.process_next_line() self.assertEqual(c.output, '<div>\n <a href="#" target="_blank">\n <span>asdf</span>\n')
def test_close_tag(self): c = Compiler() c.indent_token = " " c.open_tags = [(0, "div")] c.close_tag() self.assertEqual(c.output, "</div>\n") self.assertEqual(c.open_tags, []) c = Compiler('', compress=True) c.indent_token = " " c.open_tags = [(0, "div")] c.close_tag() self.assertEqual(c.output, "</div>") self.assertEqual(c.open_tags, [])
def test_process_embedded_line(self): c = Compiler() c.current_level = 2 c.indent_token = " " c.process_embedded_line("`<div>") self.assertEqual(c.output, " <div>\n") c = Compiler() c.current_level = 3 c.indent_token = "\t" c.process_embedded_line("`<div>") self.assertEqual(c.output, "\t\t\t<div>\n") c = Compiler('', compress=True) c.current_level = 3 c.indent_token = "\t" c.process_embedded_line("`<div>") self.assertEqual(c.output, "<div>")
def test_process_current_level(self): c = Compiler() c.text = " div" c.process_current_level() self.assertEqual(c.previous_level, 0) self.assertEqual(c.current_level, 1) self.assertEqual(c.indent_token, " ") c = Compiler() c.text = " div" c.indent_token = " " c.process_current_level() self.assertEqual(c.previous_level, 0) self.assertEqual(c.current_level, 2) self.assertEqual(c.indent_token, " ") c = Compiler() c.text = "\t\tdiv" c.indent_token = "\t" c.process_current_level() self.assertEqual(c.previous_level, 0) self.assertEqual(c.current_level, 2) self.assertEqual(c.indent_token, "\t")
def test_close_lower_level_tags(self): c = Compiler() c.current_level = 0 c.previous_level = 2 c.indent_token = " " c.open_tags = [ (0, "div"), (1, "div"), (2, "span"), ] c.close_lower_level_tags() self.assertEqual(c.output, " </span>\n </div>\n</div>\n") c = Compiler('', compress=True) c.current_level = 0 c.previous_level = 2 c.indent_token = " " c.open_tags = [ (0, "div"), (1, "div"), (2, "span"), ] c.close_lower_level_tags() self.assertEqual(c.output, "</span></div></div>")