25 lines
904 B
Bash
Executable File
25 lines
904 B
Bash
Executable File
#!/bin/sh
|
|
|
|
set -eux
|
|
|
|
# `tree-sitter test` doesn't work to validate syntax highlighting for two reasons:
|
|
# - it identifies a file's language only by its filetype (not shebang/regex), but nix-shell has no filetype
|
|
# - it requires the language to support comments, but nix-shell doesn't have those
|
|
#
|
|
# hence this custom testing tool.
|
|
#
|
|
# usage: test_highlight <TEST_NAME>
|
|
#
|
|
# 1. highlights the file at `highlight/<TEST_NAME>`.
|
|
# 2. asserts the result's body against `hightlight_spec/<TEST_NAME>.html`
|
|
|
|
here=$(dirname $(realpath $0))
|
|
echo $here
|
|
input_file="$here/highlight/$1"
|
|
spec_file="$here/highlight/$1.spec.html"
|
|
|
|
# cd into this directory before highlighting because paths specified in the tree-sitter config are relative to PWD
|
|
cd "$here" && XDG_CONFIG_HOME="$here/config" tree-sitter highlight --scope "source.nix_shell" --html "$input_file" | \
|
|
htmlq 'body' | \
|
|
diff -u "$spec_file" '/dev/stdin'
|