def test_text(self): self.assertEqual(parse('f'), Elems((Text('f'),))) self.assertEqual(parse('foo'), Elems((Text('foo'),))) self.assertEqual(parse('This is some text'), Elems((Text('This is some text'),))) self.assertEqual(parse('<'), Elems((Text('<'),))) self.assertEqual(parse('&'), Elems((Text('&'),))) self.assertEqual(parse('before&after<again'), Elems((Text('before&after<again'),)))
def test_test1(self): test1Ast = Elems((OpenTag('html'), Elems((Text('\nText\n'),)), CloseTag('html'), Text('\n'))) with open('./simphtml/test/test1.html') as f: self.assertEqual(parse(f), test1Ast)
def test_test2(self): test2Ast = Elems((OpenTag('html'), Elems((Text(' Simple\n'), StandaloneTag('standalone'), Text(' test\n'), OpenTag('a'), Elems((Text(' Blargh '), OpenTag('b'), Elems((StandaloneTag('standalone'),)), CloseTag('b'), Text('\nBoom\n'))), CloseTag('a'), Text('\n'))), CloseTag('html'), Text('\n'))) with open('./simphtml/test/test2.html') as f: self.assertEqual(parse(f), test2Ast)
def test_empty(self): self.assertEqual(parse(''), Elems()) self.assertEqual(parse(' '), Elems((Text(' '),)))
def test_nested(self): self.assertEqual(parse('<f>Text</f>'), Elems((OpenTag('f'), Elems((Text('Text'),)), CloseTag('f')))) self.assertEqual(parse('<f> Text <g/> Text <h>Text</h></f>'), Elems((OpenTag('f'), Elems((Text(' Text '), StandaloneTag('g'), Text(' Text '), OpenTag('h'), Elems((Text('Text'),)), CloseTag('h'))), CloseTag('f')))) self.assertEqual(parse('<f><g><h><i></i></h></g></f>'), Elems((OpenTag('f'), Elems((OpenTag('g'), Elems((OpenTag('h'), Elems((OpenTag('i'), CloseTag('i'))), CloseTag('h'))), CloseTag('g'))), CloseTag('f'))))
def test_matched(self): self.assertEqual(parse('<f></f>'), Elems((OpenTag('f'),CloseTag('f')))) self.assertEqual(parse('<foo></foo>'), Elems((OpenTag('foo'),CloseTag('foo')))) self.assertEqual(parse('<foo-bar></foo-bar>'), Elems((OpenTag('foo-bar'),CloseTag('foo-bar'))))
def test_standalone(self): self.assertEqual(parse('<f/>'), Elems((StandaloneTag('f'),))) self.assertEqual(parse('<foo/>'), Elems((StandaloneTag('foo'),))) self.assertEqual(parse('<foo-bar/>'), Elems((StandaloneTag('foo-bar'),))) self.assertEqual(parse('<a-/>'), Elems((StandaloneTag('a-'),)))