mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-06-16 17:40:57 +03:00
Add test cases for comment nesting
Add a test case that would fail if all line comments were parsed before block comments, and a test case that would fail if all block comments were parsed before line comments. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@ -820,6 +820,94 @@ exit:
|
|||||||
yes sir yes sir
|
yes sir yes sir
|
||||||
3 bags full
|
3 bags full
|
||||||
}
|
}
|
||||||
|
'''
|
||||||
|
self.assertEqual(code, expected)
|
||||||
|
|
||||||
|
@patch("generate_test_code.gen_dispatch")
|
||||||
|
@patch("generate_test_code.gen_dependencies")
|
||||||
|
@patch("generate_test_code.gen_function_wrapper")
|
||||||
|
@patch("generate_test_code.parse_function_arguments")
|
||||||
|
def test_line_comment_in_block_comment(self, parse_function_arguments_mock,
|
||||||
|
gen_function_wrapper_mock,
|
||||||
|
gen_dependencies_mock,
|
||||||
|
gen_dispatch_mock):
|
||||||
|
"""
|
||||||
|
Test with line comment in block comment.
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
parse_function_arguments_mock.return_value = ([], '', [])
|
||||||
|
gen_function_wrapper_mock.return_value = ''
|
||||||
|
gen_dependencies_mock.side_effect = gen_dependencies
|
||||||
|
gen_dispatch_mock.side_effect = gen_dispatch
|
||||||
|
data = '''
|
||||||
|
void func( int x /* // */ )
|
||||||
|
{
|
||||||
|
ba ba black sheep
|
||||||
|
have you any wool
|
||||||
|
exit:
|
||||||
|
yes sir yes sir
|
||||||
|
3 bags full
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
'''
|
||||||
|
stream = StringIOWrapper('test_suite_ut.function', data)
|
||||||
|
_, _, code, _ = parse_function_code(stream, [], [])
|
||||||
|
|
||||||
|
expected = '''#line 1 "test_suite_ut.function"
|
||||||
|
|
||||||
|
void test_func( int x )
|
||||||
|
{
|
||||||
|
ba ba black sheep
|
||||||
|
have you any wool
|
||||||
|
exit:
|
||||||
|
yes sir yes sir
|
||||||
|
3 bags full
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
self.assertEqual(code, expected)
|
||||||
|
|
||||||
|
@patch("generate_test_code.gen_dispatch")
|
||||||
|
@patch("generate_test_code.gen_dependencies")
|
||||||
|
@patch("generate_test_code.gen_function_wrapper")
|
||||||
|
@patch("generate_test_code.parse_function_arguments")
|
||||||
|
def test_block_comment_in_line_comment(self, parse_function_arguments_mock,
|
||||||
|
gen_function_wrapper_mock,
|
||||||
|
gen_dependencies_mock,
|
||||||
|
gen_dispatch_mock):
|
||||||
|
"""
|
||||||
|
Test with block comment in line comment.
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
parse_function_arguments_mock.return_value = ([], '', [])
|
||||||
|
gen_function_wrapper_mock.return_value = ''
|
||||||
|
gen_dependencies_mock.side_effect = gen_dependencies
|
||||||
|
gen_dispatch_mock.side_effect = gen_dispatch
|
||||||
|
data = '''
|
||||||
|
// /*
|
||||||
|
void func( int x )
|
||||||
|
{
|
||||||
|
ba ba black sheep
|
||||||
|
have you any wool
|
||||||
|
exit:
|
||||||
|
yes sir yes sir
|
||||||
|
3 bags full
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
'''
|
||||||
|
stream = StringIOWrapper('test_suite_ut.function', data)
|
||||||
|
_, _, code, _ = parse_function_code(stream, [], [])
|
||||||
|
|
||||||
|
expected = '''#line 1 "test_suite_ut.function"
|
||||||
|
|
||||||
|
|
||||||
|
void test_func( int x )
|
||||||
|
{
|
||||||
|
ba ba black sheep
|
||||||
|
have you any wool
|
||||||
|
exit:
|
||||||
|
yes sir yes sir
|
||||||
|
3 bags full
|
||||||
|
}
|
||||||
'''
|
'''
|
||||||
self.assertEqual(code, expected)
|
self.assertEqual(code, expected)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user