aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpartizan <serg.partizan@gmail.com>2021-08-30 21:18:04 +0300
committerStephan Seitz <stephan.seitz@fau.de>2021-09-17 21:06:36 +0200
commitcfccc352c9a30c6e6c26afb3840cc8818baac1e1 (patch)
tree2b1a375e40ea03d578fb11961e8d79d40a0bdc3a
parentAdd python to .editorconfig (diff)
downloadnvim-treesitter-cfccc352c9a30c6e6c26afb3840cc8818baac1e1.tar
nvim-treesitter-cfccc352c9a30c6e6c26afb3840cc8818baac1e1.tar.gz
nvim-treesitter-cfccc352c9a30c6e6c26afb3840cc8818baac1e1.tar.bz2
nvim-treesitter-cfccc352c9a30c6e6c26afb3840cc8818baac1e1.tar.lz
nvim-treesitter-cfccc352c9a30c6e6c26afb3840cc8818baac1e1.tar.xz
nvim-treesitter-cfccc352c9a30c6e6c26afb3840cc8818baac1e1.tar.zst
nvim-treesitter-cfccc352c9a30c6e6c26afb3840cc8818baac1e1.zip
test: Add tests for is_in_node_range (#1756)
* fix: is_in_node_range now includes end line and col This fixes no indents at the end of python files Refs #1136 * update scala highlights (#1760) * add type highlights * add call expression highlights * add function definition highlights * add expression highlights * add literals highlights * add operator highlights * add punctuation highlights * add comment highlights Co-authored-by: Stevan Milic <stevan.milic@tradecore.com> * test: Add unit tests * Revert "fix: is_in_node_range now includes end line and col" This reverts commit 5a721fef5620eb2fae6d9cebe09bf7b230f2606f. * refactor test * apply stylua * fix luacheck * update `describe` text * smallfix Co-authored-by: Stevan Milic <stevan.milic@yahoo.com> Co-authored-by: Stevan Milic <stevan.milic@tradecore.com>
-rwxr-xr-xscripts/run_tests.sh8
-rw-r--r--tests/unit/ts_utils_spec.lua41
2 files changed, 46 insertions, 3 deletions
diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh
index c7800d50f..2447bd4c1 100755
--- a/scripts/run_tests.sh
+++ b/scripts/run_tests.sh
@@ -5,12 +5,14 @@ cd $HERE/..
run() {
nvim --headless --noplugin -u scripts/minimal_init.lua \
- -c "PlenaryBustedDirectory tests/indent/ { minimal_init = './scripts/minimal_init.lua' }"
+ -c "PlenaryBustedDirectory $1 { minimal_init = './scripts/minimal_init.lua' }"
}
if [[ $1 = '--summary' ]]; then
# really simple results summary by filtering plenary busted output
- run 2> /dev/null | grep -E '^\S*(Success|Fail(ed)?|Errors?)'
+ run tests/indent/ 2> /dev/null | grep -E '^\S*(Success|Fail(ed)?|Errors?)'
+elif [[ $1 = '--unit' ]]; then
+ run tests/unit
else
- run
+ run tests/indent/
fi
diff --git a/tests/unit/ts_utils_spec.lua b/tests/unit/ts_utils_spec.lua
new file mode 100644
index 000000000..1825a3b68
--- /dev/null
+++ b/tests/unit/ts_utils_spec.lua
@@ -0,0 +1,41 @@
+local tsutils = require "nvim-treesitter.ts_utils"
+
+describe("is_in_node_range", function()
+ local function test_is_in_node_range(line, col)
+ local node = {
+ range = function()
+ return unpack { 0, 3, 2, 5 }
+ end,
+ }
+ return tsutils.is_in_node_range(node, line, col)
+ end
+
+ it("returns false before node start", function()
+ assert.is_false(test_is_in_node_range(0, 0))
+ assert.is_false(test_is_in_node_range(0, 1))
+ assert.is_false(test_is_in_node_range(0, 2))
+ end)
+
+ it("returns true at node start", function()
+ assert.is_true(test_is_in_node_range(0, 3))
+ end)
+
+ it("returns true on first line of the node", function()
+ assert.is_true(test_is_in_node_range(0, 4))
+ end)
+
+ it("returns true between node lines", function()
+ assert.is_true(test_is_in_node_range(1, 2))
+ assert.is_true(test_is_in_node_range(1, 20))
+ end)
+
+ it("returns false on node end", function()
+ -- Ranges are end-exclusive
+ assert.is_false(test_is_in_node_range(2, 5))
+ end)
+
+ it("returns false after node end", function()
+ assert.is_false(test_is_in_node_range(2, 6))
+ assert.is_false(test_is_in_node_range(3, 0))
+ end)
+end)