Improved sorting.
This commit is contained in:
parent
3d6c7dbfbc
commit
6bd797c75e
15
README.md
15
README.md
|
@ -89,7 +89,9 @@ I'm looking into implementing following features:
|
||||||
non-breaking strings. Attempt to break near whitespace.
|
non-breaking strings. Attempt to break near whitespace.
|
||||||
- Attempt to fit output within a predefined width limit. Default to 80.
|
- Attempt to fit output within a predefined width limit. Default to 80.
|
||||||
- Find a better name than `pretty`.
|
- Find a better name than `pretty`.
|
||||||
- Add options for colored output, and allow custom formatting.
|
- Add option for colored output. Primarily syntax highlighting, but also
|
||||||
|
[BlueJ-style](www.bluej.org/about.html) scope highlighting, with some faint
|
||||||
|
background colors.
|
||||||
- Look more into `string.dump` in the core library.
|
- Look more into `string.dump` in the core library.
|
||||||
- Better support upvalues for in functions. Complete support is impossible
|
- Better support upvalues for in functions. Complete support is impossible
|
||||||
without traversing the original code or inspecting the intermediate
|
without traversing the original code or inspecting the intermediate
|
||||||
|
@ -98,11 +100,12 @@ I'm looking into implementing following features:
|
||||||
|
|
||||||
## Other pretty printers
|
## Other pretty printers
|
||||||
|
|
||||||
`pretty` is a large and slow library, and is not designed for serialization
|
`pretty` is large, slow, and requires the debug library to work. It's not
|
||||||
purposes, nor is `pretty` concerned with offering the same level of
|
designed for serialization purposes, nor is it concerned with offering the same
|
||||||
customization as other libraries do.
|
level of customization as other libraries do.
|
||||||
|
|
||||||
Luckily Lua has a large library of pretty printers and serialization libraries:
|
If you want a sleek, fast, customizable or embeddable library, there are other
|
||||||
|
options. Lua has a large library of pretty printers and serialization libraries:
|
||||||
|
|
||||||
- [inspect.lua](github.com/kikito/inspect.lua): One of the classic debugging
|
- [inspect.lua](github.com/kikito/inspect.lua): One of the classic debugging
|
||||||
pretty printers.
|
pretty printers.
|
||||||
|
@ -114,4 +117,4 @@ Luckily Lua has a large library of pretty printers and serialization libraries:
|
||||||
- [binser](github.com/bakpakin/binser): Library for special purpose
|
- [binser](github.com/bakpakin/binser): Library for special purpose
|
||||||
serialization.
|
serialization.
|
||||||
|
|
||||||
Others can be found at [the lua-users wiki](lua-users.org/wiki/TableSerialization).
|
Find others at [the lua-users wiki](lua-users.org/wiki/TableSerialization).
|
||||||
|
|
|
@ -82,8 +82,11 @@ local function padnum(d)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function alphanum_compare_strings (a, b)
|
local function alphanum_compare_strings (a, b)
|
||||||
return tostring(a):gsub("%.?%d+", padnum)..("%3d"):format(#b)
|
local a_padded = tostring(a):gsub("%.?%d+", padnum)..("\0%3d"):format(#b)
|
||||||
< tostring(b):gsub("%.?%d+", padnum)..("%3d"):format(#a)
|
local b_padded = tostring(b):gsub("%.?%d+", padnum)..("\0%3d"):format(#a)
|
||||||
|
local A_padded, B_padded = a_padded:upper(), b_padded:upper()
|
||||||
|
if A_padded == B_padded then return a_padded < b_padded end
|
||||||
|
return A_padded < B_padded
|
||||||
end
|
end
|
||||||
|
|
||||||
local function compare_key_value_pairs (a, b)
|
local function compare_key_value_pairs (a, b)
|
||||||
|
|
|
@ -224,13 +224,11 @@ format_test {
|
||||||
expect = '{ a = { 1, 2, 3 }, b = { 4, 5, 6 } }',
|
expect = '{ a = { 1, 2, 3 }, b = { 4, 5, 6 } }',
|
||||||
}
|
}
|
||||||
|
|
||||||
if HAS_UNICODE_IDEN then
|
|
||||||
format_test {
|
format_test {
|
||||||
name = 'Unicode characters can be used as string keys in tables',
|
name = 'Unicode characters can be used as string keys in tables',
|
||||||
input = loadstring 'return { a = 1, ψ = 2 }' (),
|
input = { ['a'] = 1, ['ψ'] = 2 },
|
||||||
expect = '{ a = 1, ψ = 2 }',
|
expect = '{ a = 1, ψ = 2 }',
|
||||||
}
|
}
|
||||||
end
|
|
||||||
|
|
||||||
format_test {
|
format_test {
|
||||||
input = { [100] = 'Hi', [300] = 'Hello' },
|
input = { [100] = 'Hi', [300] = 'Hello' },
|
||||||
|
@ -308,17 +306,15 @@ format_test {
|
||||||
expect = '{\n { a = \'hello\', b = \'hi\' },\n { a = \'hi\', b = \'hello\' }\n}',
|
expect = '{\n { a = \'hello\', b = \'hi\' },\n { a = \'hi\', b = \'hello\' }\n}',
|
||||||
}
|
}
|
||||||
|
|
||||||
if HAS_UNICODE_IDEN then
|
|
||||||
format_test {
|
format_test {
|
||||||
name = 'Proper alignment when using unicode characters as keys',
|
name = 'Proper alignment when using unicode characters as keys',
|
||||||
input = loadstring [[return {
|
input = {
|
||||||
djævle = 'dyr?',
|
['djævle'] = 'dyr?',
|
||||||
europa = 'måne',
|
['europa'] = 'måne',
|
||||||
øå = 'en å på en ø?',
|
['øå'] = 'en å på en ø?',
|
||||||
}]] (),
|
},
|
||||||
expect = '{\n djævle = \'dyr?\',\n europa = \'måne\',\n øå = \'en å på en ø?\'\n}',
|
expect = '{\n djævle = \'dyr?\',\n europa = \'måne\',\n øå = \'en å på en ø?\'\n}',
|
||||||
}
|
}
|
||||||
end
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Table recursion
|
-- Table recursion
|
||||||
|
|
|
@ -47,6 +47,12 @@ format_test {
|
||||||
expect = '{ b = true, a = {} }',
|
expect = '{ b = true, a = {} }',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
format_test {
|
||||||
|
name = 'Keys should be sorted such that uppercase and lowercase lies near each other',
|
||||||
|
input = { Dave = 1, dave = 2, mary = 3, Mary = 4, Adam = 5, adam = 6 },
|
||||||
|
expect = '{\n Adam = 5,\n adam = 6,\n Dave = 1,\n dave = 2,\n Mary = 4,\n mary = 3\n}',
|
||||||
|
}
|
||||||
|
|
||||||
format_test {
|
format_test {
|
||||||
input = { a = {}, b = true, b1 = false },
|
input = { a = {}, b = true, b1 = false },
|
||||||
expect = '{ b = true, b1 = false, a = {} }',
|
expect = '{ b = true, b1 = false, a = {} }',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user