@@ -18,6 +18,9 @@ local lua_directory = pwd .. '/lua/'
1818package.path = lua_directory .. ' ?.lua;' .. package.path
1919package.path = lua_directory .. ' ?/init.lua;' .. package.path
2020
21+ local is_list = require (' wincent.commandt.private.is_list' )
22+ local is_table = require (' wincent.commandt.private.is_table' )
23+
2124local contexts = {}
2225local current_context = nil
2326local current_test = nil
@@ -106,17 +109,53 @@ equal = function(a, b)
106109 end
107110end
108111
112+ local inspect = nil
113+
114+ inspect = function (value , indent )
115+ local prefix = (' ' ):rep (indent )
116+ if type (value ) == ' string' then
117+ return prefix .. " '" .. value :gsub (' \\ ' , ' \\\\ ' ):gsub (" '" , " \\ '" ) .. " '"
118+ elseif type (value ) == ' table' then
119+ if is_list (value ) then
120+ if # value == 0 then
121+ return prefix .. ' {}'
122+ else
123+ local output = prefix .. ' {\n '
124+ for _ , v in ipairs (value ) do
125+ output = output .. inspect (v , indent + 2 ) .. ' ,\n '
126+ end
127+ output = output .. prefix .. ' }'
128+ return output
129+ end
130+ else
131+ local output = prefix .. ' {\n '
132+ output = output .. prefix .. ' }'
133+ for k , v in pairs (value ) do
134+ local trimmed = inspect (v , indent + 2 ):gsub (' ^%s+' , ' ' )
135+ output = output .. ' [' .. inspect (k , 0 ) .. ' ] = ' .. trimmed .. ' ,\n '
136+ end
137+ return output
138+ end
139+ else
140+ return prefix .. tostring (value )
141+ end
142+ end
143+
109144_G .expect = function (value )
110145 return {
111146 to_be = function (other )
112147 if value ~= other then
148+ print (' \n Expected:\n\n ' .. inspect (other , 2 ) .. ' \n ' )
149+ print (' Actual:\n\n ' .. inspect (value , 2 ) .. ' \n ' )
150+ inspect (value )
113151 error (' not ==' , 2 )
114152 end
115153 end ,
116154
117155 to_equal = function (other )
118156 if not equal (value , other ) then
119- -- TODO: say how it was different
157+ print (' \n Expected:\n\n ' .. inspect (other , 2 ) .. ' \n ' )
158+ print (' Actual:\n\n ' .. inspect (value , 2 ) .. ' \n ' )
120159 error (' not equal' , 2 )
121160 end
122161 end ,
@@ -125,12 +164,16 @@ _G.expect = function(value)
125164 -- will refactor.
126165 not_to_be = function (other )
127166 if value == other then
167+ print (' \n Expected (not):\n\n ' .. inspect (other , 2 ) .. ' \n ' )
168+ print (' Actual:\n\n ' .. inspect (value , 2 ) .. ' \n ' )
128169 error (' ==' , 2 )
129170 end
130171 end ,
131172
132173 not_to_equal = function (other )
133174 if equal (value , other ) then
175+ print (' \n Expected (not):\n\n ' .. inspect (other , 2 ) .. ' \n ' )
176+ print (' Actual:\n\n ' .. inspect (value , 2 ) .. ' \n ' )
134177 error (' equal' , 2 )
135178 end
136179 end ,
0 commit comments