1 /**
2    Tests that we're using libclang properly.
3  */
4 module ut.transform.clang;
5 
6 
7 import ut;
8 import dpp2.expansion;
9 import dpp.runtime.options: Options;
10 import dpp.runtime.context: Context, Language;
11 
12 
13 @("includePaths")
14 @safe pure unittest {
15     {
16         Options options;
17         options.includePaths = ["foo", "bar"];
18         includePaths(options, "dir/app.dpp").should == ["foo", "bar", "dir"];
19         includePaths(options, "other/app.dpp").should == ["foo", "bar", "other"];
20     }
21 
22     {
23         Options options;
24         options.includePaths = ["quux"];
25         includePaths(options, "dir/app.dpp").should == ["quux", "dir"];
26         includePaths(options, "other/app.dpp").should == ["quux", "other"];
27     }
28 }
29 
30 
31 @("clangArgs.c.0")
32 @safe pure unittest {
33     Options options;
34     options.includePaths = ["foo", "bar"];
35     options.defines = ["quux", "toto"];
36     Context context;
37     context.options = options;
38 
39     clangArgs(context, "dir/app.dpp").shouldBeSameSetAs(
40         ["-Ifoo", "-Ibar", "-Idir", "-Dquux", "-Dtoto", "-xc"]);
41 }
42 
43 
44 @("clangArgs.c.1")
45 @safe pure unittest {
46     Options options;
47     options.includePaths = ["fizz"];
48     options.defines = ["oops"];
49     Context context;
50     context.options = options;
51 
52     clangArgs(context, "other/app.dpp").shouldBeSameSetAs(
53         ["-Ifizz", "-Iother", "-Doops", "-xc"]);
54 }
55 
56 
57 @("clangArgs.cpp.parseAsCpp")
58 @safe pure unittest {
59     Options options;
60     options.includePaths = ["fizz"];
61     options.defines = ["oops"];
62     options.parseAsCpp = true;
63     Context context;
64     context.options = options;
65 
66     clangArgs(context, "other/app.dpp").shouldBeSameSetAs(
67         ["-Ifizz", "-Iother", "-Doops", "-xc++", "-std=c++14"]);
68 }
69 
70 @("clangArgs.cpp.language")
71 @safe pure unittest {
72     Options options;
73     options.includePaths = ["fizz"];
74     options.defines = ["oops"];
75     Context context;
76     context.options = options;
77     context.language = Language.Cpp;
78 
79     clangArgs(context, "other/app.dpp").shouldBeSameSetAs(
80         ["-Ifizz", "-Iother", "-Doops", "-xc++", "-std=c++14"]);
81 }
82 
83 
84 @("getHeaderName")
85 @safe pure unittest {
86     import unit_threaded: shouldEqual;
87     getHeaderName(`#include "foo.h"`).shouldEqual(`foo.h`);
88     getHeaderName(`#include "bar.h"`).shouldEqual(`bar.h`);
89     getHeaderName(`#include "foo.h" // comment`).shouldEqual(`foo.h`);
90     getHeaderName(`#include <foo.h>`).shouldEqual(`foo.h`);
91     getHeaderName(`    #include "foo.h"`).shouldEqual(`foo.h`);
92 }