Skip to content

Commit

Permalink
Improve path code and global visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed Oct 12, 2010
1 parent edf60c2 commit 6866f3f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -46,12 +46,12 @@ Then, running the Ruby test suite is easy:


### Lua ### ### Lua ###


The Lua test depends on [Telescope](http://telescope.luaforge.net/), The Lua test depends on
[Penlight](http://stevedonovan.github.com/Penlight/),
[Telescope](http://telescope.luaforge.net/),
[jason4lua](http://json.luaforge.net/), and [jason4lua](http://json.luaforge.net/), and
[Lua Haml](http://github.com/norman/lua-haml). Install and [Lua Haml](http://github.com/norman/lua-haml). Install and run `tsc
run `tsc lua_haml_spec.lua`. lua_haml_spec.lua`.

## Contributing ##


### Getting it ### ### Getting it ###


Expand Down
35 changes: 21 additions & 14 deletions lua_haml_spec.lua
@@ -1,30 +1,37 @@
require 'luarocks.require' local dir = require 'pl.dir'
require 'json' local haml = require 'haml'
require 'telescope' local json = require 'json'
require 'haml' local path = require 'pl.path'
local telescope = require 'telescope'
local assert = assert
local describe = telescope.describe
local getinfo = debug.getinfo
local it = telescope.it
local open = io.open
local pairs = pairs

module('hamlspec')


local function get_tests(filename) local function get_tests(filename)
local self = debug.getinfo(1).short_src local me = path.abspath(getinfo(1).source:match("@(.*)$"))
if self:match("/") then return "./" .. self:gsub("[^/]*%.lua$", "/" .. filename) return path.join(path.dirname(me), filename)
elseif self:match("\\") then return self:gsub("[^\\]*%.lua$", "\\" .. filename)
else return filename
end
end end


local fh = assert(io.open(get_tests("tests.json"))) local json_file = get_tests("tests.json")
local input = fh:read '*a' local file = assert(open(json_file))
fh:close() local input = file:read '*a'
file:close()


local contexts = json.decode(input) local contexts = json.decode(input)


describe("LuaHaml", function() describe("LuaHaml", function()
for context, expectations in pairs(contexts) do for context, expectations in pairs(contexts) do
describe("When handling " .. context, function() describe("When handling " .. context, function()
for name, exp in pairs(expectations) do for name, exp in pairs(expectations) do
it(string.format("should correctly render %s", name), function() it(("should correctly render %s"):format(name), function()
assert_equal(haml.render(exp.haml, exp.config or {}, exp.locals or {}), exp.html) assert_equal(haml.render(exp.haml, exp.config or {}, exp.locals or {}), exp.html)
end) end)
end end
end) end)
end end
end) end)

0 comments on commit 6866f3f

Please sign in to comment.