summaryrefslogtreecommitdiff
path: root/tests/t0008-comments.sh
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-01 12:02:28 +0300
committerkx <kx@radix-linux.su>2026-10-01 12:02:28 +0300
commitba1b04d64bdfaf377915b22f77520216ebe47674 (patch)
tree044343035c28b2b04ca9725f26e9b7c39342d19c /tests/t0008-comments.sh
parent124b140798456778e2a96851cc7268aa9a726698 (diff)
downloadmcpu-cpp-1.0.2.tar.xz
Version 1.0.21.0.2
Diffstat (limited to 'tests/t0008-comments.sh')
-rwxr-xr-xtests/t0008-comments.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/t0008-comments.sh b/tests/t0008-comments.sh
new file mode 100755
index 0000000..26386ba
--- /dev/null
+++ b/tests/t0008-comments.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+set -eu
+src="${TMPDIR-/tmp}/mcpu-cpp-comments-$$.c"
+out="${TMPDIR-/tmp}/mcpu-cpp-comments-$$.out"
+trap 'rm -f "$src" "$out"' EXIT HUP INT TERM
+cat > "$src" <<'EOT'
+/*
+#lang "diff"
+*/
+int c_side;
+/* comment before directive */ #lang "diff"
+y' = 1;
+#endlang
+ // one-line comment
+ /*
+ multi-line comment
+ */
+LEFT/**/RIGHT
+int block_tail; /* block tail */
+int line_tail; // line tail
+int multi_tail; /*
+ block tail
+ */
+EOT
+"$MCPU_CPP" --no-config "$src" -o "$out"
+grep 'int c_side' "$out" >/dev/null
+grep "y' = 1" "$out" >/dev/null
+grep '^LEFT RIGHT$' "$out" >/dev/null
+
+# Comment-only lines must be really empty; no synthetic or leading spaces remain.
+if grep '^[[:blank:]][[:blank:]]*$' "$out" >/dev/null; then
+ exit 1
+fi
+
+# A comment ending a non-empty line must not leave trailing whitespace.
+grep '^int block_tail;$' "$out" >/dev/null
+grep '^int line_tail;$' "$out" >/dev/null
+grep '^int multi_tail;$' "$out" >/dev/null
+if grep '[[:blank:]]$' "$out" >/dev/null; then
+ exit 1
+fi