blob: 492d4e534a50e989a1ddd495878eb0b85ae2d597 (
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
#!/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"
}
@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" {
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"
}
|