From 6705bdc69e1682982832ebea24e791581c44d0d2 Mon Sep 17 00:00:00 2001 From: Alexander M Pickering Date: Mon, 3 Aug 2026 21:52:33 -0500 Subject: Allow comments to have tabs Currently, comments need to be left-aligned, even if they appear in an indented block. change the comment form to strip the same whitespace as the first line so that comments can be indented without embedding indents in the stdin. --- tests/unit/extraction.bats | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/extraction.bats b/tests/unit/extraction.bats index 21c6784..492d4e5 100644 --- a/tests/unit/extraction.bats +++ b/tests/unit/extraction.bats @@ -91,6 +91,46 @@ teardown() { chunk_contains "$CACHE" "Second chunk content" } +@test "C: opening-tag indent is stripped from body lines" { + local prog chunk line + prog="$(awk_prog_c "$CACHE")" + run_extraction "$FIXTURES/c/indented.c" "$prog" "$CACHE" + assert_equal "$(chunk_count "$CACHE")" "2" + chunk_contains "$CACHE" "@name my_enum/one" + chunk_contains "$CACHE" "My explanation of type_one" + # Body lines must not retain the 4-space indent from before /* + if grep -rlE '^ @name |^ My explanation' "$CACHE/chunks" >/dev/null 2>&1; then + echo "FAILED: opener indent was left on body lines" >&2 + grep -rn . "$CACHE/chunks" >&2 || true + return 1 + fi + # Relative extra indent inside the comment is preserved after stripping opener indent + chunk=$(grep -rl "relative indented line" "$CACHE/chunks") + line=$(grep -F "relative indented line" "$chunk") + # shellcheck disable=SC2016 + if [ "$line" != "$(printf '\trelative indented line')" ]; then + echo "FAILED: expected relative tab indent to remain after strip" >&2 + printf 'got: %q\n' "$line" >&2 + cat "$chunk" >&2 + return 1 + fi +} + +@test "C: tab indent before opening tag is stripped from body lines" { + local prog chunk line + prog="$(awk_prog_c "$CACHE")" + run_extraction "$FIXTURES/c/indented_tabs.c" "$prog" "$CACHE" + assert_equal "$(chunk_count "$CACHE")" "1" + chunk=$(grep -rl "Tab-indented body" "$CACHE/chunks") + line=$(grep -F "Tab-indented body" "$chunk") + if [ "$line" != "Tab-indented body" ]; then + echo "FAILED: expected tab opener indent stripped from body" >&2 + printf 'got: %q\n' "$line" >&2 + cat "$chunk" >&2 + return 1 + fi +} + # ── Lua (--[[ ... ]]) ────────────────────────────────────────────────────── @test "Lua: single doc comment produces one chunk" { -- cgit v1.2.3-70-g09d2