From 17f91f04ecf843de97377802d744dc1afac000e6 Mon Sep 17 00:00:00 2001 From: arg3t Date: Fri, 26 Jun 2026 06:18:46 -0700 Subject: [PATCH] test(natives): cover vendored syntax definitions in Rust --- crates/pi-natives/src/highlight.rs | 55 ++++++++++++++++++++++++++++ packages/natives/CHANGELOG.md | 2 +- packages/natives/test/native.test.ts | 48 ------------------------ 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/crates/pi-natives/src/highlight.rs b/crates/pi-natives/src/highlight.rs index 4de80ce18..1c46d7955 100644 --- a/crates/pi-natives/src/highlight.rs +++ b/crates/pi-natives/src/highlight.rs @@ -494,3 +494,58 @@ pub fn get_supported_languages() -> Vec { let ss = get_syntax_set(); ss.syntaxes().iter().map(|s| s.name.clone()).collect() } + +#[cfg(test)] +mod tests { + use super::*; + + fn test_colors() -> HighlightColors { + HighlightColors { + comment: "".to_string(), + keyword: "".to_string(), + function: "".to_string(), + variable: "".to_string(), + string: "".to_string(), + number: "".to_string(), + r#type: "".to_string(), + operator: "".to_string(), + punctuation: "

".to_string(), + inserted: None, + deleted: None, + } + } + + #[test] + fn highlights_nix_vendored_syntax() { + assert!(get_supported_languages().contains(&"Nix".to_string())); + assert!(supports_language("nix".to_string())); + + let out = highlight_code( + "{ pkgs ? import {} }:\nlet message = \"hello\"; in pkgs.writeText \"msg\" \ + message # greeting\n" + .to_string(), + Some("nix".to_string()), + test_colors(), + ); + assert!(out.contains("let")); + assert!(out.contains("hello")); + assert!(out.contains("# greeting")); + } + + #[test] + fn highlights_mermaid_vendored_syntax() { + assert!(get_supported_languages().contains(&"Mermaid".to_string())); + assert!(supports_language("mermaid".to_string())); + assert!(supports_language("mmd".to_string())); + + let out = highlight_code( + "graph TD\n A[\"Start\"] --> B\n %% note\n".to_string(), + Some("mermaid".to_string()), + test_colors(), + ); + assert!(out.contains("graph")); + assert!(out.contains("Start")); + assert!(out.contains("-->")); + assert!(out.contains(" note")); + } +} diff --git a/packages/natives/CHANGELOG.md b/packages/natives/CHANGELOG.md index aa4a513a3..a87f462c2 100644 --- a/packages/natives/CHANGELOG.md +++ b/packages/natives/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added -- Added Mermaid syntax highlighting support to `highlightCode`/`supportsLanguage` via a vendored `Mermaid.sublime-syntax` and `mermaid`/`mmd` aliases. +- Added Nix and Mermaid syntax highlighting support to `highlightCode`/`supportsLanguage` via vendored `Nix.sublime-syntax` and `Mermaid.sublime-syntax` definitions plus `nix`, `mermaid`, and `mmd` aliases. - Added in-process [uutils](https://github.com/uutils/coreutils)-backed shell builtins to the embedded brush `Shell`: `cat`, `head`, `tail`, `wc`, `sort`, `uniq`, `ls`, `find`, `grep`, `mkdir`, `rm`, and `mv`. These vendored + patched utilities run inside the shell process (no `fork`/`exec`), resolve path operands against the shell working directory, route stdio through the command's (possibly piped/redirected) file descriptors, read the shell's exported environment, and honor abort/timeout cancellation (a blocked `stdin` read unwinds cleanly). `grep` is built on the ripgrep `grep-*` crates and `find` on `uutils/findutils`; the rest are pinned to `uutils/coreutils` 0.8.0 (matching the bundled `uucore`). Registration is gated: set `PI_DISABLE_UUTILS_BUILTINS` to fall back to the system binaries for the whole set, or `PI_DISABLE_UUTILS_DESTRUCTIVE` / `PI_DISABLE_RM_BUILTIN` / `PI_DISABLE_MV_BUILTIN` to disable only the destructive `rm`/`mv` shadows. ## [16.1.17] - 2026-06-24 diff --git a/packages/natives/test/native.test.ts b/packages/natives/test/native.test.ts index db483b9d7..6c9562793 100644 --- a/packages/natives/test/native.test.ts +++ b/packages/natives/test/native.test.ts @@ -226,54 +226,6 @@ describe("pi-natives", () => { expect(out).toContain("1"); expect(out).toContain(" add"); }); - - it("highlights Nix via the vendored syntax", () => { - expect(getSupportedLanguages()).toContain("Nix"); - expect(supportsLanguage("nix")).toBe(true); - - const colors = { - comment: "", - keyword: "", - function: "", - variable: "", - string: "", - number: "", - type: "", - operator: "", - punctuation: "

", - }; - const out = highlightCode( - '{ pkgs ? import {} }:\nlet message = "hello"; in pkgs.writeText "msg" message # greeting\n', - "nix", - colors, - ); - expect(out).toContain("let"); - expect(out).toContain("hello"); - expect(out).toContain("# greeting"); - }); - - it("highlights Mermaid via the vendored syntax", () => { - expect(getSupportedLanguages()).toContain("Mermaid"); - expect(supportsLanguage("mermaid")).toBe(true); - expect(supportsLanguage("mmd")).toBe(true); - - const colors = { - comment: "", - keyword: "", - function: "", - variable: "", - string: "", - number: "", - type: "", - operator: "", - punctuation: "

", - }; - const out = highlightCode('graph TD\n A["Start"] --> B\n %% note\n', "mermaid", colors); - expect(out).toContain("graph"); - expect(out).toContain("Start"); - expect(out).toContain("-->"); - expect(out).toContain(" note"); - }); }); describe("keys", () => {