summaryrefslogtreecommitdiffstatshomepage
path: root/test/testutil.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2026-02-12 20:10:02 +0800
committerGitHub <noreply@github.com>2026-02-12 20:10:02 +0800
commit16da47f4749b49660d85b3d00aaa00d66098027f (patch)
treed7a1f10f95ff3bbe86264dc00675e15a1b2e2fdd /test/testutil.lua
parentec365a10924bc289fe30e1baf1f5511d207f6704 (diff)
fix(terminal): changing height may lead to wrong scrollback (#37824)
Problem: Changing terminal height immediately after outputting lines may lead to wrong scrollback. Solution: Insert pending scrollback lines before the old window height.
Diffstat (limited to 'test/testutil.lua')
-rw-r--r--test/testutil.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/testutil.lua b/test/testutil.lua
index 7a4a9b9aac..7709ac464f 100644
--- a/test/testutil.lua
+++ b/test/testutil.lua
@@ -646,6 +646,29 @@ function M.concat_tables(...)
return ret
end
+--- Get all permutations of an array.
+---
+--- @param arr any[]
+--- @return any[][]
+function M.permutations(arr)
+ local res = {} --- @type any[][]
+ --- @param a any[]
+ --- @param n integer
+ local function gen(a, n)
+ if n == 0 then
+ res[#res + 1] = M.shallowcopy(a)
+ return
+ end
+ for i = 1, n do
+ a[n], a[i] = a[i], a[n]
+ gen(a, n - 1)
+ a[n], a[i] = a[i], a[n]
+ end
+ end
+ gen(M.shallowcopy(arr), #arr)
+ return res
+end
+
--- @param str string
--- @param leave_indent? integer
--- @return string