1 module cogito.tests.expressions;
2 
3 import cogito;
4 import std.sumtype;
5 
6 @("No conditions")
7 unittest
8 {
9     auto meter = runOnCode(q{
10 bool f()
11 {
12     return true;
13 }
14     });
15 
16     assert(meter.tryMatch!((Source source) => source.score) == 0);
17 }
18 
19 @("Single &&")
20 unittest
21 {
22     auto meter = runOnCode(q{
23 bool f()
24 {
25     return true && true;
26 }
27     });
28 
29     assert(meter.tryMatch!((Source source) => source.score) == 1);
30 }
31 
32 @("&& row")
33 unittest
34 {
35     auto meter = runOnCode(q{
36 bool f()
37 {
38     return true && true && true;
39 }
40     });
41 
42     assert(meter.tryMatch!((Source source) => source.score) == 1);
43 }
44 
45 @("?:")
46 unittest
47 {
48     auto meter = runOnCode(q{
49 int f()
50 {
51     return true ? 0 : 1;
52 }
53     });
54 
55     assert(meter.tryMatch!((Source source) => source.score) == 1);
56 }
57 
58 @("Nested ?:")
59 unittest
60 {
61     auto meter = runOnCode(q{
62 int f()
63 {
64     return true ? (true ? 1 : 0) : 1;
65 }
66     });
67 
68     assert(meter.tryMatch!((Source source) => source.score) == 3);
69 }
70 
71 @("Nested ?: in else")
72 unittest
73 {
74     auto meter = runOnCode(q{
75 int f()
76 {
77     return true ? 0 : (true ? 1 : 0);
78 }
79     });
80 
81     assert(meter.tryMatch!((Source source) => source.score) == 3);
82 }
83 
84 @("2 nested ?:")
85 unittest
86 {
87     auto meter = runOnCode(q{
88 int f()
89 {
90     return true ? (true ? 1 : 0) : (true ? 1 : 0);
91 }
92     });
93 
94     assert(meter.tryMatch!((Source source) => source.score) == 5);
95 }