Ejemplo n.º 1
0
 def test_make_from_type_method_should_succeed(self):
     tree = self.parse('''
         package x;
         interface Interface {}
         class Implementation implements Interface {}
         class AnotherImplementation implements Interface {}
         class Parameter {}
         class Client {
             Interface field = new Implementation();
             void f(Parameter p) {
                 Interface local = new AnotherImplementation();
             }
         }
     ''')
     set_full_classifiers_names(tree)
     classifiers, errors = make_classifiers(tree)
     assert_that(errors, empty())
     errors = set_full_types_names(tree, classifiers)
     assert_that(errors, empty())
     types, errors = fill_classifiers(tree, classifiers)
     assert_that(errors, empty())
     make_dependencies(tree, types)
     assert_that(
         classifiers['x.Client'].suppliers,
         equal_to([
             classifiers['x.Implementation'],
             classifiers['x.Parameter'],
             classifiers['x.Interface'],
             classifiers['x.AnotherImplementation'],
         ]))
Ejemplo n.º 2
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.º 3
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.º 4
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,
     }))
Ejemplo n.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
0
 def test_fill_empty_should_succeed(self):
     assert_that(fill_classifiers(self.parse(''), {}), equal_to(({}, [])))