aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test_preprocess_flag.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_preprocess_flag.sh')
-rw-r--r--tests/test_preprocess_flag.sh122
1 files changed, 122 insertions, 0 deletions
diff --git a/tests/test_preprocess_flag.sh b/tests/test_preprocess_flag.sh
new file mode 100644
index 0000000..3b52bc0
--- /dev/null
+++ b/tests/test_preprocess_flag.sh
@@ -0,0 +1,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