@@ -27,19 +27,19 @@ def replace_defines_should_return_remove_comments():
27
27
def test_parse_defines ():
28
28
p = Preprocessor ()
29
29
30
- assert p .parse_defines ("" ) == {}
31
- assert p .parse_defines ("// comment" ) == {}
32
- assert p .parse_defines (" // comment" ) == {}
33
- assert p .parse_defines (" /* comment */" ) == {}
34
- assert p .parse_defines (" /* comment */ #define A 42" ) == {} # #define must be the first thing on a line
35
- assert p .parse_defines ("#define a 1" ) == {"a" : "1" }
36
- assert p .parse_defines (" #define a 1" ) == {"a" : "1" }
37
- assert p .parse_defines ("#define a 1 2" ) == {"a" : "1 2" }
38
- assert p .parse_defines ("#define f(a,b) 1" ) == {} # macros not supported
39
- assert p .parse_defines ("#define f(a, b) 1" ) == {} # macros not supported
40
- assert p .parse_defines ("#define f (a,b) 1" ) == {"f" : "(a,b) 1" } # f is not a macro
41
- assert p .parse_defines ("#define f (a, b) 1" ) == {"f" : "(a, b) 1" } # f is not a macro
42
- assert p .parse_defines ("#define RTC_ADDR 0x12345 // start of range" ) == {"RTC_ADDR" : "0x12345" }
30
+ assert p .parse_define_line ("" ) == {}
31
+ assert p .parse_define_line ("// comment" ) == {}
32
+ assert p .parse_define_line (" // comment" ) == {}
33
+ assert p .parse_define_line (" /* comment */" ) == {}
34
+ assert p .parse_define_line (" /* comment */ #define A 42" ) == {} # #define must be the first thing on a line
35
+ assert p .parse_define_line ("#define a 1" ) == {"a" : "1" }
36
+ assert p .parse_define_line (" #define a 1" ) == {"a" : "1" }
37
+ assert p .parse_define_line ("#define a 1 2" ) == {"a" : "1 2" }
38
+ assert p .parse_define_line ("#define f(a,b) 1" ) == {} # macros not supported
39
+ assert p .parse_define_line ("#define f(a, b) 1" ) == {} # macros not supported
40
+ assert p .parse_define_line ("#define f (a,b) 1" ) == {"f" : "(a,b) 1" } # f is not a macro
41
+ assert p .parse_define_line ("#define f (a, b) 1" ) == {"f" : "(a, b) 1" } # f is not a macro
42
+ assert p .parse_define_line ("#define RTC_ADDR 0x12345 // start of range" ) == {"RTC_ADDR" : "0x12345" }
43
43
44
44
45
45
@test
@@ -181,6 +181,29 @@ def test_expand_rtc_macros():
181
181
assert p .expand_rtc_macros ("READ_RTC_FIELD(1, 2)" ) == "\t reg_rd 1, 2 + 1 - 1, 2"
182
182
183
183
184
+ @test
185
+ def test_process_include_file ():
186
+ p = Preprocessor ()
187
+
188
+ defines = p .process_include_file ('fixtures/incl.h' )
189
+ assert defines ['CONST1' ] == '42'
190
+ assert defines ['CONST2' ] == '99'
191
+ assert defines .get ('MULTI_LINE' , None ) == 'abc \\ ' # correct. line continuations not supported
192
+ assert 'MACRO' not in defines
193
+
194
+
195
+ @test
196
+ def test_process_include_file_with_multiple_files ():
197
+ p = Preprocessor ()
198
+
199
+ defines = p .process_include_file ('fixtures/incl.h' )
200
+ defines = p .process_include_file ('fixtures/incl2.h' )
201
+
202
+ assert defines ['CONST1' ] == '42' , "constant from incl.h"
203
+ assert defines ['CONST2' ] == '123' , "constant overridden by incl2.h"
204
+ assert defines ['CONST3' ] == '777' , "constant from incl2.h"
205
+
206
+
184
207
if __name__ == '__main__' :
185
208
# run all methods marked with @test
186
209
for t in tests :
0 commit comments