mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 11:02:20 +00:00
Spec cleanups
This commit is contained in:
@@ -3,8 +3,8 @@ getmetatable(Parser()).error = function(_, msg) error(msg) end
|
|||||||
|
|
||||||
describe("tests related to actions", function()
|
describe("tests related to actions", function()
|
||||||
it("calls actions for options", function()
|
it("calls actions for options", function()
|
||||||
local action1 = spy.new(function(x) end)
|
local action1 = spy.new(function() end)
|
||||||
local action2 = spy.new(function(x) end)
|
local action2 = spy.new(function() end)
|
||||||
|
|
||||||
local parser = Parser()
|
local parser = Parser()
|
||||||
parser:option "-f" "--from" {
|
parser:option "-f" "--from" {
|
||||||
@@ -23,9 +23,9 @@ describe("tests related to actions", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("properly calls actions for flags", function()
|
it("properly calls actions for flags", function()
|
||||||
local action1 = spy.new(function(x) end)
|
local action1 = spy.new(function() end)
|
||||||
local action2 = spy.new(function(x) end)
|
local action2 = spy.new(function() end)
|
||||||
local action3 = spy.new(function(x) end)
|
local action3 = spy.new(function() end)
|
||||||
|
|
||||||
local parser = Parser()
|
local parser = Parser()
|
||||||
parser:flag "-v" "--verbose" {
|
parser:flag "-v" "--verbose" {
|
||||||
@@ -47,7 +47,7 @@ describe("tests related to actions", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("calls actions for commands", function()
|
it("calls actions for commands", function()
|
||||||
local action = spy.new(function(x) end)
|
local action = spy.new(function() end)
|
||||||
|
|
||||||
local parser = Parser "name"
|
local parser = Parser "name"
|
||||||
parser:flag "-v" "--verbose" {
|
parser:flag "-v" "--verbose" {
|
||||||
|
@@ -37,8 +37,8 @@ describe("tests related to commands", function()
|
|||||||
it("handles nested commands", function()
|
it("handles nested commands", function()
|
||||||
local parser = Parser "name"
|
local parser = Parser "name"
|
||||||
local foo = parser:command "foo"
|
local foo = parser:command "foo"
|
||||||
local bar = foo:command "bar"
|
foo:command "bar"
|
||||||
local baz = foo:command "baz"
|
foo:command "baz"
|
||||||
|
|
||||||
local args = parser:parse{"foo", "bar"}
|
local args = parser:parse{"foo", "bar"}
|
||||||
assert.same({foo = true, bar = true}, args)
|
assert.same({foo = true, bar = true}, args)
|
||||||
@@ -57,7 +57,7 @@ describe("tests related to commands", function()
|
|||||||
|
|
||||||
it("Detects wrong commands", function()
|
it("Detects wrong commands", function()
|
||||||
local parser = Parser "name"
|
local parser = Parser "name"
|
||||||
local install = parser:command "install"
|
parser:command "install"
|
||||||
|
|
||||||
assert.has_error(function() parser:parse{"run"} end, "unknown command 'run'")
|
assert.has_error(function() parser:parse{"run"} end, "unknown command 'run'")
|
||||||
end)
|
end)
|
||||||
|
@@ -9,7 +9,7 @@ describe("tests related to default values", function()
|
|||||||
:default "bar"
|
:default "bar"
|
||||||
local args = parser:parse{}
|
local args = parser:parse{}
|
||||||
assert.same({foo = "bar"}, args)
|
assert.same({foo = "bar"}, args)
|
||||||
local args = parser:parse{"baz"}
|
args = parser:parse{"baz"}
|
||||||
assert.same({foo = "baz"}, args)
|
assert.same({foo = "baz"}, args)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@@ -69,7 +69,7 @@ describe("tests related to options", function()
|
|||||||
parser:flag("-q", "--quiet")
|
parser:flag("-q", "--quiet")
|
||||||
local args = parser:parse({"--quiet"})
|
local args = parser:parse({"--quiet"})
|
||||||
assert.same({quiet = true}, args)
|
assert.same({quiet = true}, args)
|
||||||
local args = parser:parse({})
|
args = parser:parse({})
|
||||||
assert.same({}, args)
|
assert.same({}, args)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user