Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better list diffing2 #79

Merged
merged 17 commits into from Nov 18, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 6 additions & 12 deletions luaunit.lua
Expand Up @@ -498,13 +498,6 @@ local function getTaTbDesc()
return descta, desctb
end

local function is_eq( a, b )
if type(a) == 'table' and type(b) == 'table' then
return M.private._is_table_equals(a,b)
end
return a == b
end

local function extendWithStrFmt( res, ... )
table.insert( res, string.format( ... ) )
end
Expand All @@ -530,7 +523,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis )
local k, v

for k,v in pairs( ta ) do
if is_eq( v, tb[k] ) then
if is_equals( v, tb[k] ) then
table.insert( keysCommon, k )
else
if tb[k] == nil then
Expand All @@ -542,7 +535,7 @@ local function mismatchFormattingMapping( ta, tb, doDeepAnalysis )
end

for k,v in pairs( tb ) do
if not is_eq( v, ta[k] ) and ta[k] == nil then
if not is_equals( v, ta[k] ) and ta[k] == nil then
table.insert( keysOnlyTb, k )
end
end
Expand Down Expand Up @@ -646,7 +639,7 @@ local function mismatchFormattingPureList( ta, tb )

i = 1
while i <= longest do
if not is_eq(ta[i], tb[i]) then
if not is_equals(ta[i], tb[i]) then
break
end

Expand All @@ -656,7 +649,7 @@ local function mismatchFormattingPureList( ta, tb )

i = 0
while i > -shortest do
if not is_eq(ta[lta+i], tb[ltb+i]) then
if not is_equals(ta[lta+i], tb[ltb+i]) then
break
end
i = i - 1
Expand Down Expand Up @@ -689,7 +682,7 @@ local function mismatchFormattingPureList( ta, tb )

local function insertABValue(i, bi)
bi = bi or i
if is_eq( ta[i], tb[bi]) then
if is_equals( ta[i], tb[bi]) then
return extendWithStrFmt( result, ' = A[%d], B[%d]: %s', i, bi, prettystr(ta[i]) )
else
extendWithStrFmt( result, ' - A[%d]: %s', i, prettystr(ta[i]))
Expand Down Expand Up @@ -1036,6 +1029,7 @@ local function _is_table_equals(actual, expected, recursions)
return true
end
M.private._is_table_equals = _is_table_equals
local is_equals = _is_table_equals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer singular here in the function name, i.e. is_equal.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not...


local function failure(msg, level)
-- raise an error indicating a test failure
Expand Down