implement very basic highlighting
This commit is contained in:
8
tests/config/tree-sitter/config.json
Normal file
8
tests/config/tree-sitter/config.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"parser-directories": [
|
||||
".."
|
||||
],
|
||||
"theme": {
|
||||
"keyword": "#cccccc"
|
||||
}
|
||||
}
|
4
tests/highlight/basic
Normal file
4
tests/highlight/basic
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i bash -p bash
|
||||
true
|
||||
echo "bash-string"
|
16
tests/highlight/basic.spec.html
Normal file
16
tests/highlight/basic.spec.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<body>
|
||||
|
||||
<table>
|
||||
<tbody><tr><td class="line-number">1</td><td class="line">#!/usr/bin/env nix-shell
|
||||
</td></tr>
|
||||
<tr><td class="line-number">2</td><td class="line"><span style="color: #cccccc">#!nix-shell -i bash -p bash</span>
|
||||
</td></tr>
|
||||
<tr><td class="line-number">3</td><td class="line">true
|
||||
</td></tr>
|
||||
<tr><td class="line-number">4</td><td class="line">echo "bash-string"
|
||||
</td></tr>
|
||||
</tbody></table>
|
||||
|
||||
|
||||
|
||||
</body>
|
22
tests/test_highlight
Executable file
22
tests/test_highlight
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
# `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>
|
||||
#
|
||||
# upon execution, performs this sequence:
|
||||
# 1. highlights the file at `highlight/<TEST_NAME>`.
|
||||
# 2. asserts the result's body against `hightlight/<TEST_NAME>.spec.html`
|
||||
|
||||
here=$(dirname $(realpath $0))
|
||||
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'
|
Reference in New Issue
Block a user