1 module it.c.compile.preprocessor;
2 
3 import it;
4 
5 @("simple macro")
6 @safe unittest {
7     shouldCompile(
8         C(
9             `
10                 #define FOO 5
11             `
12         ),
13         D(
14             q{
15                 int[FOO] foos;
16                 static assert(foos.length == 5, "Wrong length for foos");
17             }
18         )
19     );
20 }
21 
22 @("define macro, undefine, then define again")
23 @safe unittest {
24     shouldCompile(
25         C(
26             `
27                 #define FOO foo
28                 #undef FOO
29                 #define FOO bar
30                 int FOO(int i);
31             `
32         ),
33         D(
34             q{
35                 int i = bar(2);
36             }
37         )
38     );
39 }
40 
41 
42 @("include guards")
43 @safe unittest {
44     with(immutable IncludeSandbox()) {
45         writeFile("hdr.h",
46                   `#ifndef HAHA
47                    #    define HAHA
48                    int inc(int);
49                    #endif`);
50         writeFile("foo.dpp",
51                   `#include "hdr.h"
52                    import bar;
53                    int func(int i) { return inc(i) * 2; }`);
54         writeFile("bar.dpp",
55                   `#include "hdr.h";
56                    int func(int i) { return inc(i) * 3; }`);
57 
58         runPreprocessOnly("foo.dpp");
59         runPreprocessOnly("bar.dpp");
60         shouldCompile("foo.d");
61     }
62 }
63 
64 
65 @("octal.whitespace")
66 @safe unittest {
67     shouldCompile(
68         C(
69             `
70                 #define FOO	   00
71             `
72         ),
73         D(
74             q{
75             }
76         )
77     );
78 
79 }