Skip to content

Commit

Permalink
Merge 9a17acd into af60264
Browse files Browse the repository at this point in the history
  • Loading branch information
sveyret committed Jul 21, 2022
2 parents af60264 + 9a17acd commit a43211a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ see [CONTRIBUTING.md](CONTRIBUTING.md#release-instructions-for-a-new-version) fo
[#431](https://github.com/lunarmodules/Penlight/pull/431)
- feat: `app.require_here` now follows symlink'd main modules to their directory
[#423](https://github.com/lunarmodules/Penlight/pull/423)
- fix: `pretty.write` invalid order function for sorting
[#430](https://github.com/lunarmodules/Penlight/pull/430)
- fix: `compat.warn` raised write guard warning in OpenResty
[#414](https://github.com/lunarmodules/Penlight/pull/414)
- feat: `utils.enum` now accepts hash tables, to enable better error handling
Expand Down
7 changes: 4 additions & 3 deletions lua/pl/pretty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ function pretty.write (tbl,space,not_clever)
end
end
table.sort(ordered_keys, function (a, b)
if type(a) == type(b) and type(a) == 'string' then
return a < b
if type(a) == type(b) then
return tostring(a) < tostring(b)
else
return type(a) < type(b)
end
return type(a) == 'boolean' or (type(b) ~= 'boolean' and type(a) == 'table')
end)
local function write_entry (key, val)
local tkey = type(key)
Expand Down
4 changes: 2 additions & 2 deletions tests/test-pretty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ asserteq( pretty.write(t1,""), [[{{},{}}]] )

-- Check that write correctly print table with non number or string as keys

t1 = { [true] = "boolean", a = "a", b = "b", [1] = 1, [0] = 0 }
asserteq( pretty.write(t1,""), [[{1,["true"]="boolean",a="a",b="b",[0]=0}]] )
t1 = { [true] = "boolean", [false] = "untrue", a = "a", b = "b", [1] = 1, [0] = 0 }
asserteq( pretty.write(t1,""), [[{1,["false"]="untrue",["true"]="boolean",a="a",b="b",[0]=0}]] )


-- Check number formatting
Expand Down

0 comments on commit a43211a

Please sign in to comment.