What is an is not an identifier is now automatically determined by is_identifier
.
This commit is contained in:
parent
8f8e5b9c7f
commit
33fb88fdd7
|
@ -48,13 +48,18 @@ local MINIMUM_NUMBER_OF_SET_ELEMENTS = 2
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function is_identifier(str)
|
||||
-- An identier is defined in the lua reference guide
|
||||
local function is_identifier(s)
|
||||
-- Predicate: Is the given string usable as an identifier in this version of
|
||||
-- Lua?
|
||||
|
||||
return str:match('^[_%a][_%w]*$') and not RESERVED_LUA_WORDS[str]
|
||||
assert(type(s) == 'string')
|
||||
--
|
||||
return not not loadstring(s..'=0') and not s:find '%.' and not RESERVED_LUA_WORDS[s]
|
||||
end
|
||||
|
||||
local function get_key_types (t)
|
||||
assert(type(t) == 'table')
|
||||
--
|
||||
local types = { nr_types = -1 }
|
||||
for key, _ in pairs(t) do
|
||||
types[type(key)] = true
|
||||
|
@ -67,6 +72,8 @@ local function get_key_types (t)
|
|||
end
|
||||
|
||||
local function get_value_types (t)
|
||||
assert(type(t) == 'table')
|
||||
--
|
||||
local types = { nr_types = -1 }
|
||||
for _, value in pairs(t) do
|
||||
types[type(value)] = true
|
||||
|
@ -81,6 +88,8 @@ end
|
|||
local function largest_number_index (t)
|
||||
-- Returns the largest number index in t.
|
||||
|
||||
assert(type(t) == 'table')
|
||||
--
|
||||
local max_index = 0
|
||||
for k,v in pairs(t) do
|
||||
if type(k) == 'number' then
|
||||
|
@ -91,6 +100,8 @@ local function largest_number_index (t)
|
|||
end
|
||||
|
||||
local function nr_elements_in_table (t)
|
||||
assert(type(t) == 'table')
|
||||
--
|
||||
local k, count = nil, -1
|
||||
repeat
|
||||
k, count = next(t, k), count + 1
|
||||
|
|
|
@ -96,7 +96,6 @@ format_test {
|
|||
input = '\000',
|
||||
expect = '\'\\000\'',
|
||||
}
|
||||
|
||||
format_test {
|
||||
input = '\a\b\v\r\f',
|
||||
expect = '\'\\a\\b\\v\\r\\f\'',
|
||||
|
@ -107,6 +106,13 @@ format_test {
|
|||
expect = '\'ø\'',
|
||||
}
|
||||
|
||||
format_test {
|
||||
name = 'Malformed Unicode is escaped',
|
||||
input = '\000\001\003\012\169\003\000\030',
|
||||
expect = '\'\\000\\000\\001\\003\\012\\169\\003\\000\\030\'',
|
||||
}
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Primitive types
|
||||
|
||||
|
@ -414,6 +420,12 @@ SUITE:addTest('UseCase: Can load function from file that is shortly deleted', fu
|
|||
assert(true)
|
||||
end)
|
||||
|
||||
SUITE:addTest('UseCase: Can use pretty on loadstring block', function ()
|
||||
-- TODO: Move to more appropriate test module.
|
||||
format(loadstring 'hi = 0')
|
||||
assert(true)
|
||||
end)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
return SUITE
|
||||
|
|
Loading…
Reference in New Issue
Block a user