From e9307df32f8fbbe483f890a768422e0fb0044c7a Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Tue, 28 May 2024 18:21:27 +0300 Subject: [PATCH] test: update fixtures and tests --- tests/fixtures/narrative/05 Capture Groups.js | 13 +++++++++++++ tests/fixtures/narrative/12 Regex Sudoku.js | 1 + tests/helpers/util.lua | 7 ++++--- tests/regexplainer/nvim-regexplainer_spec.lua | 12 ++++-------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/fixtures/narrative/05 Capture Groups.js b/tests/fixtures/narrative/05 Capture Groups.js index 7ca9a9b..1e37fb4 100644 --- a/tests/fixtures/narrative/05 Capture Groups.js +++ b/tests/fixtures/narrative/05 Capture Groups.js @@ -5,6 +5,19 @@ */ /@(hello)/; +/** + * capture group 1: + * **0-9** + */ +/(\d)/; + +/** + * **0-9** (_>= 0x_) + * capture group 1: + * **0-9** + */ +/\d*(\d)/; + /** * `@` * capture group 1: diff --git a/tests/fixtures/narrative/12 Regex Sudoku.js b/tests/fixtures/narrative/12 Regex Sudoku.js index c7bd365..f3b6e6e 100644 --- a/tests/fixtures/narrative/12 Regex Sudoku.js +++ b/tests/fixtures/narrative/12 Regex Sudoku.js @@ -125,6 +125,7 @@ * **WS** (_>= 1x_) */ /\d*\s+/; + /** * **0-9** (_>= 0x_) * **NOT followed by**: diff --git a/tests/helpers/util.lua b/tests/helpers/util.lua index 01c7bf4..d2279aa 100644 --- a/tests/helpers/util.lua +++ b/tests/helpers/util.lua @@ -4,6 +4,7 @@ local parsers = require "nvim-treesitter.parsers" local get_parser = vim.treesitter.get_parser local get_node_text = vim.treesitter.get_node_text +local bd = vim.api.nvim_buf_delete local query = vim.treesitter.query.get('javascript', 'regexplainer_test') if not query then error('could not get query') end @@ -52,7 +53,7 @@ local function get_cases() next.expected = get_expected_from_jsdoc(jsdoc_text) elseif name == 'test.pattern' then next.pattern = get_node_text(node, 0) - next.row = node:start() + next.row = node:start() + 1 end if next.row and next.expected and next.pattern then table.insert(results, next) @@ -90,7 +91,7 @@ local function show_and_get_regexplainer_buffer(bufnr) local buffer repeat get_parser(0):parse() - vim.uv.sleep(10) + vim.uv.sleep(1) local row, col = unpack(vim.api.nvim_win_get_cursor(0)); vim.api.nvim_win_set_cursor(0, {row, col + 1}) local cursor_node = vim.treesitter.get_node() @@ -141,7 +142,7 @@ function M.assert_string(pattern, expected, message) local rebufnr = show_and_get_regexplainer_buffer(newbufnr) local text = get_buffer_text(rebufnr) -- Cleanup any remaining buffers - vim.api.nvim_buf_delete(newbufnr, { force = true }) + bd(newbufnr, { force = true }) regexplainer.hide() return assert.are.same(expected, text, message) end diff --git a/tests/regexplainer/nvim-regexplainer_spec.lua b/tests/regexplainer/nvim-regexplainer_spec.lua index e890af8..eb9d0b7 100644 --- a/tests/regexplainer/nvim-regexplainer_spec.lua +++ b/tests/regexplainer/nvim-regexplainer_spec.lua @@ -3,10 +3,6 @@ local Utils = require 'tests.helpers.util' local regexplainer = require 'regexplainer' local scan = require 'plenary.scandir' -local function setup_narrative() - regexplainer.setup() -end - local function file_filter(filename) local filter = vim.env.REGEXPLAINER_TEST_FILTER or nil if filter then @@ -17,7 +13,7 @@ local function file_filter(filename) end local function row_filter(row) - -- return row == 36 + -- return row <= 12 return true end @@ -42,7 +38,7 @@ end describe("Regexplainer", function() describe('Yank', function() it('yanks into a given register', function() - setup_narrative() + regexplainer.setup() local bufnr = vim.api.nvim_create_buf(true, true) local expected = "Either `hello` or `world`\n" @@ -69,10 +65,10 @@ describe("Regexplainer", function() print(require'ansicolors'('%{yellow}Skipping %{reset}') .. category) else describe(category, function() - before_each(setup_narrative) + before_each(regexplainer.setup) for result in Utils.iter_regexes_with_descriptions(file) do if (row_filter(result.row)) then - it(result.pattern, function() + it('/'..result.pattern..'/', function() Utils.assert_string(result.pattern, result.expected, file .. ':' .. result.row) end) end