from hamlish_jinja.parser import Hamlish, Output

from .base import TestCase


class TestDivShortcut(TestCase):
	def setUp(self) -> None:
		self.hamlish = Hamlish(
			Output(
				indent_string = "  ",
				newline_string = "\n",
			),
			use_div_shortcut = True
		)


	def test_div_class_shortcut(self) -> None:
		s = self._h("""
.test
    Test
""")

		r = """\
<div class="test">
  Test
</div>\
"""

		self.assertEqual(s, r)


	def test_div_class_shortcut_inline_data(self) -> None:
		s = self._h(""".test << Test""")
		r = """<div class="test">Test</div>"""
		self.assertEqual(s, r)


	def test_div_id_shortcut(self) -> None:
		s = self._h("""
#test
    Test
""")

		r = """\
<div id="test">
  Test
</div>\
"""

		self.assertEqual(s, r)


	def test_div_id_shortcut_inline_data(self) -> None:
		s = self._h("""#test << Test""")
		r = """<div id="test">Test</div>"""
		self.assertEqual(s, r)



	def test_div_multiple_class_shortcut(self) -> None:
		s = self._h("""
.test.test2
    Test
""")

		r = """\
<div class="test test2">
  Test
</div>\
"""

		self.assertEqual(s, r)


	def test_div_multiple_class_shortcut_inline_data(self) -> None:
		s = self._h(""".test.test2 << Test""")
		r = """<div class="test test2">Test</div>"""
		self.assertEqual(s, r)


	def test_div_multiple_id_shortcut(self) -> None:
		s = self._h("""
#test#test2
    Test
""")

		r = """\
<div id="test test2">
  Test
</div>\
"""

		self.assertEqual(s, r)


	def test_div_multiple_id_shortcut_inline_data(self) -> None:
		s = self._h("""#test#test2 << Test""")
		r = """<div id="test test2">Test</div>"""
		self.assertEqual(s, r)


	# this was defined twice?
	def test_div_multiple_id_shortcut_inline_data2(self) -> None:
		s = self._h("""
#test.test << Test
.test#test << Test
.test.test2#test << Test
.test#test.test2 << Test
""")

		r = """\
<div id="test" class="test">Test</div>
<div class="test" id="test">Test</div>
<div class="test test2" id="test">Test</div>
<div class="test test2" id="test">Test</div>\
"""

		self.assertEqual(s, r)


	def test_div_mixed_class_id_shortcut(self) -> None:
		s = self._h("""
#test.test
    Test
.test#test
    Test
.test#test.test2
    Test
#test.test#test2
    Test
#test#test2.test#test3.test2
    Test
""")

		r = """\
<div id="test" class="test">
  Test
</div>
<div class="test" id="test">
  Test
</div>
<div class="test test2" id="test">
  Test
</div>
<div id="test test2" class="test">
  Test
</div>
<div id="test test2 test3" class="test test2">
  Test
</div>\
"""

		self.assertEqual(s, r)


	def test_mixed_shortcut_normal(self) -> None:
		s = self._h("""
#test class="test"
    Test
""")

		r = """\
<div id="test" class="test">
  Test
</div>"""

		self.assertEqual(s, r)


	def test_mixed_shortcut_normal2(self) -> None:
		s = self._h("""
.test.test2 id="test"
    Test
""")

		r = """\
<div class="test test2" id="test">
  Test
</div>"""

		self.assertEqual(s, r)


	def test_mixed_shortcut_normal_inline_data(self) -> None:
		s = self._h("""#test class="test" << Test""")
		r = """<div id="test" class="test">Test</div>"""
		self.assertEqual(s, r)


	def test_mixed_shortcut_normal_inline_data2(self) -> None:
		s = self._h(""".test.test2 id="test" << Test""")
		r = """<div class="test test2" id="test">Test</div>"""
		self.assertEqual(s, r)


	def test_shortcut_parenthetic_normal(self) -> None:
		s = self._h('.test(foo="bar")\n  Test')
		r = '<div class="test" foo="bar">\n  Test\n</div>'
		self.assertEqual(s, r)


	def test_shortcut_parenthetic_inline(self) -> None:
		s = self._h('.test(foo="bar") << Test')
		r = '<div class="test" foo="bar">Test</div>'
		self.assertEqual(s, r)


	def test_shortcut_parenthetic_normal2(self) -> None:
		s = self._h('.test.test-1(foo="bar")\n  Test')
		r = '<div class="test test-1" foo="bar">\n  Test\n</div>'
		self.assertEqual(s, r)


	def test_shortcut_parenthetic_inline2(self) -> None:
		s = self._h('.test.test-1(foo="bar") << Test')
		r = '<div class="test test-1" foo="bar">Test</div>'
		self.assertEqual(s, r)


	def test_shortcut_parenthetic_inline3(self) -> None:
		s = self._h('#foo.test.test-1(foo="bar") << Test')
		r = '<div id="foo" class="test test-1" foo="bar">Test</div>'
		self.assertEqual(s, r)


	def test_shortcut_parenthetic_self_closing(self) -> None:
		s = self._h('.test(foo="bar").')
		r = '<div class="test" foo="bar" />'
		self.assertEqual(s, r)


	def test_shortcut_parenthetic_self_closing2(self) -> None:
		s = self._h('.test.test-1(foo="bar").')
		r = '<div class="test test-1" foo="bar" />'
		self.assertEqual(s, r)


	def test_shortcut_parenthetic_self_closing3(self) -> None:
		s = self._h('#foo.test.test-1(foo="bar").')
		r = '<div id="foo" class="test test-1" foo="bar" />'
		self.assertEqual(s, r)


	def test_nested_with_shortcuts(self) -> None:
		s = self._h("""
%p -> %span.test
    Test
""")

		r = """\
<p><span class="test">
  Test
</span></p>"""

		self.assertEqual(s, r)


	def test_nested_with_shortcuts2(self) -> None:
		s = self._h("""
%p -> %span.test << Test
""")

		r = """\
<p><span class="test">Test</span></p>"""

		self.assertEqual(s, r)


	def test_nested_with_shortcuts3(self) -> None:
		s = self._h("""
%p -> %span.test id="test" -> Test
""")

		r = """\
<p><span class="test" id="test">Test</span></p>"""

		self.assertEqual(s, r)
