test(natives): cover vendored syntax definitions in Rust

This commit is contained in:
arg3t
2026-06-26 06:18:46 -07:00
parent b10cea54d7
commit 17f91f04ec
3 changed files with 56 additions and 49 deletions
+55
View File
@@ -494,3 +494,58 @@ pub fn get_supported_languages() -> Vec<String> {
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: "<c>".to_string(),
keyword: "<k>".to_string(),
function: "<f>".to_string(),
variable: "<v>".to_string(),
string: "<s>".to_string(),
number: "<n>".to_string(),
r#type: "<t>".to_string(),
operator: "<o>".to_string(),
punctuation: "<p>".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 <nixpkgs> {} }:\nlet message = \"hello\"; in pkgs.writeText \"msg\" \
message # greeting\n"
.to_string(),
Some("nix".to_string()),
test_colors(),
);
assert!(out.contains("<k>let"));
assert!(out.contains("<s>hello"));
assert!(out.contains("<c># 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("<k>graph"));
assert!(out.contains("<s>Start"));
assert!(out.contains("<k>-->"));
assert!(out.contains("<c> note"));
}
}
+1 -1
View File
@@ -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
-48
View File
@@ -226,54 +226,6 @@ describe("pi-natives", () => {
expect(out).toContain("<n>1");
expect(out).toContain("<c> add");
});
it("highlights Nix via the vendored syntax", () => {
expect(getSupportedLanguages()).toContain("Nix");
expect(supportsLanguage("nix")).toBe(true);
const colors = {
comment: "<c>",
keyword: "<k>",
function: "<f>",
variable: "<v>",
string: "<s>",
number: "<n>",
type: "<t>",
operator: "<o>",
punctuation: "<p>",
};
const out = highlightCode(
'{ pkgs ? import <nixpkgs> {} }:\nlet message = "hello"; in pkgs.writeText "msg" message # greeting\n',
"nix",
colors,
);
expect(out).toContain("<k>let");
expect(out).toContain("<s>hello");
expect(out).toContain("<c># 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: "<c>",
keyword: "<k>",
function: "<f>",
variable: "<v>",
string: "<s>",
number: "<n>",
type: "<t>",
operator: "<o>",
punctuation: "<p>",
};
const out = highlightCode('graph TD\n A["Start"] --> B\n %% note\n', "mermaid", colors);
expect(out).toContain("<k>graph");
expect(out).toContain("<s>Start");
expect(out).toContain("<k>-->");
expect(out).toContain("<c> note");
});
});
describe("keys", () => {