Example #1
0
class UnittestNewtest(unittest.TestCase):
    def setUp(self):
        self.cparse = KoocG()

    def tearDown(self):
        self.cparse = None
        KoocFile.debugCleanAll()

    def test_module_simple_overload(self):
        # print("THE FIRST TEST")
        res = str(
            self.cparse.parse("""
            @module Mayuri
            {
                int tuturu;
                float tuturu;
            }
            """).to_c())
        self.assertEqual(
            res,
            "extern int M6Mayuri__i6tuturu;\nextern float M6Mayuri__f6tuturu;\n"
        )

    def test_module_simple_overload_invalid(self):
        # print("THE SECOND TEST")
        with self.assertRaises(RuntimeError) as cm:
            print(
                self.cparse.parse("""
            @module Mayuri
            {
                int tuturu;
                int tuturu;
            }
            """).to_c())

    def test_module_const_overload_invalid(self):
        # print("THE THIRD TEST")
        with self.assertRaises(RuntimeError) as cm:
            print(
                self.cparse.parse("""
            @module Mayuri
            {
                int tuturu;
                const int tuturu;
            }
            """).to_c())

    def test_module_static_overload_invalid(self):
        with self.assertRaises(RuntimeError) as cm:
            print(
                self.cparse.parse("""
            @module Mayuri
            {
                int tuturu;
                static int tuturu;
            }
            """).to_c())
Example #2
0
class UnittestNewtest(unittest.TestCase):

    def setUp(self):
        self.cparse = KoocG()

    def tearDown(self):
        self.cparse = None
        KoocFile.debugCleanAll()

    def test_module_simple_overload(self):
        # print("THE FIRST TEST")
        res = str(self.cparse.parse(
            """
            @module Mayuri
            {
                int tuturu;
                float tuturu;
            }
            """).to_c())
        self.assertEqual(res,
                         "extern int M6Mayuri__i6tuturu;\nextern float M6Mayuri__f6tuturu;\n")

    def test_module_simple_overload_invalid(self):
        # print("THE SECOND TEST")
        with self.assertRaises(RuntimeError) as cm:
            print(self.cparse.parse(
            """
            @module Mayuri
            {
                int tuturu;
                int tuturu;
            }
            """).to_c())
    def test_module_const_overload_invalid(self):
        # print("THE THIRD TEST")
        with self.assertRaises(RuntimeError) as cm:
            print(self.cparse.parse(
            """
            @module Mayuri
            {
                int tuturu;
                const int tuturu;
            }
            """).to_c())
    def test_module_static_overload_invalid(self):
        with self.assertRaises(RuntimeError) as cm:
            print(self.cparse.parse(
            """
            @module Mayuri
            {
                int tuturu;
                static int tuturu;
            }
            """).to_c())
Example #3
0
 def setUp(self):
     self.cparse = KoocG()
Example #4
0
 def setUp(self):
     self.cparse = KoocG()
Example #5
0
 def setUp(self):
     self.cparse = Declaration()
     self.kparse = KoocG()
Example #6
0
def kooc_a_file(kooc_file_name):
    cparse = KoocG()
    ast = cparse.parse_file(kooc_file_name)
    return ast
