Skip to content

Commit

Permalink
tests: add test cases for single quote f string in python
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 committed Aug 1, 2023
1 parent 571bcec commit a4f4ad1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lua/nvim-autopairs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ M.is_in_quotes = function (line, pos, quote_type)
result == false and
M.is_quote(char) and
(not quote_type or char == quote_type) and
--a single quote with a word before is not count unless in python
--(e.g. f'string {with_brackets}')
not (char == "'" and prev_char:match("%w") and
vim.bo.filetype ~= "python")
--a single quote with a word before is not count unless it is a
-- prefixed string in python (e.g. f'string {with_brackets}')
not (char == "'" and prev_char:match(vim.bo.filetype == "python"
and "[AC-EG-QS-TV-Zac-eg-qs-tv-z0-9]" or "%w"))
then
last_char = quote_type or char
result = true
Expand Down
35 changes: 35 additions & 0 deletions tests/nvim-autopairs_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,41 @@ local data = {
before = [[aa| 'aa]],
after = [[aa"|" 'aa]]
},
{
name = "81 add closing single quote for python prefixed string",
filetype = "python",
key = [[']],
before = [[print(f|)]],
after = [[print(f'|')]]
},
{
name = "82 add closing single quote for capital python prefixed string",
filetype = "python",
key = [[']],
before = [[print(B|)]],
after = [[print(B'|')]]
},
{
name = "83 don't add closing single quote for random prefix string",
filetype = "python",
key = [[']],
before = [[print(s|)]],
after = [[print(s'|)]]
},
{
name = "84 don't add closing single quote for other filetype prefixed string",
filetype = "lua",
key = [[']],
before = [[print(f|)]],
after = [[print(f'|)]]
},
{
name = "85 allow brackets in prefixed python single quote string",
filetype = "python",
key = [[{]],
before = [[print(f'|')]],
after = [[print(f'{|}')]]
},
}

local run_data = _G.Test_filter(data)
Expand Down

0 comments on commit a4f4ad1

Please sign in to comment.