def testStringAttr(self): self.assertEqual( '<div title="hello"></div>', hbml.compile( '%div(title="hello")' ) )
def testExprAttrWithBrace(self): self.assertEqual( '<div data-id="HELLO"></div>', hbml.compile( '%div(data-id="hello".upper())' ) )
def _test_uncompress_file(self, filename): self.assertEqual( _file_content(os.path.join(DIRPATH, filename + '.uncompress.html')), hbml.compile(_file_content( os.path.join(DIRPATH, filename + '.hbml')), compress_output=False))
def testSimpleAttr(self): self.assertEqual( '''<div id="yoyo" class="hello goodbye"></div>''', hbml.compile( "%div#yoyo.hello.goodbye" ) )
def testExprAttrWithMultiBraces(self): self.assertEqual( '<div data-id="45"></div>', hbml.compile( '%div(data-id= 3 * ( 1 + 2 * ( 3 + 4)))' ) )
def testExprAttr(self): self.assertEqual( '<div data-id="2"></div>', hbml.compile( '%div(data-id= 1 + 1)' ) )
def testMultiStringAttr(self): self.assertEqual( '<div title="hello" alt="yoyo"></div>', hbml.compile( '%div(title="hello", alt="yoyo")' ) )
def testSimpleSource(self): self.assertEqual( '''<div><h1></h1></div>''', hbml.compile(( "%div\n" " %h1" )) )
def testSimpleText(self): self.assertEqual( '<div><h2>hello</h2></div>', hbml.compile(( "%div\n" " %h2 hello" )) )
def testNoTerminateTag(self): self.assertEqual( '<div data-id="2" data-name="hello"><h2></h2></div>', hbml.compile(( "%div(data-id= 1 + 1,\n" " data-name=\"hello\")\n" " %h2" )) )
def testInBracketAttr(self): self.assertEqual( ( '<div title="hello" data-id="2"' ' onclick="a = 1, b = 2, c = 3; item_clicked(a, b)"></div>' ), hbml.compile(( '%div(title="hello", data-id="2",' ' onclick="a = 1, b = 2, c = 3; item_clicked(a, b)")' )) )
def testDontCompress(self): self.assertEqual( '''<div><h1></h1></div>''', hbml.compile(( "%div\n" " %h1" )) ) self.assertEqual( '<div>\n' ' <h1></h1>\n' '</div>\n', hbml.compile( ( "%div\n" " %h1" ), compress_output=False ) )
def testVariables(self): self.assertEqual( '<div data-length="5">HELLO</div>', hbml.compile( ( "%div(data-length=len(content))\n" " = content.upper()" ), dict( content="hello" ) ) )
def testStringEscape(self): self.assertEqual(r'<a onclick="alert(\"hello\")">yoyo</a>', hbml.compile(r'%a(onclick="alert(\"hello\")") yoyo'))
def _test_file(self, filename): self.assertEqual( _file_content(os.path.join(DIRPATH, filename + '.html')), hbml.compile( _file_content(os.path.join(DIRPATH, filename + '.hbml'))) + "\n")
def testStringEscapeAtLast(self): self.assertEqual(r'<div title="h\""></div>', hbml.compile(r'%div(title="h\"")'))
def testMultiAttrStringEscape(self): self.assertEqual( r'<a onclick="alert(\"hello\")" href="#">yoyo</a>', hbml.compile(r'%a(onclick="alert(\"hello\")", href="#") yoyo'))