HS test generator: accept ES6 shorthand {foo} in run() locals
Several upstream regex-pick tests use JS ES6 shorthand to pass a
local declared earlier in the test body, e.g.
const haystack = "..."
await run(\`pick match of "\\\\d+" from haystack ...\`, {locals: {haystack}});
The generator's `(\\w+)\\s*:\\s*...` locals regex only matched explicit
`key: value` entries, so `{haystack}` produced zero local_pairs and the
HS script failed with "Undefined symbol: haystack". Now a second pass
scans for bare identifiers in the locals object and resolves each
against a preceding `const NAME = VALUE;` in the test body.
Net test-count is unchanged (the affected regex tests still fail — now
with TIMEOUT in the regex engine rather than Undefined-symbol, so this
just moves them closer to real coverage).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1125,6 +1125,21 @@ def generate_eval_only_test(test, idx):
|
||||
lname = lm.group(1)
|
||||
lval = js_val_to_sx(lm.group(2).strip().rstrip(','))
|
||||
local_pairs.append((lname, lval))
|
||||
# Also accept ES6 shorthand `{foo}` (= `{foo: foo}`): for every
|
||||
# bare identifier in locals_str not already captured, look up
|
||||
# `const <name> = <value>;` earlier in the test body.
|
||||
taken = {n for n, _ in local_pairs}
|
||||
for sh in re.finditer(r'(?<![\w:])(\w+)(?![\w:])', locals_str):
|
||||
lname = sh.group(1)
|
||||
if lname in taken:
|
||||
continue
|
||||
const_match = re.search(
|
||||
r'const\s+' + re.escape(lname) + r'\s*=\s*(.+?);',
|
||||
body, re.DOTALL)
|
||||
if const_match:
|
||||
lval = js_val_to_sx(const_match.group(1).strip())
|
||||
local_pairs.append((lname, lval))
|
||||
taken.add(lname)
|
||||
# SX list of (symbol value) pairs for eval-hs-locals
|
||||
locals_sx = '(list ' + ' '.join(f'(list (quote {n}) {v})' for n, v in local_pairs) + ')' if local_pairs else '(list)'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user