renamed largparse -> argparse; imported testing setup from literal

This commit is contained in:
mpeterv
2014-01-12 23:41:46 +04:00
parent 5456f5a276
commit fe0b5f2874
12 changed files with 120 additions and 122 deletions

View File

@@ -1,4 +1,4 @@
local largparse = require "largparse"
local argparse = require "argparse"
describe("tests related to positional arguments", function()
local function curry(f, ...)
@@ -8,20 +8,20 @@ describe("tests related to positional arguments", function()
describe("passing correct arguments", function()
it("handles empty parser correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
local args = parser:parse({})
assert.same(args, {})
end)
it("handles one argument correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo"
local args = parser:parse({"bar"})
assert.same(args, {foo = "bar"})
end)
it("handles several arguments correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo1"
parser:argument "foo2"
local args = parser:parse({"bar", "baz"})
@@ -29,7 +29,7 @@ describe("tests related to positional arguments", function()
end)
it("handles multi-argument correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument("foo", {
args = "*"
})
@@ -38,7 +38,7 @@ describe("tests related to positional arguments", function()
end)
it("handles restrained multi-argument correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument("foo", {
args = "2-4"
})
@@ -47,7 +47,7 @@ describe("tests related to positional arguments", function()
end)
it("handles several multi-arguments correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument("foo1", {
args = "1-2"
})
@@ -61,14 +61,14 @@ describe("tests related to positional arguments", function()
end)
it("handles hyphen correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo"
local args = parser:parse({"-"})
assert.same(args, {foo = "-"})
end)
it("handles double hyphen correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo"
local args = parser:parse({"--", "-q"})
assert.same(args, {foo = "-q"})
@@ -76,45 +76,45 @@ describe("tests related to positional arguments", function()
end)
describe("passing incorrect arguments", function()
local old_parser = largparse.parser
local old_parser = argparse.parser
setup(function()
largparse.parser = old_parser:extends()
function largparse.parser:error(fmt, ...)
argparse.parser = old_parser:extends()
function argparse.parser:error(fmt, ...)
error(fmt:format(...))
end
end)
it("handles extra arguments with empty parser correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
assert.has_error(curry(parser.parse, parser, {"foo"}), "too many arguments")
end)
it("handles extra arguments with one argument correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo"
assert.has_error(curry(parser.parse, parser, {"bar", "baz"}), "too many arguments")
end)
it("handles sudden option correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo"
assert.has_error(curry(parser.parse, parser, {"-q"}), "unknown option -q")
end)
it("handles too few arguments with one argument correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo"
assert.has_error(curry(parser.parse, parser, {}), "too few arguments")
end)
it("handles extra arguments with several arguments correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo1"
parser:argument "foo2"
@@ -122,7 +122,7 @@ describe("tests related to positional arguments", function()
end)
it("handles too few arguments with several arguments correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument "foo1"
parser:argument "foo2"
@@ -130,7 +130,7 @@ describe("tests related to positional arguments", function()
end)
it("handles too few arguments with multi-argument correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument("foo", {
args = "+"
})
@@ -138,7 +138,7 @@ describe("tests related to positional arguments", function()
end)
it("handles too many arguments with multi-argument correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument("foo", {
args = "2-4"
})
@@ -146,7 +146,7 @@ describe("tests related to positional arguments", function()
end)
it("handles too few arguments with multi-argument correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument("foo", {
args = "2-4"
})
@@ -154,7 +154,7 @@ describe("tests related to positional arguments", function()
end)
it("handles too many arguments with several multi-arguments correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument("foo1", {
args = "1-2"
})
@@ -165,7 +165,7 @@ describe("tests related to positional arguments", function()
end)
it("handles too few arguments with several multi-arguments correctly", function()
local parser = largparse.parser()
local parser = argparse.parser()
parser:argument("foo1", {
args = "1-2"
})