aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test_preprocess_flag.sh
blob: 3b52bc0d3afd90e9a9cafaad0b53748fe3ae8b97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
cat <<'EOF' > expected

int main () {
 int x = 100;
 int y = 0;
 return 0;
}
EOF

test_cpp <<'EOF'
#define MAX 100
#define MIN 0

int main() {
    int x = MAX;
    int y = MIN;
    return 0;
}
EOF

cat <<'EOF' > expected

int main () {
 int sum = ( ( 10) + ( 20));
 int product = ( ( 3) * ( 4));
 return 0;
}
EOF

test_cpp <<'EOF'
#define ADD(a, b) ((a) + (b))
#define MUL(x, y) ((x) * (y))

int main() {
    int sum = ADD(10, 20);
    int product = MUL(3, 4);
    return 0;
}
EOF

cat <<'EOF' > expected
int main () {
 return 42;
}
EOF

test_cpp <<'EOF'
#define FOO 42
int main() {
    return FOO;
}
EOF

cat <<'EOF' > expected
int foo () { return 1; }
EOF

test_cpp <<'EOF'
#define X 1
#ifdef X
int foo() { return 1; }
#else
int foo() { return 0; }
#endif
EOF

cat <<'EOF' > expected

int main () {
 int x = 1 + 2 * 3;
 return 0;
}
EOF

test_cpp <<'EOF'
#define A 1
#define B A + 2
#define C B * 3

int main() {
    int x = C;
    return 0;
}
EOF

cat <<'EOF' > expected

int main () {
 int x = ( 5 + 3);
 int y = ( ( 5) + ( 3));
 return 0;
}
EOF

test_cpp <<'EOF'
#define SIMPLE (5 + 3)
#define COMPLEX(a, b) ((a) + (b))

int main() {
    int x = SIMPLE;
    int y = COMPLEX(5, 3);
    return 0;
}
EOF

cat <<'EOF' > expected

int main () {
 int bar = 0;
 bar ++;
}
EOF

test_cpp <<'EOF'
#define A(a) a
#define B(b) b

int main() {
    A(int)B(bar) = 0;
    bar++;
}
EOF