about summary refs log blame commit diff stats
path: root/test.lua
blob: cc94d9462ef6deae5fbcc40bdadbf7311a44a3d7 (plain) (tree)
1
2
3
4
5
6
7
8
9
                             

                      
               



              
                          
                  



                                                   
                                   
                             
                                                                







                                             
                             



                           
                             






                    
-- Some primitives for tests.

function check(x, msg)
  if not x then
    error(msg)
  end
end

function check_nil(x, msg)
  if x ~= nil then
    error(msg..'; should be nil but got "'..x..'"')
  end
end

function check_eq(x, expected, msg)
  if not eq(x, expected) then
    error(msg..'; should be "'..expected..'" but got "'..x..'"')
  end
end

function eq(a, b)
  if type(a) ~= type(b) then return false end
  if type(a) == 'table' then
    if #a ~= #b then return false end
    for k, v in pairs(a) do
      if not eq(b[k], v) then
        return false
      end
    end
    for k, v in pairs(b) do
      if not eq(a[k], v) then
        return false
      end
    end
    return true
  end
  return a == b
end