Пример #1
0
	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('&lt'), Elems((Text('<'),)))
		self.assertEqual(parse('&amp'), Elems((Text('&'),)))
		self.assertEqual(parse('before&ampafter&ltagain'), Elems((Text('before&after<again'),)))
Пример #2
0
	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)
Пример #3
0
	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)
Пример #4
0
	def test_empty(self):
		self.assertEqual(parse(''), Elems())
		self.assertEqual(parse(' '), Elems((Text(' '),)))
Пример #5
0
	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'))))
Пример #6
0
	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'))))
Пример #7
0
	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-'),)))