예제 #1
0
class ObjectiveCLexerTest(unittest.TestCase):
    def setUp(self):
        self.lexer = ObjectiveCLexer()

    def testLiteralNumberInt(self):
        fragment = u"@(1);\n"
        expected = [
            (Token.Literal, u"@("),
            (Token.Literal.Number.Integer, u"1"),
            (Token.Literal, u")"),
            (Token.Punctuation, u";"),
            (Token.Text, u"\n"),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberExpression(self):
        fragment = u"@(1+2);\n"
        expected = [
            (Token.Literal, u"@("),
            (Token.Literal.Number.Integer, u"1"),
            (Token.Operator, u"+"),
            (Token.Literal.Number.Integer, u"2"),
            (Token.Literal, u")"),
            (Token.Punctuation, u";"),
            (Token.Text, u"\n"),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberNestedExpression(self):
        fragment = u"@(1+(2+3));\n"
        expected = [
            (Token.Literal, u"@("),
            (Token.Literal.Number.Integer, u"1"),
            (Token.Operator, u"+"),
            (Token.Punctuation, u"("),
            (Token.Literal.Number.Integer, u"2"),
            (Token.Operator, u"+"),
            (Token.Literal.Number.Integer, u"3"),
            (Token.Punctuation, u")"),
            (Token.Literal, u")"),
            (Token.Punctuation, u";"),
            (Token.Text, u"\n"),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberBool(self):
        fragment = u"@NO;\n"
        expected = [(Token.Literal.Number, u"@NO"), (Token.Punctuation, u";"), (Token.Text, u"\n")]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLieralNumberBoolExpression(self):
        fragment = u"@(YES);\n"
        expected = [
            (Token.Literal, u"@("),
            (Token.Name.Builtin, u"YES"),
            (Token.Literal, u")"),
            (Token.Punctuation, u";"),
            (Token.Text, u"\n"),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))
예제 #2
0
 def show(self):
     """
     Print to terminal the highlighted class description.
     """
     print(
         highlight(str(self), ObjectiveCLexer(),
                   TerminalTrueColorFormatter(style='native')))
예제 #3
0
 def show(self, recursive: bool = False):
     """
     Print to terminal the highlighted class description.
     :param recursive: Show methods of super classes.
     """
     print(
         highlight(self._to_str(recursive), ObjectiveCLexer(),
                   TerminalTrueColorFormatter(style='native')))
예제 #4
0
 def setUp(self):
     self.lexer = ObjectiveCLexer()
예제 #5
0
class ObjectiveCLexerTest(unittest.TestCase):
    def setUp(self):
        self.lexer = ObjectiveCLexer()

    def testLiteralNumberInt(self):
        fragment = u'@(1);\n'
        expected = [
            (Token.Literal, u'@('),
            (Token.Literal.Number.Integer, u'1'),
            (Token.Literal, u')'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberExpression(self):
        fragment = u'@(1+2);\n'
        expected = [
            (Token.Literal, u'@('),
            (Token.Literal.Number.Integer, u'1'),
            (Token.Operator, u'+'),
            (Token.Literal.Number.Integer, u'2'),
            (Token.Literal, u')'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberNestedExpression(self):
        fragment = u'@(1+(2+3));\n'
        expected = [
            (Token.Literal, u'@('),
            (Token.Literal.Number.Integer, u'1'),
            (Token.Operator, u'+'),
            (Token.Punctuation, u'('),
            (Token.Literal.Number.Integer, u'2'),
            (Token.Operator, u'+'),
            (Token.Literal.Number.Integer, u'3'),
            (Token.Punctuation, u')'),
            (Token.Literal, u')'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberBool(self):
        fragment = u'@NO;\n'
        expected = [
            (Token.Literal.Number, u'@NO'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLieralNumberBoolExpression(self):
        fragment = u'@(YES);\n'
        expected = [
            (Token.Literal, u'@('),
            (Token.Name.Builtin, u'YES'),
            (Token.Literal, u')'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))
 def setUp(self):
     self.lexer = ObjectiveCLexer()
class ObjectiveCLexerTest(unittest.TestCase):

    def setUp(self):
        self.lexer = ObjectiveCLexer()

    def testLiteralNumberInt(self):
        fragment = u'@(1);\n'
        expected = [
            (Token.Text, u''),
            (Token.Literal, u'@('),
            (Token.Literal.Number.Integer, u'1'),
            (Token.Literal, u')'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
            (Token.Text, u''),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberExpression(self):
        fragment = u'@(1+2);\n'
        expected = [
            (Token.Text, u''),
            (Token.Literal, u'@('),
            (Token.Literal.Number.Integer, u'1'),
            (Token.Operator, u'+'),
            (Token.Literal.Number.Integer, u'2'),
            (Token.Literal, u')'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
            (Token.Text, u''),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberNestedExpression(self):
        fragment = u'@(1+(2+3));\n'
        expected = [
            (Token.Text, u''),
            (Token.Literal, u'@('),
            (Token.Literal.Number.Integer, u'1'),
            (Token.Operator, u'+'),
            (Token.Punctuation, u'('),
            (Token.Literal.Number.Integer, u'2'),
            (Token.Operator, u'+'),
            (Token.Literal.Number.Integer, u'3'),
            (Token.Punctuation, u')'),
            (Token.Literal, u')'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
            (Token.Text, u''),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLiteralNumberBool(self):
        fragment = u'@NO;\n'
        expected = [
            (Token.Text, u''),
            (Token.Literal.Number, u'@NO'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
            (Token.Text, u''),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))

    def testLieralNumberBoolExpression(self):
        fragment = u'@(YES);\n'
        expected = [
            (Token.Text, u''),
            (Token.Literal, u'@('),
            (Token.Name.Builtin, u'YES'),
            (Token.Literal, u')'),
            (Token.Punctuation, u';'),
            (Token.Text, u'\n'),
            (Token.Text, u''),
        ]
        self.assertEqual(expected, list(self.lexer.get_tokens(fragment)))
예제 #8
0
def lexer():
    yield ObjectiveCLexer()