#!/usr/bin/env bats # tests/unit/extraction.bats # Verifies that the AWK extraction programs correctly identify doc comment # boundaries and produce chunk files for each supported language. # # Tests operate directly on the AWK programs (via helpers/common.bash) without # running the full trbldoc.sh pipeline. load "../helpers/common.bash" FIXTURES="$BATS_TEST_DIRNAME/../fixtures" setup() { setup_workspace CACHE=".trblcache" mkdir -p "$CACHE/chunks" } teardown() { teardown_workspace } # ── C (/* ... */) ────────────────────────────────────────────────────────── @test "C: single doc comment produces one chunk" { local prog prog="$(awk_prog_c "$CACHE")" run_extraction "$FIXTURES/c/simple.c" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "1" } @test "C: two doc comments produce two chunks" { local prog prog="$(awk_prog_c "$CACHE")" run_extraction "$FIXTURES/c/multi_chunk.c" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "2" } @test "C: file with no doc comments produces no chunks" { local prog prog="$(awk_prog_c "$CACHE")" run_extraction "$FIXTURES/c/no_comments.c" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "0" } @test "C: chunk contains @exec directive for renderer" { local prog prog="$(awk_prog_c "$CACHE")" run_extraction "$FIXTURES/c/simple.c" "$prog" "$CACHE" chunk_contains "$CACHE" "@exec" } @test "C: chunk contains @file directive with source file name" { local prog prog="$(awk_prog_c "$CACHE")" run_extraction "$FIXTURES/c/simple.c" "$prog" "$CACHE" chunk_contains "$CACHE" "@file" } @test "C: chunk body lines are captured" { local prog prog="$(awk_prog_c "$CACHE")" run_extraction "$FIXTURES/c/simple.c" "$prog" "$CACHE" chunk_contains "$CACHE" "Hello from a C comment" } @test "C: non-comment source lines are not captured in chunk" { local prog prog="$(awk_prog_c "$CACHE")" run_extraction "$FIXTURES/c/simple.c" "$prog" "$CACHE" # 'int main' is code, not doc if grep -rl "int main" "$CACHE/chunks" >/dev/null 2>&1; then echo "FAILED: code line 'int main' was captured in a chunk" >&2 return 1 fi } @test "C: single-line /* */ comment produces no chunks" { local prog prog="$(awk_prog_c "$CACHE")" # no_comments.c contains a single-line /* ... */ comment on the first line run_extraction "$FIXTURES/c/no_comments.c" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "0" } @test "C: two-chunk file produces chunks with distinct content" { local prog prog="$(awk_prog_c "$CACHE")" run_extraction "$FIXTURES/c/multi_chunk.c" "$prog" "$CACHE" chunk_contains "$CACHE" "First chunk content" chunk_contains "$CACHE" "Second chunk content" } # ── Lua (--[[ ... ]]) ────────────────────────────────────────────────────── @test "Lua: single doc comment produces one chunk" { local prog prog="$(awk_prog_lua "$CACHE")" run_extraction "$FIXTURES/lua/simple.lua" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "1" } @test "Lua: chunk body lines are captured" { local prog prog="$(awk_prog_lua "$CACHE")" run_extraction "$FIXTURES/lua/simple.lua" "$prog" "$CACHE" chunk_contains "$CACHE" "Hello from a Lua comment" } @test "Lua: non-comment source lines are not captured" { local prog prog="$(awk_prog_lua "$CACHE")" run_extraction "$FIXTURES/lua/simple.lua" "$prog" "$CACHE" if grep -rl "local x" "$CACHE/chunks" >/dev/null 2>&1; then echo "FAILED: code line 'local x' was captured in a chunk" >&2 return 1 fi } @test "Lua: single-line --[[ ]] comment produces no chunks" { local prog prog="$(awk_prog_lua "$CACHE")" run_extraction "$FIXTURES/lua/single_line.lua" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "0" } # ── Python ('''renderer ... ''') ─────────────────────────────────────────── @test "Python: single doc comment produces one chunk" { local prog prog="$(awk_prog_py "$CACHE")" run_extraction "$FIXTURES/py/simple.py" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "1" } @test "Python: chunk body lines are captured" { local prog prog="$(awk_prog_py "$CACHE")" run_extraction "$FIXTURES/py/simple.py" "$prog" "$CACHE" chunk_contains "$CACHE" "Hello from a Python doc comment" } @test "Python: single-line '''content''' on one line produces no chunks" { local prog prog="$(awk_prog_py "$CACHE")" run_extraction "$FIXTURES/py/single_line.py" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "0" } # ── Markdown (whole file = one chunk) ────────────────────────────────────── @test "Markdown: whole file produces exactly one chunk" { local prog prog="$(awk_prog_md "$CACHE")" run_extraction "$FIXTURES/md/simple.md" "$prog" "$CACHE" assert_equal "$(chunk_count "$CACHE")" "1" } @test "Markdown: chunk contains @exec md directive" { local prog prog="$(awk_prog_md "$CACHE")" run_extraction "$FIXTURES/md/simple.md" "$prog" "$CACHE" chunk_contains "$CACHE" "@exec md" } @test "Markdown: chunk includes file body content" { local prog prog="$(awk_prog_md "$CACHE")" run_extraction "$FIXTURES/md/simple.md" "$prog" "$CACHE" chunk_contains "$CACHE" "Hello from a markdown file" }