Ejemplo n.º 1
0
 def test_error_name_reserved_keyword(self):
     expected = ("Game name 'bool': name conflicts with a keyword of a "
                 "target language.")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'name': 'bool'
         }))
Ejemplo n.º 2
0
 def test_error_function_reserved_keyword(self):
     expected = ("Function 'static': name conflicts with a keyword of a "
                 "target language.")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'function': [{
                 'fct_name': 'static',
                 'fct_summary': 'static is a keyword',
                 'fct_ret_type': 'int',
                 'fct_arg': [],
             }]
         }))
Ejemplo n.º 3
0
 def test_error_func_unknown_return_type(self):
     expected = ("Function 'foobar_fail' has an unknown return type "
                 "'whatever'")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'function': [{
                 'fct_name': 'foobar_fail',
                 'fct_summary': 'argument type is unknown',
                 'fct_ret_type': 'whatever',
                 'fct_arg': [],
             }]
         }))
Ejemplo n.º 4
0
 def test_error_func_unknown_arg_type(self):
     expected = ("Function 'foobar_fail': Argument 'foobar' of unknown "
                 "type 'whatever'")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'function': [{
                 'fct_name': 'foobar_fail',
                 'fct_summary': 'argument type is unknown',
                 'fct_ret_type': 'int',
                 'fct_arg': [
                     ['foobar', 'whatever', ''],
                 ],
             }]
         }))
Ejemplo n.º 5
0
 def test_error_func_arg_redefined(self):
     expected = ("Function 'foobar_fail': Argument 'barfoo' was defined "
                 "twice")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'function': [{
                 'fct_name': 'foobar_fail',
                 'fct_summary': 'same argument is here twice',
                 'fct_ret_type': 'int',
                 'fct_arg': [
                     ['foobar', 'int', ''],
                     ['barfoo', 'int', ''],
                     ['barfoo', 'string', ''],
                 ],
             }]
         }))
Ejemplo n.º 6
0
 def test_error_struct_shadows_enum(self):
     expected = "Type sometype was defined twice."
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'enum': [{
                 'enum_name': 'sometype',
                 'enum_summary': 'some type',
                 'enum_field': [
                     ['x', 'some field']
                 ]
             }],
             'struct': [{
                 'str_name': 'sometype',
                 'str_summary': 'some type',
                 'str_field': [
                     ['y', 'int', 'some field']
                 ]
             }],
         }))
Ejemplo n.º 7
0
 def test_error_func_defined_twice(self):
     expected = "Function 'foobar_fail' was defined twice."
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'function': [
                 {
                     'fct_name': 'foobar_fail',
                     'fct_summary': 'defined once',
                     'fct_ret_type': 'int',
                     'fct_arg': [],
                 },
                 {
                     'fct_name': 'foobar_fail',
                     'fct_summary': 'defined twice',
                     'fct_ret_type': 'double',
                     'fct_arg': [],
                 },
             ]
         }))
Ejemplo n.º 8
0
 def test_error_struct_field_typename(self):
     expected = ("Struct structtype: Field 'conflict' conflicts with a "
                 "type name")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'enum': [{
                 'enum_name': 'conflict',
                 'enum_summary': 'enum type',
                 'enum_field': [
                     ['x', 'some field']
                 ]
             }],
             'struct': [{
                 'str_name': 'structtype',
                 'str_summary': 'struct type',
                 'str_field': [
                     ['conflict', 'int', 'field with conflict name']
                 ]
             }],
         }))
Ejemplo n.º 9
0
 def test_error_function_arg_reserved_keyword(self):
     expected = ("Function add_stuff: argument 'type': name conflicts with "
                 "a keyword of a target language.")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'enum': [{
                 'enum_name': 'error',
                 'enum_summary': 'error',
                 'enum_field': [
                     ['ok', 'OK']
                 ]
             }],
             'function': [{
                 'fct_name': 'add_stuff',
                 'fct_summary': 'add a thing',
                 'fct_ret_type': 'error',
                 'fct_action': 'yes',
                 'fct_arg': [['type', 'int', 'Type of stuff to add']],
             }]
         }))
Ejemplo n.º 10
0
 def test_error_unicity_struct_fields(self):
     expected = ("struct 'structtype': Field name 'conflict' already used "
                 "in enum 'enumtype'. This will confuse some type "
                 "inferrers.")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'enum': [{
                 'enum_name': 'enumtype',
                 'enum_summary': 'enum type',
                 'enum_field': [
                     ['conflict', 'some field']
                 ]
             }],
             'struct': [{
                 'str_name': 'structtype',
                 'str_summary': 'struct type',
                 'str_field': [
                     ['conflict', 'int', 'field with conflict name']
                 ]
             }],
         }))
Ejemplo n.º 11
0
 def test_error_func_arg_type_conflict(self):
     expected = ("Function 'foobar_fail': Argument 'sometype' conflicts "
                 "with a type name")
     with self.assertRaisesRegex(GameError, expected):
         Game(get_test_game({
             'struct': [{
                 'str_name': 'sometype',
                 'str_summary': 'some type',
                 'str_field': [
                     ['x', 'int', 'some field']
                 ]
             }],
             'function': [{
                 'fct_name': 'foobar_fail',
                 'fct_summary': 'argument and type have same name',
                 'fct_ret_type': 'int',
                 'fct_arg': [
                     ['foo', 'sometype', ''],
                     ['sometype', 'int', ''],
                 ],
             }]
         }))