blob: 21c6784d3ff7764ad407b985f18acb935327dd52 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#!/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"
}
|