Ejemplo n.º 1
0
 def test_save_and_retrieve_all_urls_for_c(self):
     """
     Test get_all_urls function, for new language - c, after adding it to DB
     """
     data = {"urls": ["c_url1", "c_url2"], "c_url1": {"type": "class", "name": "section"},
                                           "c_url2": {"type": "id", "name": "content"}}
     ce = ContributionEngine("C", "")
     ce.add_urls_for_language(data)
     res = get_urls_for_language("C")
     self.assertEqual(data["urls"], res)
Ejemplo n.º 2
0
 def test_add_classification_for_language_classify(self):
     """
     Test add_classification_for_language function, use classify function to test
     """
     ndb.get_context().clear_cache()
     data = {"statements": ["for", "if", "else"], "operators": ['signed'], "data_types": ["int", "long", "float", "char",
             "double"], "expressions": ['sizeof'], "other": []}
     tr = TranslationEngine("C")
     ce = ContributionEngine("C")
     ce.add_classification_for_language(data)
     self.assertEqual("statement", tr.classify_keywords("for", "keyword"))
     self.assertEqual("data type", tr.classify_keywords("int", "keyword"))
     self.assertEqual("expression", tr.classify_keywords("sizeof", "keyword"))
     self.assertEqual("operator", tr.classify_keywords("signed", "keyword"))
Ejemplo n.º 3
0
 def test_save_and_retrieve_all_details_for_url_c(self):
     """
     Test get all details about url, after saving it in DB using 'add_urls_for_language' function
     """
     data = {"urls": ["c_url1", "c_url2"], "c_url1": {"type": "class", "name": "section"},
                                           "c_url2": {"type": "id", "name": "content"}}
     ce = ContributionEngine("C", "")
     ce.add_urls_for_language(data)
     _type, name = get_details_about_url("c_url1")
     self.assertEqual(_type, "class")
     self.assertEqual(name, "section")
     _type, name = get_details_about_url("c_url2")
     self.assertEqual(_type, "id")
     self.assertEqual(name, "content")
     _type, name = get_details_about_url("https://wiki.python.org")
     self.assertEqual(_type, "id")
     self.assertEqual(name, "content")
Ejemplo n.º 4
0
    def test_add_new_language_json_C_check_real_code(self):
        """
        Test add new language function, add new language c and run parser on it
        """
        ndb.get_context().clear_cache()
        data = dict()
        ce = ContributionEngine("C")
        data['keywords'] = ["auto", "else", "long", "switch", "break", "enum", "register", "typedef", "case", "extern",
                            "char", "float", "short", "unsigned", "const", "for", "signed", "continue", "goto", 'void',
                            "volatile", "default", "if", "static", "while", "do", "int", "struct", "_Packed", "double",
                            "return", "union",  "sizeof"]
        data['str_symbol1'] = [str_symbol1]
        data['str_symbol2'] = [str_symbol2]
        data['operations'] = ['+', '-', '*', '/', '%', '++', '--',  '==', '!=', '<', '<=', '>', '>=', '=', '&', '|', '^',
                              '<<', '>>', '&&', '||', '!', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '&=', '^=',
                              '?', ':', '~', '|=']
        data['add_library'] = ["include"]
        data['literals'] = []
        data['start_comment_symb'] = ['//']
        data['comment_start1'] = ['/*']
        data['comment_end1'] = ['*/']
        data['comment_start2'] = []
        data['comment_end2'] = []
        data['func_def'] = []
        data['class_keyword'] = []
        data['escape_character'] = ['\\']
        data['func_start'] = ['(']
        data['function_call_char'] = ['(']
        data['function_call_must_char'] = "True"
        data['other'] = {}
        json_data = json.dumps(data)
        ce.add_new_language_json(json_data)
        dal = DAL()
        res = dal.get_all_data_for_language("C")
        print res
        self.filename = "parser_tests/c_real_code.txt"
        self.run_parser()

        expected_lib = ['HashTable.h']
        expected_keywords = ['include', 'void', 'int', 'char', 'if', 'return', 'for']
        expected_functions_calls = ['freeTable', 'freeList', 'free', 'free']
        self.assertEqual(expected_keywords, self.p.keywords)
        self.assertEqual(expected_functions_calls, self.p.scanner.functions_calls)
        self.assertEqual(expected_lib, self.p.scanner.libraries)