Finished working on new interface and stuff

This commit is contained in:
mpeterv
2014-01-18 13:12:56 +04:00
parent dafff3d63e
commit d492dc5e0f
9 changed files with 264 additions and 690 deletions

View File

@@ -77,16 +77,6 @@ describe("tests related to positional arguments", function()
end)
describe("passing incorrect arguments", function()
local old_parser = argparse.parser
setup(function()
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 = argparse.parser()
@@ -132,17 +122,17 @@ describe("tests related to positional arguments", function()
it("handles too few arguments with multi-argument correctly", function()
local parser = argparse.parser()
parser:argument("foo", {
parser:argument "foo" {
args = "+"
})
}
assert.has_error(curry(parser.parse, parser, {}), "too few arguments")
end)
it("handles too many arguments with multi-argument correctly", function()
local parser = argparse.parser()
parser:argument("foo", {
parser:argument "foo" {
args = "2-4"
})
}
assert.has_error(curry(parser.parse, parser, {"foo", "bar", "baz", "qu", "quu"}), "too many arguments")
end)

View File

@@ -151,16 +151,6 @@ describe("tests related to options", function()
assert.same(args, {exclude = {{"Alice", "Bob"}, {"Emma", "Jacob"}}})
end)
it("handles multi-count option with optional argument correctly", function()
local parser = argparse.parser()
parser:option("-w", "--why", "--why-would-someone-use-this", {
count = "*",
args = "?"
})
local args = parser:parse({"-w", "-wfoo", "--why=because", "-ww"})
assert.same(args, {why = {{}, {"foo"}, {"because"}, {}, {}}})
end)
it("handles multi-count flag correctly", function()
local parser = argparse.parser()
parser:flag("-q", "--quiet", {
@@ -191,15 +181,6 @@ describe("tests related to options", function()
end)
describe("passing incorrect options", function()
local old_parser = argparse.parser
setup(function()
argparse.parser = old_parser:extends()
function argparse.parser:error(fmt, ...)
error(fmt:format(...))
end
end)
it("handles lack of required argument correctly", function()
local parser = argparse.parser()
parser:option("-s", "--server")
@@ -222,9 +203,17 @@ describe("tests related to options", function()
local parser = argparse.parser()
parser:flag("-q", "--quiet", {
count = 1,
no_overwrite = true
overwrite = false
})
assert.has_error(curry(parser.parse, parser, {"-qq"}), "option -q must be used at most 1 times")
end)
it("handles too few invocations correctly", function()
local parser = argparse.parser()
parser:option("-f", "--foo", {
count = "3-4"
})
assert.has_error(curry(parser.parse, parser, {"-fFOO", "-fBAR"}), "option -f must be used at least 3 times")
end)
end)
end)

View File

@@ -1,39 +0,0 @@
local utils = require "argparse.utils"
describe("tests related to utils.parse_boundaries", function()
it("handles * correctly", function()
local min, max = utils.parse_boundaries("*")
assert.equal(min, 0)
assert.equal(max, math.huge)
end)
it("handles + correctly", function()
local min, max = utils.parse_boundaries("+")
assert.equal(min, 1)
assert.equal(max, math.huge)
end)
it("handles ? correctly", function()
local min, max = utils.parse_boundaries("?")
assert.equal(min, 0)
assert.equal(max, 1)
end)
it("handles numbers correctly", function()
local min, max = utils.parse_boundaries(42)
assert.equal(min, 42)
assert.equal(max, 42)
end)
it("handles numbers+ correctly", function()
local min, max = utils.parse_boundaries("42+")
assert.equal(min, 42)
assert.equal(max, math.huge)
end)
it("handles ranges correctly", function()
local min, max = utils.parse_boundaries("42-96")
assert.equal(min, 42)
assert.equal(max, 96)
end)
end)