lunarmodules / luassert

Assertion library for Lua
MIT License
202 stars 77 forks source link

Add table format parameter to show table recursion #119

Closed o-lim closed 9 years ago

o-lim commented 9 years ago

This adds the TableFormatShowRecursion parameter to enable showing of table recursion when a table is formatted for display. This parameter is set to false by default.

  it("Test recursive table - show recursion", function()
    local t = {1,2}
    t[3] = t
    assert:set_parameter("TableFormatShowRecursion", true)
    assert.is.equal({}, t)
  end)
Failure → spec/test_spec.lua @ 1
Test recursive table - show recursion
spec/test_spec.lua:5: Expected objects to be equal.
Passed in:
(table) {
  [1] = 1
  [2] = 2
  [3] = { ... recursive } }
Expected:
(table) { }

vs

  it("Test recursive table - no show recursion", function()
    local t = {1,2}
    t[3] = t
    assert:set_parameter("TableFormatShowRecursion", false)  -- this is the default value
    assert.is.equal({}, t)
  end)
Failure → spec/test_spec.lua @ 1
Test recursive table - no show recursion
spec/test_spec.lua:5: Expected objects to be equal.
Passed in:
(table) {
  [1] = 1
  [2] = 2
  [3] = {
    [1] = 1
    [2] = 2
    [3] = {
      [1] = 1
      [2] = 2
      [3] = { ... more } } } }
Expected:
(table) { }