patchutils.py: Add tests for _preprocess_source function.

This commit is contained in:
Sebastian Lackner 2016-03-26 01:10:48 +01:00
parent f8073b5148
commit 19d04e3ea1

View File

@ -685,3 +685,29 @@ def generate_ifdef_patch(original, patched, ifdef):
# Return the final diff
return diff
if __name__ == "__main__":
import unittest
# Basic tests for _preprocess_source()
class PreprocessorTests(unittest.TestCase):
def test_preprocessor(self):
source = ["int a; // comment 1",
"int b; // comment 2 \\",
" comment 3 \\",
" comment 4",
"int c; // comment with \"quotes\"",
"int d; // comment with /* c++ comment */",
"int e; /* multi \\",
" line",
" comment */",
"char *x = \"\\\\\";",
"char *y = \"abc\\\"def\";",
"char *z = \"multi\" \\",
" \"line\"",
" \"string\";"]
lines, split = _preprocess_source(source)
self.assertEqual(lines, source)
self.assertEqual(split, set([0, 1, 4, 5, 6, 9, 10, 11, 13, 14]))
unittest.main()