mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
fixed ugly curry in tests
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
local argparse = require "argparse"
|
local argparse = require "argparse"
|
||||||
|
|
||||||
describe("tests related to positional arguments", function()
|
describe("tests related to positional arguments", function()
|
||||||
local function curry(f, ...)
|
|
||||||
local args = {...}
|
|
||||||
local unpack = unpack or table.unpack
|
|
||||||
return function() return f(unpack(args)) end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe("passing correct arguments", function()
|
describe("passing correct arguments", function()
|
||||||
it("handles empty parser correctly", function()
|
it("handles empty parser correctly", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
@@ -80,28 +74,28 @@ describe("tests related to positional arguments", function()
|
|||||||
it("handles extra arguments with empty parser correctly", function()
|
it("handles extra arguments with empty parser correctly", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
|
|
||||||
assert.has_error(curry(parser.parse, parser, {"foo"}), "too many arguments")
|
assert.has_error(function() parser:parse{"foo"} end, "too many arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles extra arguments with one argument correctly", function()
|
it("handles extra arguments with one argument correctly", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
parser:argument "foo"
|
parser:argument "foo"
|
||||||
|
|
||||||
assert.has_error(curry(parser.parse, parser, {"bar", "baz"}), "too many arguments")
|
assert.has_error(function() parser:parse{"bar", "baz"} end, "too many arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles sudden option correctly", function()
|
it("handles sudden option correctly", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
parser:argument "foo"
|
parser:argument "foo"
|
||||||
|
|
||||||
assert.has_error(curry(parser.parse, parser, {"-q"}), "unknown option -q")
|
assert.has_error(function() parser:parse{"-q"} end, "unknown option -q")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too few arguments with one argument correctly", function()
|
it("handles too few arguments with one argument correctly", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
parser:argument "foo"
|
parser:argument "foo"
|
||||||
|
|
||||||
assert.has_error(curry(parser.parse, parser, {}), "too few arguments")
|
assert.has_error(function() parser:parse{} end, "too few arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles extra arguments with several arguments correctly", function()
|
it("handles extra arguments with several arguments correctly", function()
|
||||||
@@ -109,7 +103,7 @@ describe("tests related to positional arguments", function()
|
|||||||
parser:argument "foo1"
|
parser:argument "foo1"
|
||||||
parser:argument "foo2"
|
parser:argument "foo2"
|
||||||
|
|
||||||
assert.has_error(curry(parser.parse, parser, {"bar", "baz", "qu"}), "too many arguments")
|
assert.has_error(function() parser:parse{"bar", "baz", "qu"} end, "too many arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too few arguments with several arguments correctly", function()
|
it("handles too few arguments with several arguments correctly", function()
|
||||||
@@ -117,7 +111,7 @@ describe("tests related to positional arguments", function()
|
|||||||
parser:argument "foo1"
|
parser:argument "foo1"
|
||||||
parser:argument "foo2"
|
parser:argument "foo2"
|
||||||
|
|
||||||
assert.has_error(curry(parser.parse, parser, {"bar"}), "too few arguments")
|
assert.has_error(function() parser:parse{"bar"} end, "too few arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too few arguments with multi-argument correctly", function()
|
it("handles too few arguments with multi-argument correctly", function()
|
||||||
@@ -125,7 +119,7 @@ describe("tests related to positional arguments", function()
|
|||||||
parser:argument "foo" {
|
parser:argument "foo" {
|
||||||
args = "+"
|
args = "+"
|
||||||
}
|
}
|
||||||
assert.has_error(curry(parser.parse, parser, {}), "too few arguments")
|
assert.has_error(function() parser:parse{} end, "too few arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too many arguments with multi-argument correctly", function()
|
it("handles too many arguments with multi-argument correctly", function()
|
||||||
@@ -133,7 +127,7 @@ describe("tests related to positional arguments", function()
|
|||||||
parser:argument "foo" {
|
parser:argument "foo" {
|
||||||
args = "2-4"
|
args = "2-4"
|
||||||
}
|
}
|
||||||
assert.has_error(curry(parser.parse, parser, {"foo", "bar", "baz", "qu", "quu"}), "too many arguments")
|
assert.has_error(function() parser:parse{"foo", "bar", "baz", "qu", "quu"} end, "too many arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too few arguments with multi-argument correctly", function()
|
it("handles too few arguments with multi-argument correctly", function()
|
||||||
@@ -141,7 +135,7 @@ describe("tests related to positional arguments", function()
|
|||||||
parser:argument("foo", {
|
parser:argument("foo", {
|
||||||
args = "2-4"
|
args = "2-4"
|
||||||
})
|
})
|
||||||
assert.has_error(curry(parser.parse, parser, {"foo"}), "too few arguments")
|
assert.has_error(function() parser:parse{"foo"} end, "too few arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too many arguments with several multi-arguments correctly", function()
|
it("handles too many arguments with several multi-arguments correctly", function()
|
||||||
@@ -152,7 +146,7 @@ describe("tests related to positional arguments", function()
|
|||||||
parser:argument("foo2", {
|
parser:argument("foo2", {
|
||||||
args = "0-1"
|
args = "0-1"
|
||||||
})
|
})
|
||||||
assert.has_error(curry(parser.parse, parser, {"foo", "bar", "baz", "qu"}), "too many arguments")
|
assert.has_error(function() parser:parse{"foo", "bar", "baz", "qu"} end, "too many arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too few arguments with several multi-arguments correctly", function()
|
it("handles too few arguments with several multi-arguments correctly", function()
|
||||||
@@ -163,7 +157,7 @@ describe("tests related to positional arguments", function()
|
|||||||
parser:argument("foo2", {
|
parser:argument("foo2", {
|
||||||
args = "*"
|
args = "*"
|
||||||
})
|
})
|
||||||
assert.has_error(curry(parser.parse, parser, {}), "too few arguments")
|
assert.has_error(function() parser:parse{} end, "too few arguments")
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@@ -1,12 +1,6 @@
|
|||||||
local argparse = require "argparse"
|
local argparse = require "argparse"
|
||||||
|
|
||||||
describe("tests related to options", function()
|
describe("tests related to options", function()
|
||||||
local function curry(f, ...)
|
|
||||||
local args = {...}
|
|
||||||
local unpack = unpack or table.unpack
|
|
||||||
return function() return f(unpack(args)) end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe("passing correct options", function()
|
describe("passing correct options", function()
|
||||||
it("handles no options passed correctly", function()
|
it("handles no options passed correctly", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
@@ -184,19 +178,19 @@ describe("tests related to options", function()
|
|||||||
it("handles lack of required argument correctly", function()
|
it("handles lack of required argument correctly", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
parser:option("-s", "--server")
|
parser:option("-s", "--server")
|
||||||
assert.has_error(curry(parser.parse, parser, {"--server"}), "too few arguments")
|
assert.has_error(function() parser:parse{"--server"} end, "too few arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too many arguments correctly", function()
|
it("handles too many arguments correctly", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
parser:option("-s", "--server")
|
parser:option("-s", "--server")
|
||||||
assert.has_error(curry(parser.parse, parser, {"-sfoo", "bar"}), "too many arguments")
|
assert.has_error(function() parser:parse{"-sfoo", "bar"} end, "too many arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("doesn't accept GNU-like long options when it doesn't need arguments", function()
|
it("doesn't accept GNU-like long options when it doesn't need arguments", function()
|
||||||
local parser = argparse.parser()
|
local parser = argparse.parser()
|
||||||
parser:flag("-q", "--quiet")
|
parser:flag("-q", "--quiet")
|
||||||
assert.has_error(curry(parser.parse, parser, {"--quiet=very_quiet"}), "option --quiet doesn't take arguments")
|
assert.has_error(function() parser:parse{"--quiet=very_quiet"} end, "option --quiet doesn't take arguments")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too many invocations correctly", function()
|
it("handles too many invocations correctly", function()
|
||||||
@@ -205,7 +199,7 @@ describe("tests related to options", function()
|
|||||||
count = 1,
|
count = 1,
|
||||||
overwrite = false
|
overwrite = false
|
||||||
})
|
})
|
||||||
assert.has_error(curry(parser.parse, parser, {"-qq"}), "option -q must be used at most 1 times")
|
assert.has_error(function() parser:parse{"-qq"} end, "option -q must be used at most 1 times")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("handles too few invocations correctly", function()
|
it("handles too few invocations correctly", function()
|
||||||
@@ -213,7 +207,7 @@ describe("tests related to options", function()
|
|||||||
parser:option("-f", "--foo", {
|
parser:option("-f", "--foo", {
|
||||||
count = "3-4"
|
count = "3-4"
|
||||||
})
|
})
|
||||||
assert.has_error(curry(parser.parse, parser, {"-fFOO", "-fBAR"}), "option -f must be used at least 3 times")
|
assert.has_error(function() parser:parse{"-fFOO", "-fBAR"} end, "option -f must be used at least 3 times")
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user