diff options
| author | Matěj Cepl <mcepl@cepl.eu> | 2026-09-30 13:12:14 +0200 |
|---|---|---|
| committer | Matěj Cepl <mcepl@cepl.eu> | 2026-09-30 13:14:23 +0200 |
| commit | ff764eed4ca67cff8016d971f07de696cfbc3ff4 (patch) | |
| tree | b3187edfcd5ea183dd7447bd9f5d06536ac1a9ed /util_test.lua | |
| parent | c54c24b2639c8e9f9b3dd03d7a4fe556da328a76 (diff) | |
| download | vis-lspc-ff764eed4ca67cff8016d971f07de696cfbc3ff4.tar.gz vis-lspc-ff764eed4ca67cff8016d971f07de696cfbc3ff4.zip | |
support feature detection for vis ui styling API
In builds of vis packaged without a git tree (such as openSUSE OBS RPM
builds), vis.API defaults to 0. Checking `vis.API > 3215` therefore
fails even when the new vis.ui styling API is present.
Check for the existence of `vis.ui.style_define` and `vis.ui.style_push`
directly, and accept an optional window object in util.style_define for
backward compatibility with older versions.
Diffstat (limited to 'util_test.lua')
| -rwxr-xr-x | util_test.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/util_test.lua b/util_test.lua index 63393b1..99f34f0 100755 --- a/util_test.lua +++ b/util_test.lua @@ -73,4 +73,34 @@ function test_table_merge() -- luacheck: ignore 111 lunatest.assert_equal(t.foo.bar.nose, 'nose') end +function test_style_define() -- luacheck: ignore 111 + -- Modern vis: vis.ui.style_define present + vis.API = 0 + vis.ui = { + style_define = function(self, id, style) + return id == 1 and style == 'fore:red' + end, + } + lunatest.assert_true(util.style_define(1, 'fore:red')) + + -- Modern vis: vis.API > 3215 + vis.API = 3216 + lunatest.assert_true(util.style_define(1, 'fore:red')) + + -- Older vis: fallback with explicit win + vis.API = nil + vis.ui = nil + local win = { + style_define = function(self, id, style) + return id == 2 and style == 'fore:blue' + end, + } + lunatest.assert_true(util.style_define(2, 'fore:blue', win)) + + -- Older vis: fallback with vis.win + vis.win = win + lunatest.assert_true(util.style_define(2, 'fore:blue')) + vis.win = nil +end + lunatest.run() |
