summaryrefslogtreecommitdiff
path: root/tests/t0009-text-scanner.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/t0009-text-scanner.sh')
-rwxr-xr-xtests/t0009-text-scanner.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/t0009-text-scanner.sh b/tests/t0009-text-scanner.sh
new file mode 100755
index 0000000..773968f
--- /dev/null
+++ b/tests/t0009-text-scanner.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+set -eu
+src="${TMPDIR-/tmp}/mcpu-cpp-scan-$$.c"
+out="${TMPDIR-/tmp}/mcpu-cpp-scan-$$.out"
+err="${TMPDIR-/tmp}/mcpu-cpp-scan-$$.err"
+bom="${TMPDIR-/tmp}/mcpu-cpp-bom-$$.c"
+nul="${TMPDIR-/tmp}/mcpu-cpp-nul-$$.c"
+trap 'rm -f "$src" "$out" "$err" "$bom" "$nul"' EXIT HUP INT TERM
+
+cat > "$src" <<'EOT'
+const char *a = "/* not a comment";
+#lang "diff"
+y' = 1;
+const char *b = "*/ still not a comment";
+#endlang
+const char *c = "// not a comment";
+/* real comment starts here
+#lang "alg"
+*/
+int c_side;
+EOT
+"$MCPU_CPP" --no-config "$src" -o "$out"
+grep '#lang "diff"' "$out" >/dev/null
+grep "y' = 1" "$out" >/dev/null
+grep 'int c_side' "$out" >/dev/null
+
+# UTF-8 BOM is accepted and removed at the external text boundary.
+printf '\357\273\277int bom_ok;\n' > "$bom"
+"$MCPU_CPP" --no-config "$bom" -o "$out"
+grep 'int bom_ok' "$out" >/dev/null
+
+# Embedded NUL is not text and must never be silently truncated.
+printf 'int before;\000int after;\n' > "$nul"
+if "$MCPU_CPP" --no-config "$nul" -o "$out" 2>"$err"; then
+ exit 1
+fi
+grep 'NUL character is not allowed' "$err" >/dev/null