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