diff src/testdir/test_signs.vim @ 16978:15bc5a64bd50 v8.1.1489

patch 8.1.1489: sign order wrong when priority was changed commit https://github.com/vim/vim/commit/64416127fc184b5544530afe818722679158f059 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 7 21:37:13 2019 +0200 patch 8.1.1489: sign order wrong when priority was changed Problem: Sign order wrong when priority was changed. Solution: Reorder signs when priority is changed. (Yegappan Lakshmanan, closes #4502)
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 Jun 2019 21:45:05 +0200
parents 1689b52cf297
children f38fcbf343ce
line wrap: on
line diff
--- a/src/testdir/test_signs.vim
+++ b/src/testdir/test_signs.vim
@@ -1183,6 +1183,301 @@ func Test_sign_priority()
 	      \ 'priority' : 10}],
 	      \ s[0].signs)
 
+  call sign_unplace('*')
+
+  " Three signs on different lines with changing priorities
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 11, 'priority' : 50})
+  call sign_place(2, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 12, 'priority' : 60})
+  call sign_place(3, '', 'sign3', 'Xsign',
+	      \ {'lnum' : 13, 'priority' : 70})
+  call sign_place(2, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 12, 'priority' : 40})
+  call sign_place(3, '', 'sign3', 'Xsign',
+	      \ {'lnum' : 13, 'priority' : 30})
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 11, 'priority' : 50})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 11, 'group' : '',
+	      \ 'priority' : 50},
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 12, 'group' : '',
+	      \ 'priority' : 40},
+	      \ {'id' : 3, 'name' : 'sign3', 'lnum' : 13, 'group' : '',
+	      \ 'priority' : 30}],
+	      \ s[0].signs)
+
+  call sign_unplace('*')
+
+  " Two signs on the same line with changing priorities
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 20})
+  call sign_place(2, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 30})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 30},
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20}],
+	      \ s[0].signs)
+  " Change the priority of the last sign to highest
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 40})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 40},
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 30}],
+	      \ s[0].signs)
+  " Change the priority of the first sign to lowest
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 25})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 30},
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 25}],
+	      \ s[0].signs)
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 45})
+  call sign_place(2, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 55})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 55},
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 45}],
+	      \ s[0].signs)
+
+  call sign_unplace('*')
+
+  " Three signs on the same line with changing priorities
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 40})
+  call sign_place(2, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 30})
+  call sign_place(3, '', 'sign3', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 20})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 40},
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 30},
+	      \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20}],
+	      \ s[0].signs)
+
+  " Change the priority of the middle sign to the highest
+  call sign_place(2, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 50})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 50},
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 40},
+	      \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20}],
+	      \ s[0].signs)
+
+  " Change the priority of the middle sign to the lowest
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 15})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 50},
+	      \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20},
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 15}],
+	      \ s[0].signs)
+
+  " Change the priority of the last sign to the highest
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 55})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 55},
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 50},
+	      \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20}],
+	      \ s[0].signs)
+
+  " Change the priority of the first sign to the lowest
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 15})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 50},
+	      \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20},
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 15}],
+	      \ s[0].signs)
+
+  call sign_unplace('*')
+
+  " Three signs on the same line with changing priorities along with other
+  " signs
+  call sign_place(1, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 2, 'priority' : 10})
+  call sign_place(2, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 30})
+  call sign_place(3, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 20})
+  call sign_place(4, '', 'sign3', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 25})
+  call sign_place(5, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 6, 'priority' : 80})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 2, 'group' : '',
+	      \ 'priority' : 10},
+	      \ {'id' : 2, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 30},
+	      \ {'id' : 4, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 25},
+	      \ {'id' : 3, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20},
+	      \ {'id' : 5, 'name' : 'sign2', 'lnum' : 6, 'group' : '',
+	      \ 'priority' : 80}],
+	      \ s[0].signs)
+
+  " Change the priority of the first sign to lowest
+  call sign_place(2, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 15})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 2, 'group' : '',
+	      \ 'priority' : 10},
+	      \ {'id' : 4, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 25},
+	      \ {'id' : 3, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20},
+	      \ {'id' : 2, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 15},
+	      \ {'id' : 5, 'name' : 'sign2', 'lnum' : 6, 'group' : '',
+	      \ 'priority' : 80}],
+	      \ s[0].signs)
+
+  " Change the priority of the last sign to highest
+  call sign_place(2, '', 'sign1', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 30})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 2, 'group' : '',
+	      \ 'priority' : 10},
+	      \ {'id' : 2, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 30},
+	      \ {'id' : 4, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 25},
+	      \ {'id' : 3, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20},
+	      \ {'id' : 5, 'name' : 'sign2', 'lnum' : 6, 'group' : '',
+	      \ 'priority' : 80}],
+	      \ s[0].signs)
+
+  " Change the priority of the middle sign to lowest
+  call sign_place(4, '', 'sign3', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 15})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 2, 'group' : '',
+	      \ 'priority' : 10},
+	      \ {'id' : 2, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 30},
+	      \ {'id' : 3, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 20},
+	      \ {'id' : 4, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 15},
+	      \ {'id' : 5, 'name' : 'sign2', 'lnum' : 6, 'group' : '',
+	      \ 'priority' : 80}],
+	      \ s[0].signs)
+
+  " Change the priority of the middle sign to highest
+  call sign_place(3, '', 'sign2', 'Xsign',
+	      \ {'lnum' : 4, 'priority' : 35})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+	      \ {'id' : 1, 'name' : 'sign1', 'lnum' : 2, 'group' : '',
+	      \ 'priority' : 10},
+	      \ {'id' : 3, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 35},
+	      \ {'id' : 2, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 30},
+	      \ {'id' : 4, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+	      \ 'priority' : 15},
+	      \ {'id' : 5, 'name' : 'sign2', 'lnum' : 6, 'group' : '',
+	      \ 'priority' : 80}],
+	      \ s[0].signs)
+
+  call sign_unplace('*')
+
+  " Multiple signs with the same priority on the same line
+  call sign_place(1, '', 'sign1', 'Xsign',
+              \ {'lnum' : 4, 'priority' : 20})
+  call sign_place(2, '', 'sign2', 'Xsign',
+              \ {'lnum' : 4, 'priority' : 20})
+  call sign_place(3, '', 'sign3', 'Xsign',
+              \ {'lnum' : 4, 'priority' : 20})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+              \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20},
+              \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20},
+              \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20}],
+              \ s[0].signs)
+  " Place the last sign again with the same priority
+  call sign_place(1, '', 'sign1', 'Xsign',
+              \ {'lnum' : 4, 'priority' : 20})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+              \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20},
+              \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20},
+              \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20}],
+              \ s[0].signs)
+  " Place the first sign again with the same priority
+  call sign_place(1, '', 'sign1', 'Xsign',
+              \ {'lnum' : 4, 'priority' : 20})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+              \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20},
+              \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20},
+              \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20}],
+              \ s[0].signs)
+  " Place the middle sign again with the same priority
+  call sign_place(3, '', 'sign3', 'Xsign',
+              \ {'lnum' : 4, 'priority' : 20})
+  let s = sign_getplaced('Xsign', {'group' : '*'})
+  call assert_equal([
+              \ {'id' : 3, 'name' : 'sign3', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20},
+              \ {'id' : 1, 'name' : 'sign1', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20},
+              \ {'id' : 2, 'name' : 'sign2', 'lnum' : 4, 'group' : '',
+              \ 'priority' : 20}],
+              \ s[0].signs)
+
+  call sign_unplace('*')
+
   " Place multiple signs with same id on a line with different priority
   call sign_place(1, '', 'sign1', 'Xsign',
 	      \ {'lnum' : 5, 'priority' : 20})