removed should from specs. fixes #3

This commit is contained in:
kikito 2012-10-29 21:11:20 +01:00
parent fa1ef6683e
commit d01950cee3

View File

@ -3,66 +3,60 @@ local inspect = require 'inspect'
context( 'inspect', function() context( 'inspect', function()
context('numbers', function() context('numbers', function()
test('Should work with integers', function() it('works', function()
assert_equal(inspect(1), "1") assert_equal(inspect(1), "1")
end)
test('Should work with decimals', function()
assert_equal(inspect(1.5), "1.5") assert_equal(inspect(1.5), "1.5")
end)
test('Should work with negative numbers', function()
assert_equal(inspect(-3.14), "-3.14") assert_equal(inspect(-3.14), "-3.14")
end) end)
end) end)
context('strings', function() context('strings', function()
test('Should put quotes around regular strings', function() it('puts quotes around regular strings', function()
assert_equal(inspect("hello"), '"hello"') assert_equal(inspect("hello"), '"hello"')
end) end)
test('Should put apostrophes around strings with quotes', function() it('puts apostrophes around strings with quotes', function()
assert_equal(inspect('I have "quotes"'), "'I have \"quotes\"'") assert_equal(inspect('I have "quotes"'), "'I have \"quotes\"'")
end) end)
test('Should use regular quotes if the string has both quotes and apostrophes', function() it('uses regular quotes if the string has both quotes and apostrophes', function()
assert_equal(inspect("I have \"quotes\" and 'apostrophes'"), '"I have \\"quotes\\" and \'apostrophes\'"') assert_equal(inspect("I have \"quotes\" and 'apostrophes'"), '"I have \\"quotes\\" and \'apostrophes\'"')
end) end)
test('Should escape escape control characters', function() it('escapes escape control characters', function()
assert_equal(inspect('I have \n new \n lines'), '"I have \\\\n new \\\\n lines"') assert_equal(inspect('I have \n new \n lines'), '"I have \\\\n new \\\\n lines"')
assert_equal(inspect('I have \b a back space'), '"I have \\\\b a back space"') assert_equal(inspect('I have \b a back space'), '"I have \\\\b a back space"')
end) end)
end) end)
test('Should work with nil', function() it('works with nil', function()
assert_equal(inspect(nil), 'nil') assert_equal(inspect(nil), 'nil')
end) end)
test('Should work with functions', function() it('works with functions', function()
assert_equal(inspect({ print, type, print }), '<1>{ <function 1>, <function 2>, <function 1> }') assert_equal(inspect({ print, type, print }), '<1>{ <function 1>, <function 2>, <function 1> }')
end) end)
test('Should work with booleans', function() it('works with booleans', function()
assert_equal(inspect(true), 'true') assert_equal(inspect(true), 'true')
assert_equal(inspect(false), 'false') assert_equal(inspect(false), 'false')
end) end)
context('tables', function() context('tables', function()
test('Should work with simple array-like tables', function() it('works with simple array-like tables', function()
assert_equal(inspect({1,2,3}), "<1>{ 1, 2, 3 }" ) assert_equal(inspect({1,2,3}), "<1>{ 1, 2, 3 }" )
end) end)
test('Should work with nested arrays', function() it('works with nested arrays', function()
assert_equal(inspect({'a','b','c', {'d','e'}, 'f'}), '<1>{ "a", "b", "c", <2>{ "d", "e" }, "f" }' ) assert_equal(inspect({'a','b','c', {'d','e'}, 'f'}), '<1>{ "a", "b", "c", <2>{ "d", "e" }, "f" }' )
end) end)
test('Should work with simple dictionary tables', function() it('works with simple dictionary tables', function()
assert_equal(inspect({a = 1, b = 2}), "<1>{\n a = 1,\n b = 2\n}") assert_equal(inspect({a = 1, b = 2}), "<1>{\n a = 1,\n b = 2\n}")
end) end)
test('Should sort keys in dictionary tables', function() it('sorts keys in dictionary tables', function()
local t = { 1,2,3, local t = { 1,2,3,
[print] = 1, ["buy more"] = 1, a = 1, [print] = 1, ["buy more"] = 1, a = 1,
[14] = 1, [{c=2}] = 1, [true]= 1 [14] = 1, [{c=2}] = 1, [true]= 1
@ -79,7 +73,7 @@ context( 'inspect', function()
}]]) }]])
end) end)
test('Should work with nested dictionary tables', function() it('works with nested dictionary tables', function()
assert_equal(inspect( {d=3, b={c=2}, a=1} ), [[<1>{ assert_equal(inspect( {d=3, b={c=2}, a=1} ), [[<1>{
a = 1, a = 1,
b = <2>{ b = <2>{
@ -89,7 +83,7 @@ context( 'inspect', function()
}]]) }]])
end) end)
test('Should work with hybrid tables', function() it('works with hybrid tables', function()
assert_equal(inspect({ 'a', {b = 1}, 2, c = 3, ['ahoy you'] = 4 }), [[<1>{ "a", <2>{ assert_equal(inspect({ 'a', {b = 1}, 2, c = 3, ['ahoy you'] = 4 }), [[<1>{ "a", <2>{
b = 1 b = 1
}, 2, }, 2,
@ -102,7 +96,7 @@ context( 'inspect', function()
local level5 = { 1,2,3, a = { b = { c = { d = { e = 5 } } } } } local level5 = { 1,2,3, a = { b = { c = { d = { e = 5 } } } } }
local keys = { [level5] = true } local keys = { [level5] = true }
test('Should have a default depth of 4', function() it('has a default depth of 4', function()
assert_equal(inspect(level5), [[<1>{ 1, 2, 3, assert_equal(inspect(level5), [[<1>{ 1, 2, 3,
a = <2>{ a = <2>{
b = <3>{ b = <3>{
@ -113,7 +107,7 @@ context( 'inspect', function()
} }
}]]) }]])
end) end)
test('Should be modifiable by the user', function() it('is modifiable by the user', function()
assert_equal(inspect(level5, 2), [[<1>{ 1, 2, 3, assert_equal(inspect(level5, 2), [[<1>{ 1, 2, 3,
a = <2>{ a = <2>{
b = {...} b = {...}
@ -137,7 +131,7 @@ context( 'inspect', function()
end) end)
test('Should respect depth on keys', function() it('respects depth on keys', function()
assert_equal(inspect(keys), [[<1>{ assert_equal(inspect(keys), [[<1>{
[<2>{ 1, 2, 3, [<2>{ 1, 2, 3,
a = <3>{ a = <3>{
@ -149,7 +143,7 @@ context( 'inspect', function()
}]]) }]])
end) end)
test('Should display <table x> instead of repeating an already existing table', function() it('displays <table x> instead of repeating an already existing table', function()
local a = { 1, 2, 3 } local a = { 1, 2, 3 }
local b = { 'a', 'b', 'c', a } local b = { 'a', 'b', 'c', a }
a[4] = b a[4] = b
@ -162,7 +156,7 @@ context( 'inspect', function()
context('metatables', function() context('metatables', function()
test('Should include the metatable as an extra hash attribute', function() it('includes the metatable as an extra hash attribute', function()
local foo = { foo = 1, __mode = 'v' } local foo = { foo = 1, __mode = 'v' }
local bar = setmetatable({a = 1}, foo) local bar = setmetatable({a = 1}, foo)
assert_equal(inspect(bar), [[<1>{ assert_equal(inspect(bar), [[<1>{
@ -174,7 +168,7 @@ context( 'inspect', function()
}]]) }]])
end) end)
test('Should include the __tostring metamethod if it exists', function() it('includes the __tostring metamethod if it exists', function()
local foo = { foo = 1, __tostring = function() return 'hello\nworld' end } local foo = { foo = 1, __tostring = function() return 'hello\nworld' end }
local bar = setmetatable({a = 1}, foo) local bar = setmetatable({a = 1}, foo)
assert_equal(inspect(bar), [[<1>{ -- hello\nworld assert_equal(inspect(bar), [[<1>{ -- hello\nworld
@ -186,7 +180,7 @@ context( 'inspect', function()
}]]) }]])
end) end)
test('Should not include an error string if __tostring metamethod throws an error', function() it('includes an error string if __tostring metamethod throws an error', function()
local foo = { foo = 1, __tostring = function() error('hello', 0) end } local foo = { foo = 1, __tostring = function() error('hello', 0) end }
local bar = setmetatable({a = 1}, foo) local bar = setmetatable({a = 1}, foo)
assert_equal(inspect(bar), [[<1>{ -- error: hello assert_equal(inspect(bar), [[<1>{ -- error: hello
@ -197,12 +191,6 @@ context( 'inspect', function()
} }
}]]) }]])
end) end)
end) end)
end) end)
end) end)