local sessions = require 'bugabinga.sessions' local function pane( left, top, width, height ) return { left = left, top = top, width = width, height = height, domain = 'local', cwd = '/tmp', } end local single = sessions.layout { pane( 0, 0, 80, 24 ), } assert( single.width == 80 and single.height == 24 and single.domain == 'local' ) local tree = sessions.layout { pane( 0, 0, 39, 24 ), pane( 40, 0, 40, 11 ), pane( 40, 12, 40, 12 ), } assert( tree.direction == 'Right' and tree.first.width == 39 ) assert( tree.second.direction == 'Bottom' and tree.second.second.height == 12 ) local grid = sessions.layout { pane( 0, 0, 39, 11 ), pane( 40, 0, 40, 11 ), pane( 0, 12, 39, 12 ), pane( 40, 12, 40, 12 ), } assert( grid.direction and grid.first.direction and grid.second.direction ) assert( not pcall( sessions.layout, { pane( 0, 0, 20, 20 ), pane( 10, 10, 20, 20 ), } ) ) local snapshot = { version = 1, active_tab = 1, tabs = { { title = '', tree = tree, }, }, } sessions.validate( snapshot ) snapshot.version = 2 assert( not pcall( sessions.validate, snapshot ) ) snapshot.version = 1 snapshot.active_tab = 0 assert( not pcall( sessions.validate, snapshot ) ) snapshot.active_tab = 1 snapshot.tabs[1].tree.second.direction = 'Diagonal' assert( not pcall( sessions.validate, snapshot ) ) assert( sessions.plain_text 'π café\nnext\tcolumn\27[31m\7\194\155' == 'π café\r\nnext column[31m' ) assert( sessions.plain_text 'a\r\nb\rc\0d' == 'a\r\nbcd' ) assert( not sessions.bootstrap 'fixture':find( 'sleep', 1, true ) ) print 'Session layout tests passed'