def testIntegeral(self): self.assertEqual(self.tokens('\u222B x \uF74C y'), [ Token('Integral', '\u222B', 0), Token('Symbol', 'x', 2), Token('DifferentialD', '\uF74C', 4), Token('Symbol', 'y', 6) ])
def testIntRepeated(self): self.assertEqual(self.tokens('1..'), [Token('Number', '1', 0), Token('Repeated', '..', 1)]) self.assertEqual(self.tokens('1. .'), [Token('Number', '1.', 0), Token('Dot', '.', 3)])
def testBackslash(self): self.assertEqual(self.tokens('\[Backslash]'), [Token('Backslash', '\u2216', 0)]) self.assertEqual( self.tokens('\\ a'), [Token('RawBackslash', '\\', 0), Token('Symbol', 'a', 2)]) self.incomplete_error('\\')
def testFunction(self): self.assertEqual(self.tokens('x&'), [Token('Symbol', 'x', 0), Token('Function', '&', 1)]) self.assertEqual( self.tokens('x\uf4a1'), [Token('Symbol', 'x', 0), Token('Function', '\uf4a1', 1)])
def testAssociation(self): self.assertEqual(self.tokens('<|x -> m|>'), [ Token('RawLeftAssociation', '<|', 0), Token('Symbol', "x", 2), Token('Rule', '->', 4), Token('Symbol', "m", 7), Token('RawRightAssociation', '|>', 8) ])
def testInformation(self): self.assertEqual( self.tokens('??Sin'), [Token('Information', '??', 0), Token('Symbol', 'Sin', 2)]) self.assertEqual(self.tokens('? ?Sin'), [ Token('PatternTest', '?', 0), Token('PatternTest', '?', 2), Token('Symbol', 'Sin', 3) ])
def testApply(self): self.assertEqual(self.tokens('f // x'), [ Token('Symbol', 'f', 0), Token('Postfix', '//', 2), Token('Symbol', 'x', 5) ]) self.assertEqual(self.tokens('f @ x'), [ Token('Symbol', 'f', 0), Token('Prefix', '@', 2), Token('Symbol', 'x', 4) ]) self.assertEqual(self.tokens('f ~ x'), [ Token('Symbol', 'f', 0), Token('Infix', '~', 2), Token('Symbol', 'x', 4) ])
def testSet(self): self.assertEqual(self.tokens('x = y'), [ Token('Symbol', 'x', 0), Token('Set', '=', 2), Token('Symbol', 'y', 4) ]) self.assertEqual(self.tokens('x /: y = z'), [ Token('Symbol', 'x', 0), Token('TagSet', '/:', 2), Token('Symbol', 'y', 5), Token('Set', '=', 7), Token('Symbol', 'z', 9) ])
def testUnset(self): self.assertEqual(self.tokens('=.'), [Token('Unset', '=.', 0)]) self.assertEqual(self.tokens('= .'), [Token('Unset', '= .', 0)]) self.assertEqual(self.tokens('=.5'), [Token('Set', '=', 0), Token('Number', '.5', 1)]) self.assertEqual(self.tokens('= ..'), [Token('Set', '=', 0), Token('Repeated', '..', 2)])
def check_string(self, code): token = self.single_token(code) self.assertEqual(token, Token('String', code, 0))
def check_symbol(self, code): token = self.single_token(code) self.assertEqual(token, Token('Symbol', code, 0))
def check_number(self, code): token = self.single_token(code) self.assertEqual(token, Token('Number', code, 0))
def testBoxes(self): self.assertEqual(self.tokens('\\(1\\)'), [Token('LeftRowBox', '\\(', 0), Token('Number', "1", 2), Token('RightRowBox', '\\)', 3)])
def testPre(self): self.assertEqual(self.tokens('++x++'), [Token('Increment', '++', 0), Token('Symbol', 'x', 2), Token('Increment', '++', 3)])