use busted for specs instead of telescope

This commit is contained in:
kikito 2013-01-20 17:07:41 +01:00
parent e2fe8827e4
commit 0571e63e01
3 changed files with 38 additions and 38 deletions

View File

@ -7,6 +7,6 @@ env:
install: install:
- sudo apt-get install luajit - sudo apt-get install luajit
- sudo apt-get install luarocks - sudo apt-get install luarocks
- sudo luarocks install telescope - sudo luarocks install busted
script: "tsc -f spec/*" script: "busted"

View File

@ -105,8 +105,8 @@ Also, make sure to read the license file; the text of that license file must app
Specs Specs
===== =====
This project uses [telescope](https://github.com/norman/telescope) for its specs. If you want to run the specs, you will have to install telescope first. Then just execute the following from the root inspect folder: This project uses [busted](http://olivinelabs.com/busted/) for its specs. If you want to run the specs, you will have to install telescope first. Then just execute the following from the root inspect folder:
tsc -f spec/* busted

View File

@ -1,59 +1,59 @@
local inspect = require 'inspect' local inspect = require 'inspect'
context( 'inspect', function() describe( 'inspect', function()
context('numbers', function() describe('numbers', function()
it('works', function() it('works', function()
assert_equal(inspect(1), "1") assert.equals(inspect(1), "1")
assert_equal(inspect(1.5), "1.5") assert.equals(inspect(1.5), "1.5")
assert_equal(inspect(-3.14), "-3.14") assert.equals(inspect(-3.14), "-3.14")
end) end)
end) end)
context('strings', function() describe('strings', function()
it('puts quotes around regular strings', function() it('puts quotes around regular strings', function()
assert_equal(inspect("hello"), '"hello"') assert.equals(inspect("hello"), '"hello"')
end) end)
it('puts apostrophes around strings with quotes', function() it('puts apostrophes around strings with quotes', function()
assert_equal(inspect('I have "quotes"'), "'I have \"quotes\"'") assert.equals(inspect('I have "quotes"'), "'I have \"quotes\"'")
end) end)
it('uses 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.equals(inspect("I have \"quotes\" and 'apostrophes'"), '"I have \\"quotes\\" and \'apostrophes\'"')
end) end)
it('escapes 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.equals(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.equals(inspect('I have \b a back space'), '"I have \\\\b a back space"')
end) end)
end) end)
it('works with nil', function() it('works with nil', function()
assert_equal(inspect(nil), 'nil') assert.equals(inspect(nil), 'nil')
end) end)
it('works with functions', function() it('works with functions', function()
assert_equal(inspect({ print, type, print }), '{ <function 1>, <function 2>, <function 1> }') assert.equals(inspect({ print, type, print }), '{ <function 1>, <function 2>, <function 1> }')
end) end)
it('works with booleans', function() it('works with booleans', function()
assert_equal(inspect(true), 'true') assert.equals(inspect(true), 'true')
assert_equal(inspect(false), 'false') assert.equals(inspect(false), 'false')
end) end)
context('tables', function() describe('tables', function()
it('works with simple array-like tables', function() it('works with simple array-like tables', function()
assert_equal(inspect({1,2,3}), "{ 1, 2, 3 }" ) assert.equals(inspect({1,2,3}), "{ 1, 2, 3 }" )
end) end)
it('works with nested arrays', function() it('works with nested arrays', function()
assert_equal(inspect({'a','b','c', {'d','e'}, 'f'}), '{ "a", "b", "c", { "d", "e" }, "f" }' ) assert.equals(inspect({'a','b','c', {'d','e'}, 'f'}), '{ "a", "b", "c", { "d", "e" }, "f" }' )
end) end)
it('works with simple dictionary tables', function() it('works with simple dictionary tables', function()
assert_equal(inspect({a = 1, b = 2}), "{\n a = 1,\n b = 2\n}") assert.equals(inspect({a = 1, b = 2}), "{\n a = 1,\n b = 2\n}")
end) end)
it('sorts keys in dictionary tables', function() it('sorts keys in dictionary tables', function()
@ -61,7 +61,7 @@ context( 'inspect', function()
[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
} }
assert_equal(inspect(t), [[{ 1, 2, 3, assert.equals(inspect(t), [[{ 1, 2, 3,
[14] = 1, [14] = 1,
[true] = 1, [true] = 1,
a = 1, a = 1,
@ -74,7 +74,7 @@ context( 'inspect', function()
end) end)
it('works with nested dictionary tables', function() it('works with nested dictionary tables', function()
assert_equal(inspect( {d=3, b={c=2}, a=1} ), [[{ assert.equals(inspect( {d=3, b={c=2}, a=1} ), [[{
a = 1, a = 1,
b = { b = {
c = 2 c = 2
@ -84,7 +84,7 @@ context( 'inspect', function()
end) end)
it('works with hybrid tables', function() it('works with hybrid tables', function()
assert_equal(inspect({ 'a', {b = 1}, 2, c = 3, ['ahoy you'] = 4 }), [[{ "a", { assert.equals(inspect({ 'a', {b = 1}, 2, c = 3, ['ahoy you'] = 4 }), [[{ "a", {
b = 1 b = 1
}, 2, }, 2,
["ahoy you"] = 4, ["ahoy you"] = 4,
@ -92,12 +92,12 @@ context( 'inspect', function()
}]]) }]])
end) end)
context('depth', function() describe('depth', 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 }
it('has infinite depth by default', function() it('has infinite depth by default', function()
assert_equal(inspect(level5), [[{ 1, 2, 3, assert.equals(inspect(level5), [[{ 1, 2, 3,
a = { a = {
b = { b = {
c = { c = {
@ -110,16 +110,16 @@ context( 'inspect', function()
}]]) }]])
end) end)
it('is modifiable by the user', function() it('is modifiable by the user', function()
assert_equal(inspect(level5, 2), [[{ 1, 2, 3, assert.equals(inspect(level5, 2), [[{ 1, 2, 3,
a = { a = {
b = {...} b = {...}
} }
}]]) }]])
assert_equal(inspect(level5, 1), [[{ 1, 2, 3, assert.equals(inspect(level5, 1), [[{ 1, 2, 3,
a = {...} a = {...}
}]]) }]])
assert_equal(inspect(level5, 0), "{...}") assert.equals(inspect(level5, 0), "{...}")
assert_equal(inspect(level5, 4), [[{ 1, 2, 3, assert.equals(inspect(level5, 4), [[{ 1, 2, 3,
a = { a = {
b = { b = {
c = { c = {
@ -132,7 +132,7 @@ context( 'inspect', function()
end) end)
it('respects depth on keys', function() it('respects depth on keys', function()
assert_equal(inspect(keys, 4), [[{ assert.equals(inspect(keys, 4), [[{
[{ 1, 2, 3, [{ 1, 2, 3,
a = { a = {
b = { b = {
@ -149,17 +149,17 @@ context( 'inspect', function()
a[4] = b a[4] = b
a[5] = a a[5] = a
a[6] = b a[6] = b
assert_equal(inspect(a), '<1>{ 1, 2, 3, <2>{ "a", "b", "c", <table 1> }, <table 1>, <table 2> }') assert.equals(inspect(a), '<1>{ 1, 2, 3, <2>{ "a", "b", "c", <table 1> }, <table 1>, <table 2> }')
end) end)
end) end)
context('metatables', function() describe('metatables', function()
it('includes 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), [[{ assert.equals(inspect(bar), [[{
a = 1, a = 1,
<metatable> = { <metatable> = {
__mode = "v", __mode = "v",
@ -171,7 +171,7 @@ context( 'inspect', function()
it('includes 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), [[{ -- hello\nworld assert.equals(inspect(bar), [[{ -- hello\nworld
a = 1, a = 1,
<metatable> = { <metatable> = {
__tostring = <function 1>, __tostring = <function 1>,
@ -183,7 +183,7 @@ context( 'inspect', function()
it('includes 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), [[{ -- error: hello assert.equals(inspect(bar), [[{ -- error: hello
a = 1, a = 1,
<metatable> = { <metatable> = {
__tostring = <function 1>, __tostring = <function 1>,