Пример #1
0
 def test_constructor_invocation(self):
     footype = model.Type(model.Name('Foo'))
     bartype = model.Type(model.Name('Bar'))
     for call in ['super', 'this']:
         self.assert_stmt('{}();'.format(call),
                          model.ConstructorInvocation(call))
         self.assert_stmt(
             '{}(1);'.format(call),
             model.ConstructorInvocation(call, arguments=[one]))
         self.assert_stmt(
             '{}(1, foo, "bar");'.format(call),
             model.ConstructorInvocation(
                 call, arguments=[one, foo,
                                  model.Literal('"bar"')]))
         self.assert_stmt(
             '<Foo> {}();'.format(call),
             model.ConstructorInvocation(call, type_arguments=[footype]))
         self.assert_stmt(
             'Foo.{}();'.format(call),
             model.ConstructorInvocation(call, target=model.Name('Foo')))
         self.assert_stmt(
             'Foo.<Bar> {}();'.format(call),
             model.ConstructorInvocation(call,
                                         type_arguments=[bartype],
                                         target=model.Name('Foo')))
Пример #2
0
    def test_annotations(self):
        # bug #13
        m = self.parser.parse_string('''
        @Annot(key = 1)
        class Foo {}
        ''')
        t = self._assert_declaration(m, 'Foo')

        self.assertEqual(t.modifiers, [
            model.Annotation(name=model.Name('Annot'),
                             members=[
                                 model.AnnotationMember(
                                     name=model.Name('key'),
                                     value=model.Literal('1'))
                             ])
        ])
Пример #3
0
 def test_assert(self):
     self.assert_stmt('assert foo;', model.Assert(foo))
     self.assert_stmt('assert foo : "bar";',
                      model.Assert(foo, message=model.Literal('"bar"')))
Пример #4
0
import unittest

import plyj.parser as plyj
import plyj.model as model

foo = model.Name('foo')
bar = model.Name('bar')
i = model.Name('i')
j = model.Name('j')
zero = model.Literal('0')
one = model.Literal('1')
two = model.Literal('2')
three = model.Literal('3')
ten = model.Literal('10')


class StatementTest(unittest.TestCase):
    def setUp(self):
        self.parser = plyj.Parser()

    def test_while(self):
        self.assert_stmt('while(foo) return;',
                         model.While(foo, body=model.Return()))
        self.assert_stmt('while(foo) { return; }',
                         model.While(foo, body=model.Block([model.Return()])))

        self.assert_stmt('do return; while(foo);',
                         model.DoWhile(foo, body=model.Return()))
        self.assert_stmt(
            'do { return; } while(foo);',
            model.DoWhile(foo, body=model.Block([model.Return()])))
import unittest

import plyj.parser as plyj
import plyj.model as model

one = model.Literal('1')
two = model.Literal('2')
three = model.Literal('3')
a = model.Name('a')
b = model.Name('b')
c = model.Name('c')
d = model.Name('d')
e = model.Name('e')


def bin(operator, operand1, operand2):
    return model.BinaryExpression(operator, operand1, operand2)


def u(operator, operand):
    return model.Unary(operator, operand)


expression_tests = [
    # simple test for each operator
    ('1+2', bin('+', one, two)),
    (' 1 + 2 ', bin('+', one, two)),
    ('1-2', bin('-', one, two)),
    ('1*2', bin('*', one, two)),
    ('1/2', bin('/', one, two)),
    ('1%2', bin('%', one, two)),
Пример #6
0
def jmerge(lhs, rhs):
    # if lhs and rhs are both string literals, then combine them.
    if isstrliteral(lhs) and isstrliteral(rhs):
        return jmodel.Literal(quote(unquote(jstr(lhs)) + unquote(jstr(rhs))))