From 347f10a379f21d40e888e459f532ea04968f208e Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Mon, 29 Jul 2013 11:41:05 -0400 Subject: [PATCH] Make table.isempty work with table which has a key as false (Baiyan Huang) --- src/base/table.lua | 2 +- tests/base/test_table.lua | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/base/table.lua b/src/base/table.lua index 80211c7f..95c513c2 100644 --- a/src/base/table.lua +++ b/src/base/table.lua @@ -224,7 +224,7 @@ -- function table.isempty(t) - return not next(t) + return next(t) == nil end diff --git a/tests/base/test_table.lua b/tests/base/test_table.lua index 90963c27..01e5b5e5 100644 --- a/tests/base/test_table.lua +++ b/tests/base/test_table.lua @@ -1,12 +1,11 @@ -- -- tests/base/test_table.lua -- Automated test suite for the new table functions. --- Copyright (c) 2008-2010 Jason Perkins and the Premake project +-- Copyright (c) 2008-2013 Jason Perkins and the Premake project -- - T.table = { } - local suite = T.table + local suite = test.declare("table") local t @@ -55,7 +54,7 @@ test.isequal(2, idx) end - + -- -- table.isempty() tests -- @@ -67,3 +66,11 @@ function suite.isempty_ReturnsFalseOnNotEmpty() test.isfalse(table.isempty({ 1 })) end + + function suite.isempty_ReturnsFalseOnNotEmptyMap() + test.isfalse(table.isempty({ name = 'premake' })) + end + + function suite.isempty_ReturnsFalseOnNotEmptyMapWithFalseKey() + test.isfalse(table.isempty({ [false] = 0 })) + end