andrew-d/lua-ext — pull request #1 by ryankoppenhaver (2013-09-14 04:59:03+00:00)
Title: fix test failures due to assumptions on pairs() ordering

(This is a bit verbose; I'm trying to make sure I've got all my ducks in a row because I don't know Lua all that well.)

I'm getting three test failures when running busted. Looks like the tests are making assumptions about the order of the values coming out of `tablex.keys()`, `tablex.values()` and `Set:__tostring()`, all of which call `pairs()` internally. From http://www.lua.org/pil/7.3.html:

> The `pairs` function, which iterates over all elements in a table, is similar [to `ipairs`], except that the iterator function is the `next` function, which [...] returns a next key in the table, **in an arbitrary order**.

(Emphasis mine.)

This patch fixes the tests for `tablex`, but I didn't do the one for `set`, as I'm not sure if it'd be a good idea to sort the keys before building the string, or let it remain arbitrary (making it a bit more of a pain to test).

Here's the output from busted:

Failure → ./spec/tablex_spec.lua @ 116
will return the keys of a table
./spec/tablex_spec.lua:119: Expected objects to be the same. Passed in:
(table): {
[1] = 'asdf'
[2] = 'foo' }
Expected:
(table): {
[1] = 'foo'
[2] = 'asdf' }

Failure → ./spec/tablex_spec.lua @ 130
will return the values of a table
./spec/tablex_spec.lua:133: Expected objects to be the same. Passed in:
(table): {
[1] = 'baz'
[2] = 'bar' }
Expected:
(table): {
[1] = 'bar'
[2] = 'baz' }

Failure → ./spec/set_spec.lua @ 116
will have a sensible string representation
./spec/set_spec.lua:119: Expected objects to be equal. Passed in:
(string) '[5, 6, 4, 3]'
Expected:
(string) '[3, 4, 5, 6]'