diff src/testdir/test_popupwin.vim @ 16837:18593056d8f1 v8.1.1420

patch 8.1.1420: popup window size only uses first line length commit https://github.com/vim/vim/commit/88c4e1f06905983870175a473683e81312d14c64 Author: Bram Moolenaar <Bram@vim.org> Date: Wed May 29 23:14:28 2019 +0200 patch 8.1.1420: popup window size only uses first line length Problem: Popup window size only uses first line length. Solution: Use the longest line. (Ben Jackson, closes https://github.com/vim/vim/issues/4451) Also deal with wrapping lines.
author Bram Moolenaar <Bram@vim.org>
date Wed, 29 May 2019 23:15:05 +0200
parents 5cebaecad422
children 032d5335987e
line wrap: on
line diff
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -176,3 +176,39 @@ func Test_popup_getposition()
 
   call popup_close(winid)
 endfunc
+
+func Test_popup_width_longest()
+  let tests = [
+	\ [['hello', 'this', 'window', 'displays', 'all of its text'], 15],
+	\ [['hello', 'this', 'window', 'all of its text', 'displays'], 15],
+	\ [['hello', 'this', 'all of its text', 'window', 'displays'], 15],
+	\ [['hello', 'all of its text', 'this', 'window', 'displays'], 15],
+	\ [['all of its text', 'hello', 'this', 'window', 'displays'], 15],
+	\ ]
+
+  for test in tests
+    let winid = popup_create(test[0], {'line': 2, 'col': 3})
+    redraw
+    let position = popup_getposition(winid)
+    call assert_equal(test[1], position.width)
+    call popup_close(winid)
+  endfor
+endfunc
+
+func Test_popup_wraps()
+  let tests = [
+	\ ['nowrap', 6, 1],
+	\ ['a line that wraps once', 12, 2],
+	\ ['a line that wraps two times', 12, 3],
+	\ ]
+  for test in tests
+    let winid = popup_create(test[0],
+	  \ {'line': 2, 'col': 3, 'maxwidth': 12})
+    redraw
+    let position = popup_getposition(winid)
+    call assert_equal(test[1], position.width)
+    call assert_equal(test[2], position.height)
+
+    call popup_close(winid)
+  endfor
+endfunc