From b55f87e96dc98728cf5c0e304c24ca7fc75ab82b Mon Sep 17 00:00:00 2001 From: Levi Neuwirth Date: Tue, 14 Jul 2026 17:55:27 +0100 Subject: [PATCH] =?UTF-8?q?test(highlight):=20PR=20#118=20round=202=20?= =?UTF-8?q?=E2=80=94=20assert=20shadowed=20console=20keeps=20@variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Non-blocking review nit: the shadowing test only proved the `.builtin` captures disappeared. Also assert both `console` occurrences retain an ordinary `@variable` capture, so dropping the locals-predicate pattern loses only the `.builtin` refinement, not all styling for the token. Test-only. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01YJ9FQ832QwftJXCD9LeFan --- src/syntax.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/syntax.rs b/src/syntax.rs index 6b77371..33577e0 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -1384,6 +1384,22 @@ mod tests { builtin.is_empty(), "a locally-shadowed `console` must not get a *.builtin capture; got {builtin:?}" ); + // ...and dropping the builtin pattern must not strip *all* styling: + // each `console` occurrence still keeps its ordinary `@variable` + // capture (the fallback), so the loss is only the `.builtin` refine. + let src = "const console = 5;\nconsole;\n"; + for (pos, _) in src.match_indices("console") { + let (start, end) = (pos as u32, (pos + "console".len()) as u32); + let caps: Vec<&str> = spans + .iter() + .filter(|s| s.start_byte == start && s.end_byte == end) + .map(|s| names[s.capture_index as usize]) + .collect(); + assert!( + caps.iter().any(|n| n.starts_with("variable")), + "`console` at byte {pos} keeps a variable capture; got {caps:?}" + ); + } } #[test]