mirror of
https://github.com/TangentFoxy/inspect.lua.git
synced 2025-07-28 11:02:18 +00:00
organized tests into groups
This commit is contained in:
@@ -2,25 +2,58 @@ local inspect = require 'inspect'
|
||||
|
||||
context( 'inspect', function()
|
||||
|
||||
test('Should work with numbers', function()
|
||||
assert_equal(inspect(1), "1")
|
||||
assert_equal(inspect(1.5), "1.5")
|
||||
assert_equal(inspect(-3.14), "-3.14")
|
||||
context('numbers', function()
|
||||
test('Should work with integers', function()
|
||||
assert_equal(inspect(1), "1")
|
||||
end)
|
||||
|
||||
test('Should work with decimals', function()
|
||||
assert_equal(inspect(1.5), "1.5")
|
||||
end)
|
||||
|
||||
test('Should work with negative numbers', function()
|
||||
assert_equal(inspect(-3.14), "-3.14")
|
||||
end)
|
||||
end)
|
||||
|
||||
test('Should work with strings', function()
|
||||
assert_equal(inspect("hello"), '"hello"')
|
||||
assert_equal(inspect('I have "quotes"'), "'I have \"quotes\"'")
|
||||
context('strings', function()
|
||||
test('Should put quotes around regular strings', function()
|
||||
assert_equal(inspect("hello"), '"hello"')
|
||||
end)
|
||||
|
||||
test('Should put apostrophes around strings with quotes', function()
|
||||
assert_equal(inspect('I have "quotes"'), "'I have \"quotes\"'")
|
||||
end)
|
||||
|
||||
test('Should use 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 \n new \n lines'), '"I have \\\\n new \\\\n lines"')
|
||||
end)
|
||||
|
||||
test('Should escape escape control characters', function()
|
||||
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"')
|
||||
end)
|
||||
end)
|
||||
|
||||
test('Should work with simple array-like tables', function()
|
||||
assert_equal(inspect({1,2,3}), "{1, 2, 3}" )
|
||||
test('Should work with functions', function()
|
||||
assert_equal(inspect(print), '<function>')
|
||||
end)
|
||||
|
||||
test('Should work with nested arrays', function()
|
||||
assert_equal(inspect({1,2,3, {4,5}, 6}), "{1, 2, 3, {4, 5}, 6}" )
|
||||
test('Should work with booleans', function()
|
||||
assert_equal(inspect(true), 'true')
|
||||
assert_equal(inspect(false), 'false')
|
||||
end)
|
||||
|
||||
context('tables', function()
|
||||
|
||||
test('Should work with simple array-like tables', function()
|
||||
assert_equal(inspect({1,2,3}), "{1, 2, 3}" )
|
||||
end)
|
||||
|
||||
test('Should work with nested arrays', function()
|
||||
assert_equal(inspect({1,2,3, {4,5}, 6}), "{1, 2, 3, {4, 5}, 6}" )
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
|
Reference in New Issue
Block a user