def testNextSiblingNoOther(self): """when there are no siblings, expect next_sibling to return None""" here = outer_token = Token() token = Token(indent=2) here = here.consume(token) self.assertFalse(token.next_sibling())
def testConsumeCall(self): "render a token structure. Expect an empty string" here = outer_token = Token() for i in range(3): token = Token(indent=i * 2) here = here.consume(token) self.assertEqual(outer_token({}), '')
def testConsumeHigherIndent3Levels(self): "The inner tokens will be in the outer token's content" here = outer_token = Token() for i in range(3): token = Token(indent=i * 2) here = here.consume(token) self.assertEqual(here.parent.parent.parent, outer_token)
def testConsumeBadDedent(self): "try to add a token with an invalid indent." here = outer_token = Token() for i in range(3): token = Token(indent=i * 2) here = here.consume(token) # indent -1 0 2 4 token = Token(indent=1) self.assertRaises(EvoIndentationError, here.consume, token)
def testConsumeCorrectDedentToZero(self): "add a correctly dedented token" here = outer_token = Token() for i in range(3): token = Token(indent=i * 2) here = here.consume(token) # indent -1 0 2 4 token = Token(indent=0) here = here.consume(token) self.assertIn(token, outer_token.content)
def testNextSibling(self): """for the last sibling expect next_sibling to return None""" here = outer_token = Token() token1 = Token(indent=2) token2 = Token(indent=2) token3 = Token(indent=2) here = here.consume(token1) here = here.consume(token2) here = here.consume(token3) # first returns second; second returns third self.assertEqual(token1.next_sibling(), token2) self.assertEqual(token2.next_sibling(), token3) # last in the queue self.assertFalse(token3.next_sibling())
def testCreateToken(self): "" token = Token() self.assertFalse(token.parent) self.assertEqual(token.content, []) self.assertEqual(token.indent, -1) self.assertEqual(token.filename, '') self.assertEqual(token.line, 0)