aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2015-01-17 12:46:29 +0100
committerThiago de Arruda <tpadilha84@gmail.com>2015-01-23 07:47:48 -0300
commit5c837f613ed6e5eb6765cbfa8e27ea0a0ed97cb7 (patch)
tree7a4f8af8399dd88ca375d4d5c3f617fba4fcc3b4
parent0f39097e5348ae61dbf9a226ffde3bca6b75d659 (diff)
downloadrneovim-5c837f613ed6e5eb6765cbfa8e27ea0a0ed97cb7.tar.gz
rneovim-5c837f613ed6e5eb6765cbfa8e27ea0a0ed97cb7.tar.bz2
rneovim-5c837f613ed6e5eb6765cbfa8e27ea0a0ed97cb7.zip
tests/ui: snapshot util
-rw-r--r--test/functional/ui/screen.lua58
1 files changed, 53 insertions, 5 deletions
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 27e5900338..321853bb1b 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -385,6 +385,50 @@ function Screen:_current_screen()
return table.concat(rv, '\n')
end
+function Screen:snapshot_util(attrs)
+ -- util to generate screen test
+ pcall(function() self:wait(function() return "error" end, 250) end)
+ if attrs == nil then
+ attrs = {{}}
+ for i = 1, self._height do
+ local row = self._rows[i]
+ for j = 1, self._width do
+ local attr = row[j].attrs
+ local found = false
+ for i,a in pairs(attrs) do
+ if equal_attrs(a, attr) then
+ found = true
+ break
+ end
+ end
+ if not found then
+ table.insert(attrs, attr)
+ end
+ end
+ end
+ table.remove(attrs, 1)
+ end
+
+ local rv = {}
+ for i = 1, self._height do
+ table.insert(rv, " "..self:_row_repr(self._rows[i],attrs).."|")
+ end
+ local attrstrs = {}
+ for i, a in ipairs(attrs) do
+ local items = {}
+ for f, v in pairs(a) do
+ table.insert(items, f.." = "..tostring(v))
+ end
+ local dict = "{"..table.concat(items, ", ").."}"
+ table.insert(attrstrs, "["..tostring(i).."] = "..dict)
+ end
+ local attrstr = "{"..table.concat(attrstrs, ", ").."}"
+ print( "\nscreen:expect([[")
+ print( table.concat(rv, '\n'))
+ print( "]], "..attrstr..")\n")
+end
+
+
function backward_find_meaningful(tbl, from)
for i = from or #tbl, 1, -1 do
if tbl[i] ~= ' ' then
@@ -399,15 +443,19 @@ function get_attr_id(attr_ids, attrs)
return
end
for id, a in pairs(attr_ids) do
- if a.bold == attrs.bold and a.standout == attrs.standout and
- a.underline == attrs.underline and a.undercurl == attrs.undercurl and
- a.italic == attrs.italic and a.reverse == attrs.reverse and
- a.foreground == attrs.foreground and
- a.background == attrs.background then
+ if equal_attrs(a, attrs) then
return id
end
end
return nil
end
+function equal_attrs(a, b)
+ return a.bold == b.bold and a.standout == b.standout and
+ a.underline == b.underline and a.undercurl == b.undercurl and
+ a.italic == b.italic and a.reverse == b.reverse and
+ a.foreground == b.foreground and
+ a.background == b.background
+end
+
return Screen