Beispiel #1
0
 def test_all_poles(self):
     '''
     Тестирование всех полей комнаты
     '''
     print("\ntest_all_poles")
     tokens = create_tokens('room a1:'    + "\n" +
                            'height 123'  + "\n" +
                            'width 123'   + "\n" +
                            'left nice1'  + "\n" +
                            'right nice2' + "\n" +
                            'up nice3'    + "\n" +
                            'down nice4'  + "\n" +
                            'img "nice5"' + "\n" +
                            'end'        )
     built_tree = build_tree(tokens)
     room1 = Room()
     room1.height = tokens[1][1]
     room1.width  = tokens[2][1]
     room1.left   = tokens[3][1]
     room1.right  = tokens[4][1]
     room1.up     = tokens[5][1]
     room1.down   = tokens[6][1]
     room1.img    = tokens[7][1]
     tree = {"a1" : room1}
     self.assertTrue(are_equal(tree, built_tree))
     print("test_all_poles passed")
def create_tree(text):
    '''
    Создает словарь с комнатами из входного текста
    '''
    file = open(F_NAME, "w")
    file.write(text)
    file.close()
    tokens = find_tokens(F_NAME)
    tree = build_tree(tokens)
    return tree
Beispiel #3
0
 def test_empty_room(self):
     '''
     Тестирование пустой комнаты
     '''
     print("\ntest_empty_room")
     tokens = create_tokens('room ask321_me:'+ "\n" +
                            ''               + "\n" +
                            'end'        )
     built_tree = build_tree(tokens)
     room1 = Room()
     tree = {"ask321_me" : room1}
     self.assertTrue(are_equal(tree, built_tree))
     print("test_empty_room passed")
Beispiel #4
0
 def test_room_reuse(self):
     '''
     Тестирование ошибки (повторение комнат)
     '''
     print("\ntest_room_reuse")
     tokens = create_tokens('room a1:'  + "\n" +
                            'end'       + "\n" +
                            'room a1:'  + "\n" +
                            'end'       )
     built_tree = build_tree(tokens)
     room1 = Room()
     self.assertEqual(built_tree, None)
     print("test_room_reuse passed")
Beispiel #5
0
 def test_room_end_error(self):
     '''
     Тестирование синтаксической ошибки (нет конца комнаты)
     '''
     print("\ntest_room_end_error")
     tokens = create_tokens('room a1:'  + "\n" +
                            'end'       + "\n" +
                            'room a2:'  + "\n" +
                            'room a3:'  + "\n" +
                            'end'       )
     built_tree = build_tree(tokens)
     self.assertEqual(built_tree, None)
     print("test_room_end_error passed")
Beispiel #6
0
 def test_no_colon(self):
     '''
     Тестирование синтаксической ошибки (нет двоеточия)
     '''
     print("\ntest_no_colon")
     tokens = create_tokens('room a1:'  + "\n" +
                            'end'       + "\n" +
                            'room a2'   + "\n" +
                            'end'       + "\n" +
                            'room a3:'  + "\n" +
                            'end'       )
     built_tree = build_tree(tokens)
     self.assertEqual(built_tree, None)
     print("test_no_colon passed")
Beispiel #7
0
def compile():
    '''
    Компилирует файл (собирает дерево и анализирует его, 
    используя модули scanner, parser, analyzer)
    В случае успешной компиляции возвращает собранное дерево
    В случае ошибки возвращает None
    '''
    print("compiling:")
    tokens = find_tokens()
    if tokens == None: 
        return None
    tree = build_tree(tokens)
    if tree == None:
        return None
    if analyse_all_errors(tree):
        return None
    print("compiled successfully")
    return tree
Beispiel #8
0
 def test_some_rooms(self):
     '''
     Тестирование нескольких комнат
     '''
     print("\ntest_some_rooms")
     tokens = create_tokens('room a1:'  + "\n" +
                            'end'       + "\n" +
                            'room a2:'  + "\n" +
                            'end'       + "\n" +
                            'room a3:'  + "\n" +
                            'end'       )
     built_tree = build_tree(tokens)
     room = Room()
     tree = {
         "a1" : room,
         "a2" : room,
         "a3" : room
         }
     self.assertTrue(are_equal(tree, built_tree))
     print("test_some_rooms passed")