mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	test: more tests for nvim_eval_statusline "fillchar" (#27502)
This commit is contained in:
		@@ -3655,6 +3655,7 @@ describe('API', function()
 | 
			
		||||
      eq({ 2, 2, buf, mark[4] }, mark)
 | 
			
		||||
    end)
 | 
			
		||||
  end)
 | 
			
		||||
 | 
			
		||||
  describe('nvim_eval_statusline', function()
 | 
			
		||||
    it('works', function()
 | 
			
		||||
      eq({
 | 
			
		||||
@@ -3662,57 +3663,89 @@ describe('API', function()
 | 
			
		||||
        width = 31,
 | 
			
		||||
      }, api.nvim_eval_statusline('%%StatusLineString%#WarningMsg#WithHighlights', {}))
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it("doesn't exceed maxwidth", function()
 | 
			
		||||
      eq({
 | 
			
		||||
        str = 'Should be trun>',
 | 
			
		||||
        width = 15,
 | 
			
		||||
      }, api.nvim_eval_statusline('Should be truncated%<', { maxwidth = 15 }))
 | 
			
		||||
    end)
 | 
			
		||||
    it('supports ASCII fillchar', function()
 | 
			
		||||
 | 
			
		||||
    it('has correct default fillchar', function()
 | 
			
		||||
      local oldwin = api.nvim_get_current_win()
 | 
			
		||||
      command('set fillchars=stl:#,stlnc:$,wbr:%')
 | 
			
		||||
      command('new')
 | 
			
		||||
      eq({ str = 'a###b', width = 5 }, api.nvim_eval_statusline('a%=b', { maxwidth = 5 }))
 | 
			
		||||
      eq(
 | 
			
		||||
        { str = 'a~~~b', width = 5 },
 | 
			
		||||
        api.nvim_eval_statusline('a%=b', { fillchar = '~', maxwidth = 5 })
 | 
			
		||||
      )
 | 
			
		||||
    end)
 | 
			
		||||
    it('supports single-width multibyte fillchar', function()
 | 
			
		||||
      eq(
 | 
			
		||||
        { str = 'a━━━b', width = 5 },
 | 
			
		||||
        api.nvim_eval_statusline('a%=b', { fillchar = '━', maxwidth = 5 })
 | 
			
		||||
      )
 | 
			
		||||
    end)
 | 
			
		||||
    it('treats double-width fillchar as single-width', function()
 | 
			
		||||
      eq(
 | 
			
		||||
        { str = 'a哦哦哦b', width = 5 },
 | 
			
		||||
        api.nvim_eval_statusline('a%=b', { fillchar = '哦', maxwidth = 5 })
 | 
			
		||||
      )
 | 
			
		||||
    end)
 | 
			
		||||
    it('treats control character fillchar as single-width', function()
 | 
			
		||||
      eq(
 | 
			
		||||
        { str = 'a\031\031\031b', width = 5 },
 | 
			
		||||
        api.nvim_eval_statusline('a%=b', { fillchar = '\031', maxwidth = 5 })
 | 
			
		||||
        { str = 'a$$$b', width = 5 },
 | 
			
		||||
        api.nvim_eval_statusline('a%=b', { winid = oldwin, maxwidth = 5 })
 | 
			
		||||
      )
 | 
			
		||||
      eq(
 | 
			
		||||
        { str = 'a%%%b', width = 5 },
 | 
			
		||||
        api.nvim_eval_statusline('a%=b', { use_winbar = true, maxwidth = 5 })
 | 
			
		||||
      )
 | 
			
		||||
      eq(
 | 
			
		||||
        { str = 'a   b', width = 5 },
 | 
			
		||||
        api.nvim_eval_statusline('a%=b', { use_tabline = true, maxwidth = 5 })
 | 
			
		||||
      )
 | 
			
		||||
      eq(
 | 
			
		||||
        { str = 'a   b', width = 5 },
 | 
			
		||||
        api.nvim_eval_statusline('a%=b', { use_statuscol_lnum = 1, maxwidth = 5 })
 | 
			
		||||
      )
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    for fc, desc in pairs({
 | 
			
		||||
      ['~'] = 'supports ASCII fillchar',
 | 
			
		||||
      ['━'] = 'supports single-width multibyte fillchar',
 | 
			
		||||
      ['c̳'] = 'supports single-width fillchar with composing',
 | 
			
		||||
      ['哦'] = 'treats double-width fillchar as single-width',
 | 
			
		||||
      ['\031'] = 'treats control character fillchar as single-width',
 | 
			
		||||
    }) do
 | 
			
		||||
      it(desc, function()
 | 
			
		||||
        eq(
 | 
			
		||||
          { str = 'a' .. fc:rep(3) .. 'b', width = 5 },
 | 
			
		||||
          api.nvim_eval_statusline('a%=b', { fillchar = fc, maxwidth = 5 })
 | 
			
		||||
        )
 | 
			
		||||
        eq(
 | 
			
		||||
          { str = 'a' .. fc:rep(3) .. 'b', width = 5 },
 | 
			
		||||
          api.nvim_eval_statusline('a%=b', { fillchar = fc, use_winbar = true, maxwidth = 5 })
 | 
			
		||||
        )
 | 
			
		||||
        eq(
 | 
			
		||||
          { str = 'a' .. fc:rep(3) .. 'b', width = 5 },
 | 
			
		||||
          api.nvim_eval_statusline('a%=b', { fillchar = fc, use_tabline = true, maxwidth = 5 })
 | 
			
		||||
        )
 | 
			
		||||
        eq(
 | 
			
		||||
          { str = 'a' .. fc:rep(3) .. 'b', width = 5 },
 | 
			
		||||
          api.nvim_eval_statusline('a%=b', { fillchar = fc, use_statuscol_lnum = 1, maxwidth = 5 })
 | 
			
		||||
        )
 | 
			
		||||
      end)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it('rejects multiple-character fillchar', function()
 | 
			
		||||
      eq(
 | 
			
		||||
        "Invalid 'fillchar': expected single character",
 | 
			
		||||
        pcall_err(api.nvim_eval_statusline, '', { fillchar = 'aa' })
 | 
			
		||||
      )
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it('rejects empty string fillchar', function()
 | 
			
		||||
      eq(
 | 
			
		||||
        "Invalid 'fillchar': expected single character",
 | 
			
		||||
        pcall_err(api.nvim_eval_statusline, '', { fillchar = '' })
 | 
			
		||||
      )
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it('rejects non-string fillchar', function()
 | 
			
		||||
      eq(
 | 
			
		||||
        "Invalid 'fillchar': expected String, got Integer",
 | 
			
		||||
        pcall_err(api.nvim_eval_statusline, '', { fillchar = 1 })
 | 
			
		||||
      )
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it('rejects invalid string', function()
 | 
			
		||||
      eq('E539: Illegal character <}>', pcall_err(api.nvim_eval_statusline, '%{%}', {}))
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it('supports various items', function()
 | 
			
		||||
      eq({ str = '0', width = 1 }, api.nvim_eval_statusline('%l', { maxwidth = 5 }))
 | 
			
		||||
      command('set readonly')
 | 
			
		||||
@@ -3727,6 +3760,7 @@ describe('API', function()
 | 
			
		||||
      screen:expect({ any = '123456' })
 | 
			
		||||
      eq({ str = '<3456', width = 5 }, api.nvim_eval_statusline('%S', { maxwidth = 5 }))
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    describe('highlight parsing', function()
 | 
			
		||||
      it('works', function()
 | 
			
		||||
        eq(
 | 
			
		||||
@@ -3744,6 +3778,7 @@ describe('API', function()
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
      end)
 | 
			
		||||
 | 
			
		||||
      it('works with no highlight', function()
 | 
			
		||||
        eq({
 | 
			
		||||
          str = 'TextWithNoHighlight',
 | 
			
		||||
@@ -3753,9 +3788,9 @@ describe('API', function()
 | 
			
		||||
          },
 | 
			
		||||
        }, api.nvim_eval_statusline('TextWithNoHighlight', { highlights = true }))
 | 
			
		||||
      end)
 | 
			
		||||
 | 
			
		||||
      it('works with inactive statusline', function()
 | 
			
		||||
        command('split')
 | 
			
		||||
 | 
			
		||||
        eq(
 | 
			
		||||
          {
 | 
			
		||||
            str = 'TextWithNoHighlightTextWithWarningHighlight',
 | 
			
		||||
@@ -3771,6 +3806,7 @@ describe('API', function()
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
      end)
 | 
			
		||||
 | 
			
		||||
      it('works with tabline', function()
 | 
			
		||||
        eq(
 | 
			
		||||
          {
 | 
			
		||||
@@ -3787,6 +3823,7 @@ describe('API', function()
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
      end)
 | 
			
		||||
 | 
			
		||||
      it('works with winbar', function()
 | 
			
		||||
        eq(
 | 
			
		||||
          {
 | 
			
		||||
@@ -3803,6 +3840,7 @@ describe('API', function()
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
      end)
 | 
			
		||||
 | 
			
		||||
      it('works with statuscolumn', function()
 | 
			
		||||
        exec([[
 | 
			
		||||
          let &stc='%C%s%=%l '
 | 
			
		||||
@@ -3842,6 +3880,7 @@ describe('API', function()
 | 
			
		||||
          api.nvim_eval_statusline('%l%#ErrorMsg# ', { use_statuscol_lnum = 3, highlights = true })
 | 
			
		||||
        )
 | 
			
		||||
      end)
 | 
			
		||||
 | 
			
		||||
      it('no memory leak with click functions', function()
 | 
			
		||||
        api.nvim_eval_statusline('%@ClickFunc@StatusLineStringWithClickFunc%T', {})
 | 
			
		||||
        eq({
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user