-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests, rockspec and Travis integration
- Loading branch information
1 parent
e561075
commit 88034b9
Showing
5 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: erlang | ||
|
||
env: | ||
- LUA="" | ||
- LUA="luajit" | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
install: | ||
- sudo apt-get install luajit | ||
- sudo apt-get install luarocks | ||
- sudo luarocks install luafilesystem | ||
- sudo luarocks install busted | ||
|
||
script: "busted spec" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package = "classic" | ||
version = "0.1-1" | ||
source = { | ||
url = "git://github.com/rxi/classic", | ||
branch = "master" | ||
} | ||
description = { | ||
summary = "Tiny class module for Lua", | ||
detailed = [[ | ||
A tiny class module for Lua. Attempts to stay simple and provide decent performance by avoiding unnecessary over-abstraction. | ||
]], | ||
homepage = "https://github.com/rxi/classic", | ||
license = "MIT" | ||
} | ||
dependencies = { | ||
"lua >= 5.1" | ||
} | ||
build = { | ||
type = "builtin", | ||
modules = { | ||
classic = "src/classic.lua" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Object = require "classic" | ||
|
||
-- BaseClass provides a say() method | ||
local BaseClass = Object:extend() | ||
function BaseClass:new(name) | ||
self._name = name | ||
end | ||
function BaseClass:get_name() | ||
return self._name | ||
end | ||
function BaseClass.say_something() | ||
return "something" | ||
end | ||
|
||
-- ClassOne extends BaseClass | ||
local ClassOne = BaseClass:extend() | ||
function ClassOne:new(name) | ||
ClassOne.super.new(self, name) | ||
end | ||
function ClassOne.say_something() | ||
return "something better" | ||
end | ||
|
||
-- ClassTwo extends BaseClass | ||
local ClassTwo = BaseClass:extend() | ||
function ClassTwo:new(name) | ||
if name == "wrong" then | ||
error({message = "Wrong value"}) | ||
end | ||
ClassTwo.super.new(self, name) | ||
end | ||
|
||
describe("classic #classic", function() | ||
describe("Base tests", function() | ||
|
||
it("Constructors should work", function() | ||
local class_one = ClassOne("Mark") | ||
local class_two = ClassTwo("John") | ||
|
||
assert.are.same("Mark", class_one:get_name()) | ||
assert.are.same("John", class_two:get_name()) | ||
end) | ||
it("Static method should work", function() | ||
local class_one = ClassOne("Mark") | ||
local class_two = ClassTwo("John") | ||
|
||
assert.are.same("something better", class_one:say_something()) | ||
assert.are.same("something", class_two:say_something()) | ||
end) | ||
it("Constructor returns error", function() | ||
local status, res = pcall(ClassTwo, "wrong") | ||
|
||
assert.falsy(status) | ||
assert.truthy(res) | ||
assert.are.same("Wrong value", res.message) | ||
end) | ||
|
||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,4 @@ function Object:__call(...) | |
end | ||
|
||
|
||
return Object | ||
return Object |