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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//! Mutation-proof boundary tests for the qw-whitespace seam in `perl-module`.
//!
//! Each test pins ONE decision boundary so that a single-line mutation of the
//! guarding sub-condition causes exactly that test to fail. Expectations were
//! derived from the actual binary output of `extract_require_import_symbols`
//! on `origin/main` after the fix shipped — never from predicted behaviour.
//!
//! Seam — qw-delimiter whitespace trim (`import/mod.rs`, `parse_qw_arg_list`, #1204)
//! Issue: `Foo::Bar->import(qw [alpha beta])` (space between `qw` and `[`)
//! was silently dropped. The space was treated as the delimiter, which is
//! not in the bracket-closing map, so the whole list was rejected.
//! Fix: `trimmed.strip_prefix("qw")?.trim_start()` — two changes in tandem:
//! (a) `.trim_start()` removes leading whitespace before the delimiter.
//! (b) The explicit `|| delimiter.is_whitespace()` guard was removed from
//! the alphanumeric/underscore rejection check, because after trimming
//! the delimiter can never be whitespace when the input is valid.
//!
//! The discriminating observable signal is `extract_require_import_symbols`
//! (public API). A mutation that:
//! - removes `.trim_start()`, OR
//! - restores `|| delimiter.is_whitespace()` in the guard,
//! causes the spaced-delimiter tests below to return an empty Vec instead
//! of the expected symbol list.
//!
//! Key output shapes:
//! `qw [a b]` → `["a", "b"]` (space before delimiter — the fixed seam)
//! `qw(a b)` → `["a", "b"]` (compact form — must stay working; control)
//! `qw\t[a b]` → `["a", "b"]` (tab before delimiter)
//! `qwfoo` → `[]` (bareword after qw — must stay rejected)
use extract_require_import_symbols;
use parse_qw_arg_list;
// ── helper ────────────────────────────────────────────────────────────────────
/// Wrap `require Mod;\nMod->import(ARG_SUFFIX)\n` and return the extracted
/// symbol names via the public `extract_require_import_symbols` API.
///
/// `arg_suffix` is everything from the opening `(` of `import(...)` onward,
/// e.g. `"(qw [alpha beta])"`.
// ═══════════════════════════════════════════════════════════════════════════════
// SEAM — qw-delimiter whitespace trim (`parse_qw_arg_list`, #1204)
// ═══════════════════════════════════════════════════════════════════════════════
//
// The fix changes two related things in `parse_qw_arg_list`:
// (a) `let after_operator = trimmed.strip_prefix("qw")?.trim_start();`
// Without `.trim_start()`, leading whitespace becomes the delimiter.
// Space is not in the bracket-closing map, so `closing = ' '` and the
// inner-extraction indexing goes wrong → empty symbol list.
// (b) The guard `if delimiter.is_ascii_alphanumeric() || delimiter == '_' {`
// Previously also had `|| delimiter.is_whitespace()`. After (a) the
// delimiter is never whitespace for valid input, but without (b) the
// old guard would reject all spaced-delimiter forms even after (a).
//
// Both (a) and (b) are tested here through the public API so RIPR can trace
// the mutation discriminating signal through the module boundary.
// ── BOUNDARY A: space before `[` delimiter → symbols extracted (tests trim_start) ──
/// `qw [a b]` — space before `[` delimiter must yield `["a", "b"]`.
/// Pinned boundary: `.trim_start()` present → delimiter is `[` → correct extraction.
/// Removing `.trim_start()` makes the delimiter `' '`, which matches `other => ' '`
/// in the closing map, so `inner_end` goes to `after_operator.len() - 1` on the
/// space-prefixed string and produces garbage (or empty) instead of `["a", "b"]`.
/// `qw [a b]` — exact symbol names match, not just non-empty.
/// A mutation that strips the wrong range (off-by-one) would produce mangled names.
// ── BOUNDARY B: compact form (no space) still works → control case ────────────
/// `qw(a b)` — compact form must continue to yield `["a", "b"]`.
/// Verifies the guard does not over-trim or break the existing path.
// ── BOUNDARY C: tab before delimiter ─────────────────────────────────────────
/// `qw\t[a b]` — tab as whitespace before `[` must yield `["a", "b"]`.
/// Boundary: `.trim_start()` strips all whitespace, not just ASCII space.
/// Removing `.trim_start()` makes `\t` the delimiter → extraction fails.
// ── BOUNDARY D: space before `(` delimiter ───────────────────────────────────
/// `qw (a b)` — space before `(` delimiter must yield `["a", "b"]`.
/// Tests a different bracket form to ensure the bracket-map path is also covered.
// ── BOUNDARY E: space before `/` non-bracket delimiter ───────────────────────
/// `qw /a b/` — space before slash delimiter must yield `["a", "b"]`.
/// Tests the `other => other` arm of the closing-character match.
/// Without `.trim_start()`, space becomes delimiter and `closing = ' '`
/// causing the trailing-space check to fail (the string ends with `/`, not ` `).
// ── BOUNDARY F: bareword after qw stays rejected (no-whitespace guard removed) ──
/// `qwfoo` — bareword directly after qw must produce no symbols.
/// Pinned boundary: the alphanumeric/underscore guard is still in place.
/// A mutation removing `delimiter.is_ascii_alphanumeric()` would let
/// `qwfoo` be treated as a delimiter `'f'` — producing garbled output.
// ── BOUNDARY G: the whitespace-guard is gone — space is now valid before delimiters ──
/// Regression: the old `|| delimiter.is_whitespace()` guard must NOT be present.
/// If a mutation restores it, `qw [..]` returns empty even after `.trim_start()`.
/// This test is the direct observable proof that the guard change holds.
/// It is structurally identical to BOUNDARY A but documents the specific guard seam.
// ── BOUNDARY H: module field is correctly populated for spaced-delimiter form ──
/// Full `RequireImportEntry` field check: module name is preserved for spaced form.
/// Verifies that the trim doesn't corrupt the module name extracted from the
/// `require Foo::Bar` line.
// ── BOUNDARY I: inner_start > inner_end guard (short/unclosed input) ─────────
/// `qw[` with no closing bracket must yield no symbols.
/// Pinned boundary: `inner_start > inner_end` guard in `parse_qw_arg_list`.
/// When the input after trimming has only the opening delimiter (no room for
/// content + closing), `checked_sub` returns `Some(0)` and
/// `inner_start (1) > inner_end (0)` → `None`.
/// Observable via the public API: the import call never matches.
// ── BOUNDARY J: !after_operator.ends_with(closing) guard (mismatched delimiter) ──
/// `qw(abc]` — mismatched closing delimiter must yield no symbols.
/// Pinned boundary: `!after_operator.ends_with(closing)` guard in `parse_qw_arg_list`.
/// When the opening delimiter is `(` but the closing is `]`, the guard returns `None`.
/// Observable via the public API: the import call with mismatched delimiters extracts nothing.
// ═══════════════════════════════════════════════════════════════════════════════
// DIRECT SEAM BOUNDARY ANCHORS — parse_qw_arg_list (pub API, direct call)
// ═══════════════════════════════════════════════════════════════════════════════
//
// These tests call `parse_qw_arg_list` directly via the public API path
// (since it is `pub` in `perl_module::import`) to give RIPR's static call-graph
// a directly traceable reach edge from this test file to the seam.
//
// Seam A: `if delimiter.is_ascii_alphanumeric() || delimiter == '_'` (line ~667)
// Covered by: parse_qw_arg_list_direct_digit_delimiter,
// parse_qw_arg_list_direct_underscore_delimiter
//
// Seam B: `if inner_start > inner_end || !after_operator.ends_with(closing)` (line ~681)
// Covered by: parse_qw_arg_list_direct_unclosed_bracket,
// parse_qw_arg_list_direct_mismatched_closing
// ── Direct seam A: alphanumeric guard ────────────────────────────────────────
/// `qw9abc` — digit directly after qw, `delimiter.is_ascii_alphanumeric()` fires.
/// RIPR seam anchor: direct call with a boundary input for the alphanumeric guard.
/// A mutation removing `delimiter.is_ascii_alphanumeric()` would let `'9'` through
/// as a delimiter, producing garbage output instead of `None`.
/// `qw_foo` — underscore directly after qw, `delimiter == '_'` fires.
/// RIPR seam anchor: direct call with a boundary input for the underscore guard.
/// A mutation removing `delimiter == '_'` would let `'_'` be treated as a
/// symmetric delimiter, extracting `"foo"` instead of returning `None`.
// ── Direct seam B: inner-bounds and closing-match guards ──────────────────────
/// `qw[` — inner_start (1) > inner_end (0), checked_sub returns Some(0).
/// RIPR seam anchor: direct call with a boundary input for the inner_start > inner_end guard.
/// A mutation removing the guard would produce an inverted slice `&rest[1..0]` (panic or UB).
/// `qw(abc]` — opening `(` but closing `]`, `!after_operator.ends_with(')')` fires.
/// RIPR seam anchor: direct call with a boundary input for the ends_with mismatch guard.
/// A mutation removing this guard would silently accept mismatched delimiters.