def test_make_not_empty_should_succeed(self):
     match_variant = MatchVariant([
         Isomorphic(Class('A'), Class('B')),
         Isomorphic(Class('C'), Class('D')),
     ])
     assert_that(str(match_variant),
                 equal_to('class A === class B\n'
                          'class C === class D'))
     assert_that(
         repr(match_variant),
         equal_to("MatchVariant([\n"
                  "Isomorphic(Class('A'), Class('B')),\n"
                  "Isomorphic(Class('C'), Class('D'))\n"
                  "])"))
     assert_that(len(match_variant), equal_to(2))
Ejemplo n.º 2
0
 def test_fill_two_same_sub_classes_should_return_error(self):
     tree = self.parse('''
         class Class {
             class SubClass {}
             class SubClass {}
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, equal_to(
         [ClassifierRedeclaration(ClassDeclaration('SubClass', []))]))
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(classifiers, equal_to({
         'Class': Class('Class'),
         'SubClass': Class('SubClass'),
     }))
     assert_that(errors, empty())
Ejemplo n.º 3
0
 def test_make_several_class_should_succeed(self):
     tree = self.parse('''
         class C1 {}
         class C2 {}
         interface I1 {}
         interface I2 {}
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(
         classifiers,
         equal_to({
             'C1': Class('C1'),
             'C2': Class('C2'),
             'I1': Interface('I1'),
             'I2': Interface('I2'),
         }))
     assert_that(errors, empty())
 def concrete_component(self):
     return Class('ConcreteComponent',
                  operations=[
                      Operation('operation',
                                self.VOID,
                                Visibility.PUBLIC,
                                is_static=False),
                  ])
 def concrete_decorator(self):
     return Class('ConcreteDecorator',
                  operations=[
                      Operation('operation',
                                self.VOID,
                                Visibility.PUBLIC,
                                is_static=False),
                  ])
Ejemplo n.º 6
0
 def test_make_array_should_succeed(self):
     variable_decl = VariableDeclarator(Variable('', dimensions=1))
     field = FieldDeclaration(PlyjType('A', dimensions=1), [variable_decl])
     variable_type = VariableType(field, variable_decl.variable)
     classifier = Class('A')
     assert_that(variable_type.type(classifier),
                 equal_to(Type(classifier, lower=0, upper=None)))
     assert_that(variable_type.type_name(), equal_to('A[][]'))
     assert_that(variable_type.classifier_name(), equal_to('A'))
Ejemplo n.º 7
0
 def test_declaration_of_two_same_classes_should_return_error(self):
     tree = self.parse('''
         class Class {}
         class Class {}
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(classifiers, equal_to({'Class': Class('Class')}))
     assert_that(
         errors,
         equal_to([ClassifierRedeclaration(ClassDeclaration('Class', []))]))
 def test_make_class_extends_class_should_succeed(self):
     tree = self.parse('''
         class General {}
         class Derived extends General {}
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     make_generalizations(tree, classifiers)
     assert_that(classifiers['Derived'].generals,
                 equal_to([
                     Class('General'),
                 ]))
Ejemplo n.º 9
0
 def test_fill_one_class_with_local_class_should_succeed(self):
     tree = self.parse('''
         class A {
             void f() {
                 class B extends A {
                     void g();
                 }
             }
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(errors, empty())
     assert_that(classifiers, equal_to({
         'A': Class('A', operations=[
             Operation('f', VOID_TYPE, Visibility.PRIVATE, is_static=False),
         ]),
         'B': Class('B', operations=[
             Operation('g', VOID_TYPE, Visibility.PRIVATE, is_static=False),
         ]),
         'void': VOID_TYPE.classifier,
     }))
Ejemplo n.º 10
0
 def test_fill_recursive_class_should_succeed(self):
     tree = self.parse('''
         class A {
             public A a;
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(errors, empty())
     a_type = Type(Class('A'))
     a_type.classifier.properties = [
         Property('a', a_type, Visibility.PUBLIC, is_static=False),
     ]
     assert_that(classifiers, equal_to({'A': a_type.classifier}))
Ejemplo n.º 11
0
 def test_fill_one_class_with_one_property_should_succeed(self):
     tree = self.parse('''
         class A {
             public int a;
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(errors, empty())
     assert_that(classifiers, equal_to({
         'A': Class('A', properties=[
             Property('a', INT_TYPE, Visibility.PUBLIC, is_static=False)
         ]),
         'int': INT_TYPE.classifier,
     }))
 def test_make_class_extends_and_implements_should_succeed(self):
     tree = self.parse('''
         interface InterfaceA {}
         interface InterfaceB {}
         class General {}
         class Realization extends General implements InterfaceA, InterfaceB
         {}
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     make_generalizations(tree, classifiers)
     assert_that(
         classifiers['Realization'].generals,
         equal_to([
             Class('General'),
             Interface('InterfaceA'),
             Interface('InterfaceB'),
         ]))
Ejemplo n.º 13
0
 def test_fill_one_class_with_two_same_property_should_return_error(self):
     tree = self.parse('''
         class A {
             public int a;
             public float a;
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(len(errors), equal_to(1))
     assert_that(str(errors[0]), equal_to(
         'error: redeclaration of variable "a" in class "A"'))
     assert_that(classifiers, equal_to({
         'A': Class('A', properties=[
             Property('a', INT_TYPE, Visibility.PUBLIC, is_static=False),
         ]),
         'int': INT_TYPE.classifier,
     }))
Ejemplo n.º 14
0
 def test_fill_one_class_with_one_operation_should_succeed(self):
     tree = self.parse('''
         class A {
             void f(int x);
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(errors, empty())
     assert_that(classifiers, equal_to({
         'A': Class('A', operations=[
             Operation('f', VOID_TYPE, Visibility.PRIVATE,
                       [Parameter('x', INT_TYPE, Direction.IN)],
                       is_static=False),
         ]),
         'void': VOID_TYPE.classifier,
         'int': INT_TYPE.classifier,
     }))
Ejemplo n.º 15
0
 def test_fill_enum_with_overriding_in_item_should_succeed(self):
     tree = self.parse('''
         enum Enum {
             Item {
                 @Override
                 public void f() {}
             };
             public abstract void f();
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(classifiers, equal_to({
         'Enum': Class('Enum', operations=[
             Operation('f', VOID_TYPE, Visibility.PUBLIC, is_static=False),
         ]),
         'void': VOID_TYPE.classifier,
     }))
     assert_that(errors, empty())
Ejemplo n.º 16
0
 def test_fill_class_with_overriding_method_in_object_should_succeed(self):
     tree = self.parse('''
         class A {
             void g();
             void f() {
                 new A() {
                     public void h();
                 };
             }
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(errors, empty())
     assert_that(classifiers, equal_to({
         'A': Class('A', operations=[
             Operation('f', VOID_TYPE, Visibility.PRIVATE, is_static=False),
             Operation('g', VOID_TYPE, Visibility.PRIVATE, is_static=False),
         ]),
         'void': VOID_TYPE.classifier,
     }))
Ejemplo n.º 17
0
 def test_fill_class_with_field_instance_creation_item_should_succeed(self):
     tree = self.parse('''
         class Class {
             Class value = new Class() {
                 @Override
                 public void f() {};
             };
             public abstract void f();
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     _, errors = fill_classifiers(tree, classifiers)
     class_type = Type(Class('Class', operations=[
         Operation('f', VOID_TYPE, Visibility.PUBLIC, is_static=False),
     ]))
     class_type.classifier.properties = [
         Property('value', class_type, Visibility.PRIVATE, is_static=False)]
     assert_that(classifiers, equal_to({
         'Class': class_type.classifier,
         'void': VOID_TYPE.classifier,
     }))
     assert_that(errors, empty())
Ejemplo n.º 18
0
 def test_fill_one_class_with_two_same_operations_should_return_error(self):
     tree = self.parse('''
         class A {
             void f(int x);
             void f(int x);
         }
     ''')
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     _, errors = fill_classifiers(tree, classifiers)
     assert_that(len(errors), equal_to(1))
     assert_that(str(errors[0]), equal_to(
         'error: redeclaration of method "-A::f(in x: int): void" in class '
         '"A"')
     )
     assert_that(classifiers, equal_to({
         'A': Class('A', operations=[
             Operation('f', VOID_TYPE, Visibility.PRIVATE,
                       [Parameter('x', INT_TYPE, Direction.IN)],
                       is_static=False),
         ]),
         'void': VOID_TYPE.classifier,
         'int': INT_TYPE.classifier,
     }))
Ejemplo n.º 19
0
 def concrete_handler(self):
     return Class('ConcreteHandler',
                  operations=[self.handler_handle_request()])
 def concrete_adapter(self):
     return Class('ConcreteAdapter',
                  properties=[self.concrete_adapter_adaptee()],
                  operations=[self.concrete_adapter_operation()])
Ejemplo n.º 21
0
 def implementation(self):
     return Class('Implementation',
                  generals=[self.interface()],
                  operations=[self.implementation_operation()])
 def abstraction(self):
     return Class('Abstraction',
                  properties=[self.abstraction_implementor()],
                  operations=[self.abstraction_operation()])
 def concrete_decorator(self):
     return Class('ConcreteDecorator',
                  operations=[self.concrete_decorator_operation()])
 def concrete_component(self):
     return Class('ConcreteComponent',
                  operations=[self.concrete_component_operation()])
 def concrete_implementor(self):
     return Class('ConcreteImplementor',
                  operations=[self.concrete_implementor_operation_impl()])
Ejemplo n.º 26
0
 def concrete_product(self):
     return Class('ConcreteProduct')
 def decorator(self):
     return Class('Decorator',
                  properties=[self.decorator_component()],
                  operations=[self.decorator_operation()])
 def derived(self):
     return Class('Derived', generals=[self.general()])
def make_class(class_info):
    return Class(class_info.pretty_this())
Ejemplo n.º 30
0
 def concrete_factory(self):
     return Class('ConcreteFactory',
                  operations=[self.concrete_factory_create()])