Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve path code and global visibility
- Loading branch information
Showing
2 changed files
with
26 additions
and
19 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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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) |