本文整理汇总了Python中cpp_generator.CppGenerator.generate方法的典型用法代码示例。如果您正苦于以下问题:Python CppGenerator.generate方法的具体用法?Python CppGenerator.generate怎么用?Python CppGenerator.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cpp_generator.CppGenerator
的用法示例。
在下文中一共展示了CppGenerator.generate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCppGenerator
# 需要导入模块: from cpp_generator import CppGenerator [as 别名]
# 或者: from cpp_generator.CppGenerator import generate [as 别名]
class TestCppGenerator(TestCase):
def setUp(self):
self.generator = CppGenerator()
def check_if_generated_code_for_fake_is(self, fake, expected):
generated = self.generator.generate(fake)
self.assertEquals(expected, generated)
def test_cpp_generator_should_generate_namespace_for_unknown_type(self):
fakes = [{'type': 'namespace', 'name': 'ShortStr'}]
expected = 'namespace ShortStr;'
self.check_if_generated_code_for_fake_is(fakes, expected)
def test_cpp_generator_should_generate_class_for_unknown_type(self):
fakes = [{'type': 'class', 'name': 'ShortStr'}]
expected = 'class ShortStr;'
self.check_if_generated_code_for_fake_is(fakes, expected)
def test_cpp_generator_should_generate_variable_declaration(self):
fakes = [{'type': 'field', 'declaration': 'int', 'name': 'ma'}]
expected = 'int ma;'
self.check_if_generated_code_for_fake_is(fakes, expected)
def test_cpp_generator_should_generate_function_declaration(self):
fakes = [
{'type': 'method', 'declaration': 'void (int)', 'name': 'foo'}
]
expected = 'void foo(int);'
self.check_if_generated_code_for_fake_is(fakes, expected)
def test_cpp_generator_should_generate_members_if_provided(self):
fakes = [{
'type': 'class',
'name': 'ShortStr',
'members': [
{
'type': 'method',
'declaration': 'void ()',
'name': 'Foo',
'access': 'public'
},
{
'type': 'method',
'declaration': 'void ()',
'name': 'Bar',
'access': 'public'
}
]
}]
expected = 'class ShortStr{\n'\
'\tpublic:\n'\
'\tvoid Foo();\n'\
'\tvoid Bar();\n'\
'};\n'
self.check_if_generated_code_for_fake_is(fakes, expected)
示例2: TestCppFaker
# 需要导入模块: from cpp_generator import CppGenerator [as 别名]
# 或者: from cpp_generator.CppGenerator import generate [as 别名]
class TestCppFaker(TestCase):
def setUp(self):
self.faker = CppFaker([])
self.generator = CppGenerator()
def check_if_generated_code_is_as_expected(self, lines, expected):
for line in lines:
self.faker.process_line(line)
fakes = self.faker.get_fakes()
generated = self.generator.generate(fakes)
self.assertMultiLineEqual(expected, generated)
def test_cpp_faker_should_generate_empty_string_for_unknown_msgtype(self):
self.check_if_generated_code_is_as_expected(
[('', '', '', 'warning', ['', 'ShortStr'])],
''
)
def test_cpp_faker_should_generate_empty_string_for_unknown_err(self):
self.check_if_generated_code_is_as_expected(
[('', '', '', 'error', ['unknown', 'ShortStr'])],
''
)
def test_cpp_faker_should_generate_class_for_undeclared_identifier(self):
self.check_if_generated_code_is_as_expected(
[('', '', '', 'error', ['use of undeclared identifier', 'Short'])],
'class Short{\n};\n'
)
def test_cpp_faker_should_generate_class_for_unknown_type_name(self):
self.check_if_generated_code_is_as_expected(
[('', '', '', 'error', ['unknown type name', 'ShortStr'])],
'class ShortStr;'
)
def test_cpp_faker_should_generate_members_for_classes(self):
lines = [
('', '', '', 'error', ['unknown type name', 'Foo']),
('', '', '', 'error', ['no member named', 'Bar', 'in', 'Foo'])
]
expected = 'class Foo{\n'\
'\tpublic:\n'\
'\tvoid Bar();\n'\
'};\n'
self.check_if_generated_code_is_as_expected(lines, expected)
def test_cpp_faker_initialization(self):
initial = ('', '', '', 'error', ['unknown type name', 'Foo'])
self.faker.process_line(initial)
fakes = self.faker.get_fakes()
self.faker = CppFaker(fakes)
lines = [
('', '', '', 'error', ['no member named', 'Bar', 'in', 'Foo'])
]
expected = 'class Foo{\n'\
'\tpublic:\n'\
'\tvoid Bar();\n'\
'};\n'
self.check_if_generated_code_is_as_expected(lines, expected)
def test_cpp_faker_should_not_register_duplicate_findings(self):
self.check_if_generated_code_is_as_expected(
[
('', '', '', 'error', ['unknown type name', 'ShortStr']),
('', '', '', 'error', ['unknown type name', 'ShortStr'])
],
'class ShortStr;'
)
def test_cpp_faker_should_not_register_duplicate_members(self):
self.check_if_generated_code_is_as_expected(
[
('', '', '', 'error', ['unknown type name', 'Foo']),
('', '', '', 'error', ['no member named', 'Bar', 'in', 'Foo']),
('', '', '', 'error', ['no member named', 'Bar', 'in', 'Foo'])
],
'class Foo{\n'
'\tpublic:\n'
'\tvoid Bar();\n'
'};\n',
)
def test_cpp_faker_should_change_type_of_a_variable(self):
lines = [
(
'r.cpp', '6', '4', 'error',
['use of undeclared identifier', 'ma', '']),
(
'r.cpp', '6', '4', 'error',
['', 'ma', 'does not refer to a value'])
]
expected = 'int ma;'
self.check_if_generated_code_is_as_expected(lines, expected)
示例3: create_wrapper_cpp
# 需要导入模块: from cpp_generator import CppGenerator [as 别名]
# 或者: from cpp_generator.CppGenerator import generate [as 别名]
def create_wrapper_cpp(filename, fakes):
with open("faked.cpp", "wb") as faked:
generator = CppGenerator()
faked.write(generator.generate(fakes))
faked.write('\n#include "{}"'.format(filename))