aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/substitute_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:18 +0100
committerJustin M. Keyes <justinkz@gmail.com>2024-01-03 02:09:29 +0100
commit04f2f864e270e772c6326cefdf24947f0130e492 (patch)
tree46f83f909b888a66c741032ab955afc6eab84292 /test/functional/legacy/substitute_spec.lua
parent59d117ec99b6037cb9fad5bbfb6d0b18f5012927 (diff)
downloadrneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.gz
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.tar.bz2
rneovim-04f2f864e270e772c6326cefdf24947f0130e492.zip
refactor: format test/*
Diffstat (limited to 'test/functional/legacy/substitute_spec.lua')
-rw-r--r--test/functional/legacy/substitute_spec.lua133
1 files changed, 89 insertions, 44 deletions
diff --git a/test/functional/legacy/substitute_spec.lua b/test/functional/legacy/substitute_spec.lua
index bba3df82d8..b462c10202 100644
--- a/test/functional/legacy/substitute_spec.lua
+++ b/test/functional/legacy/substitute_spec.lua
@@ -20,9 +20,14 @@ describe('substitute()', function()
local function test_1_and_2()
eq('AA', eval("substitute('A', 'A', '&&', '')"))
eq('&', eval([[substitute('B', 'B', '\&', '')]]))
- eq('C123456789987654321', eval([[substitute('C123456789', ]] ..
- [['C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] ..
- [['\0\9\8\7\6\5\4\3\2\1', '')]]))
+ eq(
+ 'C123456789987654321',
+ eval(
+ [[substitute('C123456789', ]]
+ .. [['C\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]]
+ .. [['\0\9\8\7\6\5\4\3\2\1', '')]]
+ )
+ )
eq('d', eval("substitute('D', 'D', 'd', '')"))
eq('~', eval("substitute('E', 'E', '~', '')"))
eq('~', eval([[substitute('F', 'F', '\~', '')]]))
@@ -61,10 +66,9 @@ describe('substitute()', function()
feed_command('set magic&')
eq('a\\a', eval([[substitute('aAa', 'A', '\="\\"', '')]]))
eq('b\\\\b', eval([[substitute('bBb', 'B', '\="\\\\"', '')]]))
- eq('c\rc', eval([[substitute('cCc', 'C', '\="]]..'\r'..[["', '')]]))
- eq('d\\\rd', eval([[substitute('dDd', 'D', '\="\\]]..'\r'..[["', '')]]))
- eq('e\\\\\re',
- eval([[substitute('eEe', 'E', '\="\\\\]]..'\r'..[["', '')]]))
+ eq('c\rc', eval([[substitute('cCc', 'C', '\="]] .. '\r' .. [["', '')]]))
+ eq('d\\\rd', eval([[substitute('dDd', 'D', '\="\\]] .. '\r' .. [["', '')]]))
+ eq('e\\\\\re', eval([[substitute('eEe', 'E', '\="\\\\]] .. '\r' .. [["', '')]]))
eq('f\\rf', eval([[substitute('fFf', 'F', '\="\\r"', '')]]))
eq('j\\nj', eval([[substitute('jJj', 'J', '\="\\n"', '')]]))
eq('k\rk', eval([[substitute('kKk', 'K', '\="\r"', '')]]))
@@ -73,39 +77,81 @@ describe('substitute()', function()
it('with submatch() (TEST_4)', function()
feed_command('set magic&')
- eq('a\\a', eval([[substitute('aAa', 'A', ]] ..
- [['\=substitute(submatch(0), ".", "\\", "")', '')]]))
- eq('b\\b', eval([[substitute('bBb', 'B', ]] ..
- [['\=substitute(submatch(0), ".", "\\\\", "")', '')]]))
- eq('c\rc', eval([[substitute('cCc', 'C', ]] ..
- [['\=substitute(submatch(0), ".", "]]..'\r'..[[", "")', '')]]))
- eq('d\rd', eval([[substitute('dDd', 'D', ]] ..
- [['\=substitute(submatch(0), ".", "\\]]..'\r'..[[", "")', '')]]))
- eq('e\\\re', eval([[substitute('eEe', 'E', ]] ..
- [['\=substitute(submatch(0), ".", "\\\\]]..'\r'..[[", "")', '')]]))
- eq('f\rf', eval([[substitute('fFf', 'F', ]] ..
- [['\=substitute(submatch(0), ".", "\\r", "")', '')]]))
- eq('j\nj', eval([[substitute('jJj', 'J', ]] ..
- [['\=substitute(submatch(0), ".", "\\n", "")', '')]]))
- eq('k\rk', eval([[substitute('kKk', 'K', ]] ..
- [['\=substitute(submatch(0), ".", "\r", "")', '')]]))
- eq('l\nl', eval([[substitute('lLl', 'L', ]] ..
- [['\=substitute(submatch(0), ".", "\n", "")', '')]]))
+ eq(
+ 'a\\a',
+ eval([[substitute('aAa', 'A', ]] .. [['\=substitute(submatch(0), ".", "\\", "")', '')]])
+ )
+ eq(
+ 'b\\b',
+ eval([[substitute('bBb', 'B', ]] .. [['\=substitute(submatch(0), ".", "\\\\", "")', '')]])
+ )
+ eq(
+ 'c\rc',
+ eval(
+ [[substitute('cCc', 'C', ]]
+ .. [['\=substitute(submatch(0), ".", "]]
+ .. '\r'
+ .. [[", "")', '')]]
+ )
+ )
+ eq(
+ 'd\rd',
+ eval(
+ [[substitute('dDd', 'D', ]]
+ .. [['\=substitute(submatch(0), ".", "\\]]
+ .. '\r'
+ .. [[", "")', '')]]
+ )
+ )
+ eq(
+ 'e\\\re',
+ eval(
+ [[substitute('eEe', 'E', ]]
+ .. [['\=substitute(submatch(0), ".", "\\\\]]
+ .. '\r'
+ .. [[", "")', '')]]
+ )
+ )
+ eq(
+ 'f\rf',
+ eval([[substitute('fFf', 'F', ]] .. [['\=substitute(submatch(0), ".", "\\r", "")', '')]])
+ )
+ eq(
+ 'j\nj',
+ eval([[substitute('jJj', 'J', ]] .. [['\=substitute(submatch(0), ".", "\\n", "")', '')]])
+ )
+ eq(
+ 'k\rk',
+ eval([[substitute('kKk', 'K', ]] .. [['\=substitute(submatch(0), ".", "\r", "")', '')]])
+ )
+ eq(
+ 'l\nl',
+ eval([[substitute('lLl', 'L', ]] .. [['\=substitute(submatch(0), ".", "\n", "")', '')]])
+ )
end)
it('with submatch() (TEST_5)', function()
feed_command('set magic&')
- eq('A123456789987654321', eval([[substitute('A123456789', ]] ..
- [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] ..
- [['\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . ]] ..
- [[submatch(6) . submatch(5) . submatch(4) . submatch(3) . ]] ..
- [[submatch(2) . submatch(1)', '')]]))
- eq("[['A123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], " ..
- "['2'], ['1']]", eval([[substitute('A123456789', ]] ..
- [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]] ..
- [['\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), ]] ..
- [[submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), ]] ..
- [[submatch(3, 1), submatch(2, 1), submatch(1, 1)])', '')]]))
+ eq(
+ 'A123456789987654321',
+ eval(
+ [[substitute('A123456789', ]]
+ .. [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]]
+ .. [['\=submatch(0) . submatch(9) . submatch(8) . submatch(7) . ]]
+ .. [[submatch(6) . submatch(5) . submatch(4) . submatch(3) . ]]
+ .. [[submatch(2) . submatch(1)', '')]]
+ )
+ )
+ eq(
+ "[['A123456789'], ['9'], ['8'], ['7'], ['6'], ['5'], ['4'], ['3'], " .. "['2'], ['1']]",
+ eval(
+ [[substitute('A123456789', ]]
+ .. [['A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', ]]
+ .. [['\=string([submatch(0, 1), submatch(9, 1), submatch(8, 1), ]]
+ .. [[submatch(7, 1), submatch(6, 1), submatch(5, 1), submatch(4, 1), ]]
+ .. [[submatch(3, 1), submatch(2, 1), submatch(1, 1)])', '')]]
+ )
+ )
end)
-- TEST_6 was about the 'cpoptions' flag / which was removed in pull request
@@ -115,8 +161,7 @@ describe('substitute()', function()
feed_command('set magic&')
eq('A\rA', eval("substitute('A\rA', 'A.', '\\=submatch(0)', '')"))
eq('B\nB', eval([[substitute("B\nB", 'B.', '\=submatch(0)', '')]]))
- eq("['B\n']B",
- eval([[substitute("B\nB", 'B.', '\=string(submatch(0, 1))', '')]]))
+ eq("['B\n']B", eval([[substitute("B\nB", 'B.', '\=string(submatch(0, 1))', '')]]))
eq('-abab', eval([[substitute('-bb', '\zeb', 'a', 'g')]]))
eq('c-cbcbc', eval([[substitute('-bb', '\ze', 'c', 'g')]]))
end)
@@ -145,9 +190,9 @@ describe(':substitute', function()
feed_command('set magic&')
feed_command([[1s/\(^\|,\)\ze\(,\|X\)/\1N/g]])
feed_command([[2s/\(^\|,\)\ze\(,\|Y\)/\1N/gc]])
- feed('a') -- For the dialog of the previous :s command.
+ feed('a') -- For the dialog of the previous :s command.
feed_command([[3s/\(^\|,\)\ze\(,\|Z\)/\1N/gc]])
- feed('yy') -- For the dialog of the previous :s command.
+ feed('yy') -- For the dialog of the previous :s command.
expect([[
N,,NX
N,,NY
@@ -158,16 +203,16 @@ describe(':substitute', function()
insert('xxx')
feed_command('set magic&')
feed_command('s/x/X/gc')
- feed('yyq') -- For the dialog of the previous :s command.
+ feed('yyq') -- For the dialog of the previous :s command.
expect('XXx')
end)
it('first char is highlighted with confirmation dialog and empty match', function()
local screen = Screen.new(60, 8)
screen:set_default_attr_ids({
- [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
- [1] = {reverse = true}, -- IncSearch
- [2] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg
+ [0] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
+ [1] = { reverse = true }, -- IncSearch
+ [2] = { bold = true, foreground = Screen.colors.SeaGreen }, -- MoreMsg
})
screen:attach()
exec([[