moonscript/spec/cmd_spec.moon

131 lines
3.6 KiB
Plaintext
Raw Normal View History

2014-06-18 16:23:41 +00:00
import with_dev from require "spec.helpers"
2014-06-18 16:23:41 +00:00
-- TODO: add specs for windows equivalents
describe "moonc", ->
local moonc
dev_loaded = with_dev ->
moonc = require "moonscript.cmd.moonc"
2016-04-14 02:30:03 +00:00
same = (fn, a, b) ->
2014-06-18 16:23:41 +00:00
assert.same b, fn a
it "should normalize dir", ->
same moonc.normalize_dir, "hello/world/", "hello/world/"
same moonc.normalize_dir, "hello/world//", "hello/world/"
same moonc.normalize_dir, "", "/" -- wrong
same moonc.normalize_dir, "hello", "hello/"
it "should parse dir", ->
same moonc.parse_dir, "/hello/world/file", "/hello/world/"
same moonc.parse_dir, "/hello/world/", "/hello/world/"
same moonc.parse_dir, "world", ""
same moonc.parse_dir, "", ""
it "should parse file", ->
same moonc.parse_file, "/hello/world/file", "file"
same moonc.parse_file, "/hello/world/", ""
same moonc.parse_file, "world", "world"
same moonc.parse_file, "", ""
it "convert path", ->
same moonc.convert_path, "test.moon", "test.lua"
same moonc.convert_path, "/hello/file.moon", "/hello/file.lua"
same moonc.convert_path, "/hello/world/file", "/hello/world/file.lua"
2014-06-18 17:14:26 +00:00
it "calculate target", ->
p = moonc.path_to_target
assert.same "test.lua", p "test.moon"
assert.same "hello/world.lua", p "hello/world.moon"
assert.same "compiled/test.lua", p "test.moon", "compiled"
assert.same "/home/leafo/test.lua", p "/home/leafo/test.moon"
assert.same "compiled/test.lua", p "/home/leafo/test.moon", "compiled"
assert.same "/compiled/test.lua", p "/home/leafo/test.moon", "/compiled/"
assert.same "moonscript/hello.lua", p "moonscript/hello.moon", nil, "moonscript"
assert.same "out/moonscript/hello.lua", p "moonscript/hello.moon", "out", "moonscript"
assert.same "out/moonscript/package/hello.lua",
p "moonscript/package/hello.moon", "out", "moonscript/"
assert.same "/out/moonscript/package/hello.lua",
p "/home/leafo/moonscript/package/hello.moon", "/out", "/home/leafo/moonscript"
2014-06-18 16:48:25 +00:00
it "should compile file text", ->
2014-06-18 16:23:41 +00:00
assert.same {
[[return print('hello')]]
}, {
2015-02-28 19:47:58 +00:00
moonc.compile_file_text "print'hello'", fname: "test.moon"
2014-06-18 16:23:41 +00:00
}
2016-04-14 02:30:03 +00:00
describe "watcher", ->
describe "inotify watcher", ->
it "gets dirs", ->
2016-04-14 02:49:16 +00:00
import InotifyWacher from require "moonscript.cmd.watchers"
2016-04-14 02:30:03 +00:00
watcher = InotifyWacher {
{"hello.moon", "hello.lua"}
{"cool/no.moon", "cool/no.lua"}
}
assert.same {
"./"
"cool/"
}, watcher\get_dirs!
2016-04-16 06:51:27 +00:00
describe "parse args", ->
2016-04-17 06:58:36 +00:00
it "parses spec", ->
import parse_spec from require "moonscript.cmd.args"
spec = parse_spec "lt:o:X"
assert.same {
X: {}
o: {value: true}
t: {value: true}
l: {}
}, spec
2016-04-16 06:51:27 +00:00
it "parses arguments", ->
2016-04-17 06:58:36 +00:00
import parse_arguments from require "moonscript.cmd.args"
2016-04-16 06:51:27 +00:00
out, res = parse_arguments {
2016-04-17 06:58:36 +00:00
"ga:p"
2016-04-16 06:51:27 +00:00
print: "p"
}, {"hello", "word", "-gap"}
assert.same {
g: true
a: true
p: true
}, out
2016-04-14 02:30:03 +00:00
2014-06-18 16:23:41 +00:00
describe "stubbed lfs", ->
local dirs
before_each ->
dirs = {}
package.loaded.lfs = nil
dev_loaded["moonscript.cmd.moonc"] = nil
2014-06-18 16:23:41 +00:00
package.loaded.lfs = {
mkdir: (dir) -> table.insert dirs, dir
attributes: -> "directory"
}
moonc = require "moonscript.cmd.moonc"
after_each ->
package.loaded.lfs = nil
dev_loaded["moonscript.cmd.moonc"] = nil
2014-06-18 16:23:41 +00:00
moonc = require "moonscript.cmd.moonc"
it "should make directory", ->
moonc.mkdir "hello/world/directory"
assert.same {
"hello"
"hello/world"
"hello/world/directory"
}, dirs