Beispiel #1
0
	def test_degenerate(self):
		try: tokenize('<-')
		except TokenizeError as e:
			self.assertEqual(e.line, 0)
			self.assertEqual(e.col, 1)

		try: tokenize('<->')
		except TokenizeError as e:
			self.assertEqual(e.line, 0)
			self.assertEqual(e.col, 1)

		try: tokenize('</->')
		except TokenizeError as e:
			self.assertEqual(e.line, 0)
			self.assertEqual(e.col, 2)

		try: tokenize('&foo')
		except TokenizeError as e:
			self.assertEqual(e.line, 0)
			self.assertEqual(e.col, 1)

		try: tokenize('&foo')
		except TokenizeError as e:
			self.assertEqual(e.line, 0)
			self.assertEqual(e.col, 1)
Beispiel #2
0
	def test_degenerate(self):
		self.assertEqual(tokenize('<'), (LtToken(),))
		self.assertEqual(tokenize('<>'), (LtToken(), GtToken()))
		self.assertEqual(tokenize('>'), (GtToken(),))
		self.assertEqual(tokenize('/>'), (SlashToken(), GtToken()))
		self.assertEqual(tokenize('</>'), (LtToken(), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<<'), (LtToken(), LtToken()))
Beispiel #3
0
	def test_simple(self):
		self.assertEqual(tokenize('<')[0].line, 0)
		self.assertEqual(tokenize('<')[0].col, 0)
		self.assertEqual(tokenize('<>')[1].line, 0)
		self.assertEqual(tokenize('<>')[1].col, 1)
		self.assertEqual(tokenize('<\n>')[1].line, 1)
		self.assertEqual(tokenize('<\n>')[1].col, 0)
Beispiel #4
0
	def test_tag_with_whitespace(self):
		self.assertEqual(tokenize('< foo >'), (LtToken(), IdToken('foo'), GtToken()))
		self.assertEqual(tokenize('< f >'), (LtToken(), IdToken('f'), GtToken()))
		self.assertEqual(tokenize('< / foo >'), (LtToken(), SlashToken(), IdToken('foo'), GtToken()))
		self.assertEqual(tokenize('< / f >'), (LtToken(), SlashToken(), IdToken('f'), GtToken()))
		self.assertEqual(tokenize('<  foo / >'), (LtToken(), IdToken('foo'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<  f / >'), (LtToken(), IdToken('f'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<foo / >'), (LtToken(), IdToken('foo'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<f / >'), (LtToken(), IdToken('f'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<foo/ >'), (LtToken(), IdToken('foo'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<f/ >'), (LtToken(), IdToken('f'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('< foo/>'), (LtToken(), IdToken('foo'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('< f/>'), (LtToken(), IdToken('f'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<\nfoo/>'), (LtToken(), IdToken('foo'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<\nfoo\n/>'), (LtToken(), IdToken('foo'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<\nfoo\n/\n>'), (LtToken(), IdToken('foo'), SlashToken(), GtToken()))
Beispiel #5
0
	def test_text_whitespace(self):
		self.assertEqual(tokenize(' some text \n more text'), (TextToken(' some text \n more text'),))
Beispiel #6
0
	def test_text_with_newline(self):
		self.assertEqual(tokenize('this is some text\nwith a newline'), (TextToken('this is some text\nwith a newline'),))
Beispiel #7
0
	def test_matched(self):
		self.assertEqual(tokenize('<f></f>'), (LtToken(), IdToken('f'), GtToken(), LtToken(), SlashToken(), IdToken('f'), GtToken()))
		self.assertEqual(tokenize('<foo></foo>'), (LtToken(), IdToken('foo'), GtToken(), LtToken(), SlashToken(), IdToken('foo'), GtToken()))
		self.assertEqual(tokenize('<foo-bar></foo-bar>'), (LtToken(), IdToken('foo-bar'), GtToken(), LtToken(), SlashToken(), IdToken('foo-bar'), GtToken()))
Beispiel #8
0
	def test_standalone(self):
		self.assertEqual(tokenize('<f/>'), (LtToken(), IdToken('f'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<foo/>'), (LtToken(), IdToken('foo'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<foo-bar/>'), (LtToken(), IdToken('foo-bar'), SlashToken(), GtToken()))
		self.assertEqual(tokenize('<a-/>'), (LtToken(), IdToken('a-'), SlashToken(), GtToken()))
Beispiel #9
0
	def test_escape(self):
		self.assertEqual(tokenize('&lt'), (EscapeLtToken(),))
		self.assertEqual(tokenize('&amp'), (EscapeAmpToken(),))
		self.assertEqual(tokenize('before&ampafter'), (TextToken('before'), EscapeAmpToken(), TextToken('after')))
Beispiel #10
0
	def test_text(self):
		self.assertEqual(tokenize('f'), (TextToken('f'),))
		self.assertEqual(tokenize('foo'), (TextToken('foo'),))
		self.assertEqual(tokenize('This is some text'), (TextToken('This is some text'),))
Beispiel #11
0
	def test_empty(self):
		self.assertEqual(tokenize(''), ())
Beispiel #12
0
	def test_multiline(self):
		try: tokenize('&amp\n&f\n&lt')
		except TokenizeError as e:
			self.assertEqual(e.line, 1)
			self.assertEqual(e.col, 1)
Beispiel #13
0
	def test_tag_with_newline(self):
		self.assertEqual(tokenize('<foo>\n</foo>'), (LtToken(), IdToken('foo'), GtToken(), TextToken('\n'), LtToken(), SlashToken(), IdToken('foo'), GtToken()))