zet.tlv: first screen tests
In the process I found a couple of bugs in fake screen primitives.
This commit is contained in:
parent
70c3ec42bc
commit
e627114751
|
@ -1212,6 +1212,9 @@ static int run_tests(lua_State* L) {
|
||||||
const char* key = lua_tostring(L, -2);
|
const char* key = lua_tostring(L, -2);
|
||||||
if (strncmp("test_", key, strlen("test_")) != 0) continue;
|
if (strncmp("test_", key, strlen("test_")) != 0) continue;
|
||||||
if (!lua_isfunction(L, -1)) continue;
|
if (!lua_isfunction(L, -1)) continue;
|
||||||
|
/* uncomment these lines when it's not clear which test is failing */
|
||||||
|
//? addstr(key);
|
||||||
|
//? addstr("|");
|
||||||
int status = lua_pcall(L, 0, 0, 0);
|
int status = lua_pcall(L, 0, 0, 0);
|
||||||
if (status) {
|
if (status) {
|
||||||
printw("E%d: %s", status, lua_tostring(L, -1));
|
printw("E%d: %s", status, lua_tostring(L, -1));
|
||||||
|
|
15
template.tlv
15
template.tlv
|
@ -258,7 +258,7 @@
|
||||||
> return rawget(h, key)
|
> return rawget(h, key)
|
||||||
> end
|
> end
|
||||||
> h.attrset = function(self, x)
|
> h.attrset = function(self, x)
|
||||||
> table.insert(self.scr.attrs, x)
|
> self.scr.attrs = x
|
||||||
> end
|
> end
|
||||||
> h.attron = function(self, x)
|
> h.attron = function(self, x)
|
||||||
> -- currently same as attrset since Lua 5.1 doesn't have bitwise operators
|
> -- currently same as attrset since Lua 5.1 doesn't have bitwise operators
|
||||||
|
@ -296,13 +296,16 @@
|
||||||
> h.mvaddch = function(self, y, x, c)
|
> h.mvaddch = function(self, y, x, c)
|
||||||
> self.scr.cursy = y
|
> self.scr.cursy = y
|
||||||
> self.scr.cursx = x
|
> self.scr.cursx = x
|
||||||
> self.addch(c)
|
> self:addch(c)
|
||||||
> end
|
> end
|
||||||
> h.mvaddstr = function(self, y, x, s)
|
> h.mvaddstr = function(self, y, x, s)
|
||||||
> self.scr.cursy = y
|
> self.scr.cursy = y
|
||||||
> self.scr.cursx = x
|
> self.scr.cursx = x
|
||||||
> self:addstr(s)
|
> self:addstr(s)
|
||||||
> end
|
> end
|
||||||
|
> h.clear = function(self)
|
||||||
|
> clear_scr(self.scr)
|
||||||
|
> end
|
||||||
> return h
|
> return h
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp: original
|
- __teliva_timestamp: original
|
||||||
|
@ -319,6 +322,12 @@
|
||||||
>function scr(props)
|
>function scr(props)
|
||||||
> props.cursx = 1
|
> props.cursx = 1
|
||||||
> props.cursy = 1
|
> props.cursy = 1
|
||||||
|
> clear_scr(props)
|
||||||
|
> return props
|
||||||
|
>end
|
||||||
|
- __teliva_timestamp: original
|
||||||
|
clear_scr:
|
||||||
|
>function clear_scr(props)
|
||||||
> for y=1,props.h do
|
> for y=1,props.h do
|
||||||
> props[y] = {}
|
> props[y] = {}
|
||||||
> for x=1,props.w do
|
> for x=1,props.w do
|
||||||
|
@ -332,7 +341,7 @@
|
||||||
>function check_screen(window, contents, message)
|
>function check_screen(window, contents, message)
|
||||||
> local x, y = 1, 1
|
> local x, y = 1, 1
|
||||||
> for i=1,contents:len() do
|
> for i=1,contents:len() do
|
||||||
> check_eq(contents[i], window.scr[y][x].data, message..'/'..y..','..x)
|
> check_eq(window.scr[y][x].data, contents[i], message..'/'..y..','..x)
|
||||||
> x = x+1
|
> x = x+1
|
||||||
> if x > window.scr.w then
|
> if x > window.scr.w then
|
||||||
> y = y+1
|
> y = y+1
|
||||||
|
|
99
zet.tlv
99
zet.tlv
|
@ -260,7 +260,7 @@
|
||||||
> return rawget(h, key)
|
> return rawget(h, key)
|
||||||
> end
|
> end
|
||||||
> h.attrset = function(self, x)
|
> h.attrset = function(self, x)
|
||||||
> table.insert(self.scr.attrs, x)
|
> self.scr.attrs = x
|
||||||
> end
|
> end
|
||||||
> h.attron = function(self, x)
|
> h.attron = function(self, x)
|
||||||
> -- currently same as attrset since Lua 5.1 doesn't have bitwise operators
|
> -- currently same as attrset since Lua 5.1 doesn't have bitwise operators
|
||||||
|
@ -298,13 +298,16 @@
|
||||||
> h.mvaddch = function(self, y, x, c)
|
> h.mvaddch = function(self, y, x, c)
|
||||||
> self.scr.cursy = y
|
> self.scr.cursy = y
|
||||||
> self.scr.cursx = x
|
> self.scr.cursx = x
|
||||||
> self.addch(c)
|
> self:addch(c)
|
||||||
> end
|
> end
|
||||||
> h.mvaddstr = function(self, y, x, s)
|
> h.mvaddstr = function(self, y, x, s)
|
||||||
> self.scr.cursy = y
|
> self.scr.cursy = y
|
||||||
> self.scr.cursx = x
|
> self.scr.cursx = x
|
||||||
> self:addstr(s)
|
> self:addstr(s)
|
||||||
> end
|
> end
|
||||||
|
> h.clear = function(self)
|
||||||
|
> clear_scr(self.scr)
|
||||||
|
> end
|
||||||
> return h
|
> return h
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp: original
|
- __teliva_timestamp: original
|
||||||
|
@ -321,6 +324,12 @@
|
||||||
>function scr(props)
|
>function scr(props)
|
||||||
> props.cursx = 1
|
> props.cursx = 1
|
||||||
> props.cursy = 1
|
> props.cursy = 1
|
||||||
|
> clear_scr(props)
|
||||||
|
> return props
|
||||||
|
>end
|
||||||
|
- __teliva_timestamp: original
|
||||||
|
clear_scr:
|
||||||
|
>function clear_scr(props)
|
||||||
> for y=1,props.h do
|
> for y=1,props.h do
|
||||||
> props[y] = {}
|
> props[y] = {}
|
||||||
> for x=1,props.w do
|
> for x=1,props.w do
|
||||||
|
@ -334,7 +343,7 @@
|
||||||
>function check_screen(window, contents, message)
|
>function check_screen(window, contents, message)
|
||||||
> local x, y = 1, 1
|
> local x, y = 1, 1
|
||||||
> for i=1,contents:len() do
|
> for i=1,contents:len() do
|
||||||
> check_eq(contents[i], window.scr[y][x].data, message..'/'..y..','..x)
|
> check_eq(window.scr[y][x].data, contents[i], message..'/'..y..','..x)
|
||||||
> x = x+1
|
> x = x+1
|
||||||
> if x > window.scr.w then
|
> if x > window.scr.w then
|
||||||
> y = y+1
|
> y = y+1
|
||||||
|
@ -3726,3 +3735,87 @@
|
||||||
> outfile:send(json.encode(zettels))
|
> outfile:send(json.encode(zettels))
|
||||||
> outfile:close()
|
> outfile:close()
|
||||||
>end
|
>end
|
||||||
|
- __teliva_timestamp:
|
||||||
|
>Thu Mar 10 04:21:28 2022
|
||||||
|
render_zettel:
|
||||||
|
>function render_zettel(window, bg, indent, edge_label, starty, startx, zettel)
|
||||||
|
> window:attrset(curses.color_pair(bg))
|
||||||
|
> for y=0,view_settings.height-1 do
|
||||||
|
> for x=0,view_settings.width-1 do
|
||||||
|
> window:mvaddch(y+starty, x+startx, ' ')
|
||||||
|
> end
|
||||||
|
> end
|
||||||
|
> if indent >= 2 then -- need at least 2 spaces to be able to print edge_label
|
||||||
|
> window:attrset(curses.color_pair(bg+1)) -- go from zettel color to its edge color
|
||||||
|
> window:mvaddstr(starty, startx+indent-1, edge_label)
|
||||||
|
> window:attrset(curses.color_pair(bg))
|
||||||
|
> end
|
||||||
|
> local y, x = 0, indent+1
|
||||||
|
> local data = ''
|
||||||
|
> if zettel then
|
||||||
|
> data = zettel.data
|
||||||
|
> end
|
||||||
|
> for i=1,#data do
|
||||||
|
> local c = data[i]
|
||||||
|
> if c == '\n' then
|
||||||
|
> y = y+1
|
||||||
|
> x = indent+1
|
||||||
|
> else
|
||||||
|
> window:mvaddstr(y+starty, x+startx, c)
|
||||||
|
> x = x+1
|
||||||
|
> if x >= startx + view_settings.width then
|
||||||
|
> y = y+1
|
||||||
|
> x = indent+1
|
||||||
|
> end
|
||||||
|
> end
|
||||||
|
> if y >= view_settings.height then
|
||||||
|
> break
|
||||||
|
> end
|
||||||
|
> end
|
||||||
|
>end
|
||||||
|
>
|
||||||
|
>function test_render_zettel()
|
||||||
|
> local w = window{scr=scr{h=5, w=10}}
|
||||||
|
> --
|
||||||
|
> render_zettel(w, 34, 1, -- color 34, indent 1
|
||||||
|
> '*', 1, 1, -- startx, starty
|
||||||
|
> {data='abc'})
|
||||||
|
> check_screen(w, ' abc '..
|
||||||
|
> ' '..
|
||||||
|
> ' '..
|
||||||
|
> ' '..
|
||||||
|
> ' ',
|
||||||
|
> 'test_render_zettel: single line, top-left')
|
||||||
|
> -- entire width is used by the single zettel
|
||||||
|
> -- column 1 = margin, column 2 = indent
|
||||||
|
> check_color(w, 34, '##########'..
|
||||||
|
> '##########'..
|
||||||
|
> '##########'..
|
||||||
|
> ' '..
|
||||||
|
> ' ',
|
||||||
|
> 'test_render_zettel: single line, top-left, background')
|
||||||
|
> --
|
||||||
|
> w:clear()
|
||||||
|
> render_zettel(w, 34, 1, '*', 3, 4, {data='abc'}) -- startx=3, starty=4
|
||||||
|
> check_screen(w, ' '..
|
||||||
|
> ' '..
|
||||||
|
> ' abc '..
|
||||||
|
> ' '..
|
||||||
|
> ' ',
|
||||||
|
> 'test_render_zettel: specific coord')
|
||||||
|
> check_color(w, 34, ' '..
|
||||||
|
> ' '..
|
||||||
|
> ' #######'..
|
||||||
|
> ' #######'..
|
||||||
|
> ' #######',
|
||||||
|
> 'test_render_zettel: specific coord, background')
|
||||||
|
> --
|
||||||
|
> w:clear()
|
||||||
|
> render_zettel(w, 34, 2, '*', 3, 4, {data='abc'}) -- startx=3, starty=4
|
||||||
|
> check_screen(w, ' '..
|
||||||
|
> ' '..
|
||||||
|
> ' * abc '..
|
||||||
|
> ' '..
|
||||||
|
> ' ',
|
||||||
|
> 'test_render_zettel: indent >= 2 prints edge label')
|
||||||
|
>end
|
||||||
|
|
Loading…
Reference in New Issue