@@ -8,6 +8,10 @@ local group = tasty.test_group
88local test = tasty .test_case
99local assert = tasty .assert
1010
11+ local function renderANSI (doc , cols )
12+ return doclayout .render (doc , cols , true )
13+ end
14+
1115-- Check existence static fields
1216return {
1317 group ' constructors' {
@@ -244,6 +248,75 @@ return {
244248 end )
245249 },
246250
251+ -- Styling happens per-character, so the output is quite verbose, and
252+ -- includes additional commands to reset all attributes.
253+ -- We just look for the right escape sequences instead of matching
254+ -- the whole output.
255+ group ' styling' {
256+ test (' bold' , function ()
257+ assert .is_truthy (
258+ renderANSI (doclayout .bold (' a' )):match (' \027 %[1m' )
259+ )
260+ end ),
261+
262+ test (' italics' , function ()
263+ assert .is_truthy (
264+ renderANSI (doclayout .italic (' a' )):match (' \027 %[3m' )
265+ )
266+ end ),
267+
268+ test (' underlined' , function ()
269+ assert .is_truthy (
270+ renderANSI (doclayout .underlined (' a' )):match (' \027 %[4m' )
271+ )
272+ end ),
273+
274+ test (' strikeout' , function ()
275+ assert .is_truthy (
276+ renderANSI (doclayout .strikeout (' a' )):match (' \027 %[9m' )
277+ )
278+ end ),
279+
280+ test (' fg' , function ()
281+ assert .is_truthy (
282+ renderANSI (doclayout .fg (' a' , ' red' )):match (' \027 %[31m' )
283+ )
284+ end ),
285+
286+ test (' bg' , function ()
287+ assert .is_truthy (
288+ renderANSI (doclayout .bg (' a' , ' red' )):match (' \027 %[41m' )
289+ )
290+ end ),
291+
292+ group ' colors' {
293+ test (' black' , function ()
294+ renderANSI (doclayout .bg (' a' , ' black' )):match (' \027 %[40m' )
295+ end ),
296+ test (' red' , function ()
297+ renderANSI (doclayout .bg (' a' , ' red' )):match (' \027 %[41m' )
298+ end ),
299+ test (' green' , function ()
300+ renderANSI (doclayout .bg (' a' , ' green' )):match (' \027 %[42m' )
301+ end ),
302+ test (' yellow' , function ()
303+ renderANSI (doclayout .bg (' a' , ' yellow' )):match (' \027 %[43m' )
304+ end ),
305+ test (' blue' , function ()
306+ renderANSI (doclayout .bg (' a' , ' blue' )):match (' \027 %[44m' )
307+ end ),
308+ test (' magenta' , function ()
309+ renderANSI (doclayout .bg (' a' , ' magenta' )):match (' \027 %[45m' )
310+ end ),
311+ test (' cyan' , function ()
312+ renderANSI (doclayout .bg (' a' , ' cyan' )):match (' \027 %[46m' )
313+ end ),
314+ test (' white' , function ()
315+ renderANSI (doclayout .bg (' a' , ' white' )):match (' \027 %[47m' )
316+ end ),
317+ }
318+ },
319+
247320 group ' Doc type' {
248321 test (' empty strings equal the empty Doc' , function ()
249322 assert .are_equal (doclayout .empty .. ' ' , doclayout .empty )
0 commit comments