From 70c3ec42bc7c88c26b41bd364dd4d83d4d4138b3 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 8 Mar 2022 22:42:32 -0800 Subject: [PATCH] screen tests: support bold, reverse, color We can't test combinations of these yet because Lua 5.1 doesn't support bitwise operators. Reason #1 to upgrade. --- template.tlv | 102 +++++++++++++++++++++++++++++++++++++++++++++++++-- zet.tlv | 102 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 198 insertions(+), 6 deletions(-) diff --git a/template.tlv b/template.tlv index ba92fbf..f36d526 100644 --- a/template.tlv +++ b/template.tlv @@ -76,6 +76,21 @@ > debugy = debugy+1 > window:mvaddstr(oldy, oldx, '') >end +- __teliva_timestamp: original + check: + >function check(x, msg) + > if x then + > Window:addch('.') + > else + > print('F - '..msg) + > print(' '..str(x)..' is false/nil') + > teliva_num_test_failures = teliva_num_test_failures + 1 + > -- overlay first test failure on editors + > if teliva_first_failure == nil then + > teliva_first_failure = msg + > end + > end + >end - __teliva_timestamp: original check_eq: >function check_eq(x, expected, msg) @@ -242,13 +257,30 @@ > h.__index = function(table, key) > return rawget(h, key) > end + > h.attrset = function(self, x) + > table.insert(self.scr.attrs, x) + > end + > h.attron = function(self, x) + > -- currently same as attrset since Lua 5.1 doesn't have bitwise operators + > -- doesn't support multiple attrs at once + >-- local old = self.scr.attrs + >-- self.scr.attrs = old|x + > self.scr.attrs = x + > end + > h.attroff = function(self, x) + > -- currently borked since Lua 5.1 doesn't have bitwise operators + > -- doesn't support multiple attrs at once + >-- local old = self.scr.attrs + >-- self.scr.attrs = old & (~x) + > self.scr.attrs = curses.A_NORMAL + > end > h.getch = function(self) > return table.remove(h.kbd, 1) > end > h.addch = function(self, c) > local scr = self.scr > if scr.cursy <= scr.h then - > scr[scr.cursy][scr.cursx] = c + > scr[scr.cursy][scr.cursx] = {data=c, attrs=scr.attrs} > scr.cursx = scr.cursx+1 > if scr.cursx > scr.w then > scr.cursy = scr.cursy+1 @@ -290,7 +322,7 @@ > for y=1,props.h do > props[y] = {} > for x=1,props.w do - > props[y][x] = ' ' + > props[y][x] = {data=' ', attrs=curses.A_NORMAL} > end > end > return props @@ -300,7 +332,7 @@ >function check_screen(window, contents, message) > local x, y = 1, 1 > for i=1,contents:len() do - > check_eq(contents[i], window.scr[y][x], message..'/'..y..','..x) + > check_eq(contents[i], window.scr[y][x].data, message..'/'..y..','..x) > x = x+1 > if x > window.scr.w then > y = y+1 @@ -333,6 +365,70 @@ > '123 ', > 'test_check_screen') >end +- __teliva_timestamp: original + check_reverse: + >function check_reverse(window, contents, message) + > local x, y = 1, 1 + > for i=1,contents:len() do + > if contents[i] ~= ' ' then + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & curses.A_REVERSE, message..'/'..y..','..x) + > check_eq(window.scr[y][x].attrs, curses.A_REVERSE, message..'/'..y..','..x) + > else + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & (~curses.A_REVERSE), message..'/'..y..','..x) + > check(window.scr[y][x].attrs ~= curses.A_REVERSE, message..'/'..y..','..x) + > end + > x = x+1 + > if x > window.scr.w then + > y = y+1 + > x = 1 + > end + > end + >end +- __teliva_timestamp: original + check_bold: + >function check_bold(window, contents, message) + > local x, y = 1, 1 + > for i=1,contents:len() do + > if contents[i] ~= ' ' then + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & curses.A_BOLD, message..'/'..y..','..x) + > check_eq(window.scr[y][x].attrs, curses.A_BOLD, message..'/'..y..','..x) + > else + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & (~curses.A_BOLD), message..'/'..y..','..x) + > check(window.scr[y][x].attrs ~= curses.A_BOLD, message..'/'..y..','..x) + > end + > x = x+1 + > if x > window.scr.w then + > y = y+1 + > x = 1 + > end + > end + >end +- __teliva_timestamp: original + check_color: + >-- check which parts of a screen have the given color_pair + >function check_color(window, cp, contents, message) + > local x, y = 1, 1 + > for i=1,contents:len() do + > if contents[i] ~= ' ' then + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & curses.color_pair(cp), message..'/'..y..','..x) + > check_eq(window.scr[y][x].attrs, curses.color_pair(cp), message..'/'..y..','..x) + > else + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & (~curses.A_BOLD), message..'/'..y..','..x) + > check(window.scr[y][x].attrs ~= curses.color_pair(cp), message..'/'..y..','..x) + > end + > x = x+1 + > if x > window.scr.w then + > y = y+1 + > x = 1 + > end + > end + >end - __teliva_timestamp: original render: >function render(window) diff --git a/zet.tlv b/zet.tlv index 1963796..a38f80e 100644 --- a/zet.tlv +++ b/zet.tlv @@ -76,6 +76,21 @@ > debugy = debugy+1 > window:mvaddstr(oldy, oldx, '') >end +- __teliva_timestamp: original + check: + >function check(x, msg) + > if x then + > Window:addch('.') + > else + > print('F - '..msg) + > print(' '..str(x)..' is false/nil') + > teliva_num_test_failures = teliva_num_test_failures + 1 + > -- overlay first test failure on editors + > if teliva_first_failure == nil then + > teliva_first_failure = msg + > end + > end + >end - __teliva_timestamp: original check_eq: >function check_eq(x, expected, msg) @@ -244,13 +259,30 @@ > h.__index = function(table, key) > return rawget(h, key) > end + > h.attrset = function(self, x) + > table.insert(self.scr.attrs, x) + > end + > h.attron = function(self, x) + > -- currently same as attrset since Lua 5.1 doesn't have bitwise operators + > -- doesn't support multiple attrs at once + >-- local old = self.scr.attrs + >-- self.scr.attrs = old|x + > self.scr.attrs = x + > end + > h.attroff = function(self, x) + > -- currently borked since Lua 5.1 doesn't have bitwise operators + > -- doesn't support multiple attrs at once + >-- local old = self.scr.attrs + >-- self.scr.attrs = old & (~x) + > self.scr.attrs = curses.A_NORMAL + > end > h.getch = function(self) > return table.remove(h.kbd, 1) > end > h.addch = function(self, c) > local scr = self.scr > if scr.cursy <= scr.h then - > scr[scr.cursy][scr.cursx] = c + > scr[scr.cursy][scr.cursx] = {data=c, attrs=scr.attrs} > scr.cursx = scr.cursx+1 > if scr.cursx > scr.w then > scr.cursy = scr.cursy+1 @@ -292,7 +324,7 @@ > for y=1,props.h do > props[y] = {} > for x=1,props.w do - > props[y][x] = ' ' + > props[y][x] = {data=' ', attrs=curses.A_NORMAL} > end > end > return props @@ -302,7 +334,7 @@ >function check_screen(window, contents, message) > local x, y = 1, 1 > for i=1,contents:len() do - > check_eq(contents[i], window.scr[y][x], message..'/'..y..','..x) + > check_eq(contents[i], window.scr[y][x].data, message..'/'..y..','..x) > x = x+1 > if x > window.scr.w then > y = y+1 @@ -335,6 +367,70 @@ > '123 ', > 'test_check_screen') >end +- __teliva_timestamp: original + check_reverse: + >function check_reverse(window, contents, message) + > local x, y = 1, 1 + > for i=1,contents:len() do + > if contents[i] ~= ' ' then + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & curses.A_REVERSE, message..'/'..y..','..x) + > check_eq(window.scr[y][x].attrs, curses.A_REVERSE, message..'/'..y..','..x) + > else + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & (~curses.A_REVERSE), message..'/'..y..','..x) + > check(window.scr[y][x].attrs ~= curses.A_REVERSE, message..'/'..y..','..x) + > end + > x = x+1 + > if x > window.scr.w then + > y = y+1 + > x = 1 + > end + > end + >end +- __teliva_timestamp: original + check_bold: + >function check_bold(window, contents, message) + > local x, y = 1, 1 + > for i=1,contents:len() do + > if contents[i] ~= ' ' then + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & curses.A_BOLD, message..'/'..y..','..x) + > check_eq(window.scr[y][x].attrs, curses.A_BOLD, message..'/'..y..','..x) + > else + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & (~curses.A_BOLD), message..'/'..y..','..x) + > check(window.scr[y][x].attrs ~= curses.A_BOLD, message..'/'..y..','..x) + > end + > x = x+1 + > if x > window.scr.w then + > y = y+1 + > x = 1 + > end + > end + >end +- __teliva_timestamp: original + check_color: + >-- check which parts of a screen have the given color_pair + >function check_color(window, cp, contents, message) + > local x, y = 1, 1 + > for i=1,contents:len() do + > if contents[i] ~= ' ' then + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & curses.color_pair(cp), message..'/'..y..','..x) + > check_eq(window.scr[y][x].attrs, curses.color_pair(cp), message..'/'..y..','..x) + > else + > -- hacky version while we're without bitwise operators on Lua 5.1 + >-- check(window.scr[y][x].attrs & (~curses.A_BOLD), message..'/'..y..','..x) + > check(window.scr[y][x].attrs ~= curses.color_pair(cp), message..'/'..y..','..x) + > end + > x = x+1 + > if x > window.scr.w then + > y = y+1 + > x = 1 + > end + > end + >end - __teliva_timestamp: original spaces: >function spaces(n)