Fix for issue 6: support concatenation of string literals
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py
index 20667ac..3e32cb6 100644
--- a/tests/test_c_parser.py
+++ b/tests/test_c_parser.py
@@ -807,6 +807,30 @@
self.assertEqual(expand_decl(f3.param_decls[1]),
['Decl', 'c', ['PtrDecl', ['TypeDecl', ['IdentifierType', ['long']]]]])
+ def test_unified_string_literals(self):
+ # simple string, for reference
+ d1 = self.get_decl_init('char* s = "hello";')
+ self.assertEqual(d1, ['Constant', 'string', '"hello"'])
+
+ d2 = self.get_decl_init('char* s = "hello" " world";')
+ self.assertEqual(d2, ['Constant', 'string', '"hello world"'])
+
+ # the test case from issue 6
+ d3 = self.parse(r'''
+ int main() {
+ fprintf(stderr,
+ "Wrong Params?\n"
+ "Usage:\n"
+ "%s <binary_file_path>\n",
+ argv[0]
+ );
+ }
+ ''')
+
+ self.assertEqual(
+ d3.ext[0].body.stmts[0].args.exprs[1].value,
+ r'"Wrong Params?\nUsage:\n%s <binary_file_path>\n"')
+
class TestCParser_whole_code(unittest.TestCase):
""" Testing of parsing whole chunks of code.