Example #7
0
class UnittestModule(unittest.TestCase):

    def setUp(self):
        self.cparse = Declaration()
        self.kparse = KoocG()

    def tearDown(self):
        self.cparse = None
        self.kparse = None
        KoocFile.debugCleanAll()
        if hasattr(self, "res") and not hasattr(self.res, "to_c"):
            self.assertFalse(self.res.diagnostic.get_content())

    ## SIMPLE TO MORE COMPLEX TEST OF VALIDS MODULES
    def test_empty_module(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "")
    def test_declaration_variable(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             void test;
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern void M4Test__v4test;\n")
    def test_declaration_assignement_variable(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             int test = 42;
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern int M4Test__i4test;\n")
    def test_declaration_function_implicit_void(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             void test();
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern void M4Test__v4testv();\n")
    def test_declaration_function_explicit_void(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             void test(void);
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern void M4Test__v4testv(void);\n")
    def test_declaration_function(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             char *test(int **toto, float tata[]);
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                        "extern char *M4Test__Pc4testPPiAf(int **toto, float tata[]);\n")
    def test_variable_overload(self):
        self.res = self.kparse.parse(
            """
            @module Mayuri
            {
                int tuturu;
                float tuturu;
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern int M6Mayuri__i6tuturu;\nextern float M6Mayuri__f6tuturu;\n")
    def test_variable_and_function_with_no_param(self):
        self.res = self.kparse.parse(
            """
            @module Mayuri
            {
                int tuturu;
                int tuturu();
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern int M6Mayuri__i6tuturu;\nextern int M6Mayuri__i6tuturuv();\n")
    def test_function_return_value_overload(self):
        self.res = self.kparse.parse(
            """
            @module Mayuri
            {
                int tuturu(float toto);
                float tuturu(float tutu);
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern int M6Mayuri__i6tuturuf(float toto);\n\
extern float M6Mayuri__f6tuturuf(float tutu);\n")
    def test_function_params_value_overload(self):
        self.res = self.kparse.parse(
            """
            @module Mayuri
            {
                double **tuturu(char toto[], void* ptr[]);
                double** tuturu(int tutu);
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern double **M6Mayuri__PPd6tuturuAcAPv(char toto[], void *ptr[]);\n\
extern double **M6Mayuri__PPd6tuturui(int tutu);\n")


    ## TODO : TESTS WITH SOME FUNCTION POINTER

    ## TEST OF OVERLOADS WITH DIFFERENTS STORAGES, QUALIFIERS OR SPECIFIER


    def test_auto_variable(self):
        waited = self.cparse.parse("""
extern auto int M4Test__i4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             auto int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_register_variable(self):
        waited = self.cparse.parse("""
extern register int M4Test__i4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             register int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_typedef_variable(self):
        waited = self.cparse.parse("""
extern typedef int M4Test__i4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             typedef int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))


    def test_static_variable(self):
        waited = self.cparse.parse("""
extern static int M4Test__i4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             static int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))


    def test_extern_variable(self):
        waited = self.cparse.parse("""
extern extern int M4Test__i4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             extern int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_inline_variable(self):
        with self.assertRaises(KoocException) as cm:
            print(self.kparse.parse(
            """
            @module Test
            {
             inline int test;
            }
            """))

#     def test_virtual_variable(self):
#         waited = self.cparse.parse("""
# extern virtual int M4Test__i4test;
#             """)
#         self.res = self.kparse.parse(
#             """
#             @module Test
#             {
#              virtual int test;
#             }
#             """)
#         self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

#     def test_explicit_variable(self):
#         waited = self.cparse.parse("""
# extern explicit int M4Test__i4test;
#             """)
#         self.res = self.kparse.parse(
#             """
#             @module Test
#             {
#              explicit int test;
#             }
#             """)
#         self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

#     def test_forceinline_variable(self):
#         waited = self.cparse.parse("""
# extern forceinline int M4Test__i4test;
#             """)
#         self.res = self.kparse.parse(
#             """
#             @module Test
#             {
#              forceinline int test;
#             }
#             """)
#         self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

#     def test_thread_variable(self):
#         waited = self.cparse.parse("""
# extern thread int M4Test__i4test;
#             """)
#         self.res = self.kparse.parse(
#             """
#             @module Test
#             {
#              thread int test;
#             }
#             """)
#         self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_volatile_variable(self):
        waited = self.cparse.parse("""
extern volatile int M4Test__V_i4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             volatile int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_restrict_variable(self):
        waited = self.cparse.parse("""
extern restrict int M4Test__R_i4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             restrict int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))


    def test_long_variable(self):
        waited = self.cparse.parse("""
extern long int M4Test__li4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             long int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_long_long_variable(self):
        waited = self.cparse.parse("""
extern long long int M4Test__lli4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             long long int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_short_variable(self):
        waited = self.cparse.parse("""
extern short int M4Test__si4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             short int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_const_ptr_variable(self):
        waited = self.cparse.parse("""
extern const int *M4Test__PC_i4test;
            """)
        self.res = self.kparse.parse(
            """
            @module Test
            {
             int const* test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_complex_variable(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             auto unsigned int const* const* test;
            }
            """)
        waited = self.cparse.parse("""
extern auto unsigned int const* const* M4Test__PC_PC_Ui4test;
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))
Example #8
0
class UnittestKooccall(unittest.TestCase):

    def setUp(self):
        self.cparse = Declaration()
        self.kparse = KoocG()

    def tearDown(self):
        self.cparse = None
        self.kparse = None
        KoocFile.debugCleanAll()
        if hasattr(self, "res") and not hasattr(self.res, "to_c"):
            self.assertFalse(self.res.diagnostic.get_content())


    def test_simple_function_call(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             int test(void);
            }
            int main()
            {
              [Test test];
            }
            """)
        waited = self.cparse.parse("""
extern int M4Test__i4testv(void);
int main()
{
    M4Test__i4testv();
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_simple_variable_call(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             int test;
            }
            int main()
            {
              [Test.test];
            }
            """)
        waited = self.cparse.parse("""
extern int M4Test__i4test;
int main()
{
    M4Test__i4test;
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_complex_variable_call(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             auto unsigned int const* const* test;
            }
            int main()
            {
              [Test.test];
            }
            """)
        #TODO : c'est quoi le mangling de cette merde ?
        waited = self.cparse.parse("""
extern const unsigned int *const *M4Test__PC_PC_Ui4test;
int main()
{
    M4Test__PC_PC_Ui4test;
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))


    # def test_simple_variable_call(self):
    #     self.res = self.kparse.parse(
    #         """
    #         int main()
    #         {
    #           [Test.test];
    #         }
    #         """)
    #     print(res.diagnostic.get_content())
    #     waited = self.cparse.parse("""
    # M4Test__i4test;
    #         """).to_c())
    #     print("RESULT = ", res, "\n")
    #     print("WAITED = ", waited, "\n")
    #     self.assertEqual(res, waited)


    def test_simple_variable_assign_call(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             int test;
            }
            int main()
            {
              int a = [Test.test];
            }
            """)
        waited = self.cparse.parse("""
extern int M4Test__i4test;
int main()
{
    int a = M4Test__i4test;
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_one_arg_call(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             int test(int toto);
            }
            int main()
            {
              [Test test :(int)42];
            }
            """)
        waited = self.cparse.parse("""
extern int M4Test__i4testi(int toto);
int main()
{
    M4Test__i4testi(42);
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_one_arg_call_invalid_arg_type(self):
        self.res = self.kparse.parse(
            """
            @module Test
            {
             int test(int toto);
            }
            int main()
            {
              [Test test :(invalid)42];
            }
            """)
        waited = self.cparse.parse("""
extern int M4Test__i4testi(int toto);
int main()
{
    M4Test__i4testi(42);
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_two_arg_call(self):
        self.res = self.kparse.parse(
            """
            @module Titor
            {
             void send_dmail(void *this, char *mail);
            }
            int main()
            {
                char *mail = "Watashi wa mad scientist !";
              @!(void)[Titor send_dmail :(void *)0 :(char *)mail];
            }
            """)
        waited = self.cparse.parse("""
extern void M5Titor__v10send_dmailPvPc(void *this, char *mail);
int main()
{
    char *mail = "Watashi wa mad scientist !";
    M5Titor__v10send_dmailPvPc(0, mail);
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_return_type_inferred_call(self):
        self.res = self.kparse.parse(
            """
            @module Titor
            {
             void send_dmail(void *this, char *mail);
             void send_dmail(char *mail);
            }
            int main()
            {
                char *mail = "Watashi wa mad scientist !";
              [Titor send_dmail :(void *)0 :(char *)mail];
            }
            """)
        waited = self.cparse.parse("""
extern void M5Titor__v10send_dmailPvPc(void *this, char *mail);
extern void M5Titor__v10send_dmailPc(char *mail);
int main()
{
    char *mail = "Watashi wa mad scientist !";
    M5Titor__v10send_dmailPvPc(0, mail);
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_empty_params_types_inferred_call(self):
        self.res = self.kparse.parse(
            """
            @module Titor
            {
             char *get_dmail(void);
            }
            //@implementation Titor { char *get_dmail(void) {return "tutu";} }
            int main()
            {
              printf("%s\n", @!(char *)[Titor get_dmail]);
            }
            """)
        waited = self.cparse.parse("""
 extern char* M5Titor__Pc9get_dmailv(void);
 int main()
 {
     printf("%s\n", M5Titor__Pc9get_dmailv());
 }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_int_params_types_inferred_call(self):
        self.res = self.kparse.parse(
            """
            @module Titor
            {
             char *get_dmail(int index);
             void *get_dmail(int index);
            }
            int main()
            {
              printf("%s\n", @!(char *)[Titor get_dmail :42]);
            }
            """)
        waited = self.cparse.parse("""
extern char* M5Titor__Pc9get_dmaili(int index);
extern void* M5Titor__Pv9get_dmaili(int index);
int main()
{
    printf("%s\n", M5Titor__Pc9get_dmaili(42));
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_all_inferred_call(self):
        self.res = self.kparse.parse(
            """
            @module Titor
            {
             char *get_dmail(int index);
            }
            int main()
            {
              printf("%s\n", [Titor get_dmail :42]);
            }
            """)
        waited = self.cparse.parse("""
extern char* M5Titor__Pc9get_dmaili(int index);
int main()
{
    printf("%s\n", M5Titor__Pc9get_dmaili(42));
}
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_overload_charptr_call(self):
        self.res = self.kparse.parse(
            """
            @module Titor
            {
             char *get_dmail(int index);
             float get_dmail(int index);
            }
            int main()
            {
              printf("%s\n", @!(char *)[Titor get_dmail :(int)42]);
            }
            """)
        waited = self.cparse.parse(
            """
            extern char* M5Titor__Pc9get_dmaili(int index);
            extern float M5Titor__f9get_dmaili(int index);
            int main()
            {
            printf("%s\n", M5Titor__Pc9get_dmaili(42));
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_overload_floatcall(self):
        self.res = self.kparse.parse(
            """
            @module Titor
            {
             char *get_dmail(int index);
             float get_dmail(int index);
            }
            int main()
            {
              printf("%s\n", @!(float)[Titor get_dmail :(int)42]);
            }
            """)
        waited = self.cparse.parse(
            """
            extern char* M5Titor__Pc9get_dmaili(int index);
            extern float M5Titor__f9get_dmaili(int index);
            int main()
            {
            printf("%s\n", M5Titor__f9get_dmaili(42));
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_function_impossible_inferred_return_type(self):
        with self.assertRaises(RuntimeError) as cm:
            print(self.kparse.parse(
            """
            @module Titor
            {
             char *get_dmail(int index);
             float get_dmail(int index);
            }
            int main()
            {
              printf("%s\n", [Titor get_dmail :(int)42]);
            }
            """))

    def test_function_impossible_inferred_params_type(self):
        with self.assertRaises(RuntimeError) as cm:
            print(self.kparse.parse(
            """
            @module Titor
            {
             char *get_dmail(int index);
             char *get_dmail(float date);
            }
            int main()
            {
              printf("%s\n", [Titor get_dmail :42]);
            }
            """))
Example #9
0
def kooc_a_file(kooc_file_name):
    cparse = KoocG()
    ast = cparse.parse_file(kooc_file_name)
    return ast
Example #10
0
 def setUp(self):
     self.cparse = Declaration()
     self.kparse = KoocG()
Example #11
0
class UnittestModule(unittest.TestCase):
    def setUp(self):
        self.cparse = Declaration()
        self.kparse = KoocG()

    def tearDown(self):
        self.cparse = None
        self.kparse = None
        KoocFile.debugCleanAll()
        if hasattr(self, "res") and not hasattr(self.res, "to_c"):
            self.assertFalse(self.res.diagnostic.get_content())

    ## SIMPLE TO MORE COMPLEX TEST OF VALIDS MODULES
    def test_empty_module(self):
        self.res = self.kparse.parse("""
            @module Test
            {
            }
            """)
        self.assertEqual(str(self.res.to_c()), "")

    def test_declaration_variable(self):
        self.res = self.kparse.parse("""
            @module Test
            {
             void test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), "extern void M4Test__v4test;\n")

    def test_declaration_assignement_variable(self):
        self.res = self.kparse.parse("""
            @module Test
            {
             int test = 42;
            }
            """)
        self.assertEqual(str(self.res.to_c()), "extern int M4Test__i4test;\n")

    def test_declaration_function_implicit_void(self):
        self.res = self.kparse.parse("""
            @module Test
            {
             void test();
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern void M4Test__v4testv();\n")

    def test_declaration_function_explicit_void(self):
        self.res = self.kparse.parse("""
            @module Test
            {
             void test(void);
            }
            """)
        self.assertEqual(str(self.res.to_c()),
                         "extern void M4Test__v4testv(void);\n")

    def test_declaration_function(self):
        self.res = self.kparse.parse("""
            @module Test
            {
             char *test(int **toto, float tata[]);
            }
            """)
        self.assertEqual(
            str(self.res.to_c()),
            "extern char *M4Test__Pc4testPPiAf(int **toto, float tata[]);\n")

    def test_variable_overload(self):
        self.res = self.kparse.parse("""
            @module Mayuri
            {
                int tuturu;
                float tuturu;
            }
            """)
        self.assertEqual(
            str(self.res.to_c()),
            "extern int M6Mayuri__i6tuturu;\nextern float M6Mayuri__f6tuturu;\n"
        )

    def test_variable_and_function_with_no_param(self):
        self.res = self.kparse.parse("""
            @module Mayuri
            {
                int tuturu;
                int tuturu();
            }
            """)
        self.assertEqual(
            str(self.res.to_c()),
            "extern int M6Mayuri__i6tuturu;\nextern int M6Mayuri__i6tuturuv();\n"
        )

    def test_function_return_value_overload(self):
        self.res = self.kparse.parse("""
            @module Mayuri
            {
                int tuturu(float toto);
                float tuturu(float tutu);
            }
            """)
        self.assertEqual(
            str(self.res.to_c()),
            "extern int M6Mayuri__i6tuturuf(float toto);\n\
extern float M6Mayuri__f6tuturuf(float tutu);\n")

    def test_function_params_value_overload(self):
        self.res = self.kparse.parse("""
            @module Mayuri
            {
                double **tuturu(char toto[], void* ptr[]);
                double** tuturu(int tutu);
            }
            """)
        self.assertEqual(
            str(self.res.to_c()),
            "extern double **M6Mayuri__PPd6tuturuAcAPv(char toto[], void *ptr[]);\n\
extern double **M6Mayuri__PPd6tuturui(int tutu);\n")

    ## TODO : TESTS WITH SOME FUNCTION POINTER

    ## TEST OF OVERLOADS WITH DIFFERENTS STORAGES, QUALIFIERS OR SPECIFIER

    def test_auto_variable(self):
        waited = self.cparse.parse("""
extern auto int M4Test__i4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             auto int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_register_variable(self):
        waited = self.cparse.parse("""
extern register int M4Test__i4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             register int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_typedef_variable(self):
        waited = self.cparse.parse("""
extern typedef int M4Test__i4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             typedef int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_static_variable(self):
        waited = self.cparse.parse("""
extern static int M4Test__i4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             static int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_extern_variable(self):
        waited = self.cparse.parse("""
extern extern int M4Test__i4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             extern int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_inline_variable(self):
        with self.assertRaises(KoocException) as cm:
            print(
                self.kparse.parse("""
            @module Test
            {
             inline int test;
            }
            """))


#     def test_virtual_variable(self):
#         waited = self.cparse.parse("""
# extern virtual int M4Test__i4test;
#             """)
#         self.res = self.kparse.parse(
#             """
#             @module Test
#             {
#              virtual int test;
#             }
#             """)
#         self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

#     def test_explicit_variable(self):
#         waited = self.cparse.parse("""
# extern explicit int M4Test__i4test;
#             """)
#         self.res = self.kparse.parse(
#             """
#             @module Test
#             {
#              explicit int test;
#             }
#             """)
#         self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

#     def test_forceinline_variable(self):
#         waited = self.cparse.parse("""
# extern forceinline int M4Test__i4test;
#             """)
#         self.res = self.kparse.parse(
#             """
#             @module Test
#             {
#              forceinline int test;
#             }
#             """)
#         self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

#     def test_thread_variable(self):
#         waited = self.cparse.parse("""
# extern thread int M4Test__i4test;
#             """)
#         self.res = self.kparse.parse(
#             """
#             @module Test
#             {
#              thread int test;
#             }
#             """)
#         self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_volatile_variable(self):
        waited = self.cparse.parse("""
extern volatile int M4Test__V_i4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             volatile int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_restrict_variable(self):
        waited = self.cparse.parse("""
extern restrict int M4Test__R_i4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             restrict int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_long_variable(self):
        waited = self.cparse.parse("""
extern long int M4Test__li4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             long int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_long_long_variable(self):
        waited = self.cparse.parse("""
extern long long int M4Test__lli4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             long long int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_short_variable(self):
        waited = self.cparse.parse("""
extern short int M4Test__si4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             short int test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_const_ptr_variable(self):
        waited = self.cparse.parse("""
extern const int *M4Test__PC_i4test;
            """)
        self.res = self.kparse.parse("""
            @module Test
            {
             int const* test;
            }
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))

    def test_complex_variable(self):
        self.res = self.kparse.parse("""
            @module Test
            {
             auto unsigned int const* const* test;
            }
            """)
        waited = self.cparse.parse("""
extern auto unsigned int const* const* M4Test__PC_PC_Ui4test;
            """)
        self.assertEqual(str(self.res.to_c()), str(waited.to_c()))
Example #12
0
def kooc_a_string(content):
    cparse = KoocG()
    ast = cparse.parse(content)
    return ast