Skip to content

Commit

Permalink
test: update fixtures and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed May 28, 2024
1 parent c022c6b commit e9307df
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
13 changes: 13 additions & 0 deletions tests/fixtures/narrative/05 Capture Groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
*/
/@(hello)/;

/**
* capture group 1:
* **0-9**
*/
/(\d)/;

/**
* **0-9** (_>= 0x_)
* capture group 1:
* **0-9**
*/
/\d*(\d)/;

/**
* `@`
* capture group 1:
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/narrative/12 Regex Sudoku.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
* **WS** (_>= 1x_)
*/
/\d*\s+/;

/**
* **0-9** (_>= 0x_)
* **NOT followed by**:
Expand Down
7 changes: 4 additions & 3 deletions tests/helpers/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions tests/regexplainer/nvim-regexplainer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,7 +13,7 @@ local function file_filter(filename)
end

local function row_filter(row)
-- return row == 36
-- return row <= 12
return true
end

Expand All @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit e9307df

Please sign in to comment.