mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
fixed arguments from root parser not formatted
This commit is contained in:
@@ -6,21 +6,21 @@ describe("tests related to options", function()
|
||||
local parser = argparse.parser()
|
||||
parser:option("-s", "--server")
|
||||
local args = parser:parse({})
|
||||
assert.same(args, {})
|
||||
assert.same({}, args)
|
||||
end)
|
||||
|
||||
it("handles one option correctly", function()
|
||||
local parser = argparse.parser()
|
||||
parser:option("-s", "--server")
|
||||
local args = parser:parse({"--server", "foo"})
|
||||
assert.same(args, {server = "foo"})
|
||||
assert.same({server = "foo"}, args)
|
||||
end)
|
||||
|
||||
it("handles GNU-style long options", function()
|
||||
local parser = argparse.parser()
|
||||
parser:option("-s", "--server")
|
||||
local args = parser:parse({"--server=foo"})
|
||||
assert.same(args, {server = "foo"})
|
||||
assert.same({server = "foo"}, args)
|
||||
end)
|
||||
|
||||
it("handles GNU-style long options even when it could take more arguments", function()
|
||||
@@ -29,7 +29,7 @@ describe("tests related to options", function()
|
||||
args = "*"
|
||||
})
|
||||
local args = parser:parse({"--server=foo"})
|
||||
assert.same(args, {server = {"foo"}})
|
||||
assert.same({server = {"foo"}}, args)
|
||||
end)
|
||||
|
||||
it("handles GNU-style long options for multi-argument options", function()
|
||||
@@ -38,21 +38,23 @@ describe("tests related to options", function()
|
||||
args = "1-2"
|
||||
})
|
||||
local args = parser:parse({"--server=foo", "bar"})
|
||||
assert.same(args, {server = {"foo", "bar"}})
|
||||
assert.same({server = {"foo", "bar"}}, args)
|
||||
end)
|
||||
|
||||
it("handles short option correclty", function()
|
||||
local parser = argparse.parser()
|
||||
parser:option("-s", "--server")
|
||||
local args = parser:parse({"-s", "foo"})
|
||||
assert.same(args, {server = "foo"})
|
||||
assert.same({server = "foo"}, args)
|
||||
end)
|
||||
|
||||
it("handles flag correclty", function()
|
||||
local parser = argparse.parser()
|
||||
parser:flag("-q", "--quiet")
|
||||
local args = parser:parse({"--quiet"})
|
||||
assert.same(args, {quiet = true})
|
||||
assert.same({quiet = true}, args)
|
||||
local args = parser:parse({})
|
||||
assert.same({}, args)
|
||||
end)
|
||||
|
||||
it("handles combined flags correclty", function()
|
||||
@@ -60,14 +62,14 @@ describe("tests related to options", function()
|
||||
parser:flag("-q", "--quiet")
|
||||
parser:flag("-f", "--fast")
|
||||
local args = parser:parse({"-qf"})
|
||||
assert.same(args, {quiet = true, fast = true})
|
||||
assert.same({quiet = true, fast = true}, args)
|
||||
end)
|
||||
|
||||
it("handles short options without space between option and argument", function()
|
||||
local parser = argparse.parser()
|
||||
parser:option("-s", "--server")
|
||||
local args = parser:parse({"-sfoo"})
|
||||
assert.same(args, {server = "foo"})
|
||||
assert.same({server = "foo"}, args)
|
||||
end)
|
||||
|
||||
it("handles flags combined with short option correclty", function()
|
||||
@@ -75,7 +77,7 @@ describe("tests related to options", function()
|
||||
parser:flag("-q", "--quiet")
|
||||
parser:option("-s", "--server")
|
||||
local args = parser:parse({"-qsfoo"})
|
||||
assert.same(args, {quiet = true, server = "foo"})
|
||||
assert.same({quiet = true, server = "foo"}, args)
|
||||
end)
|
||||
|
||||
describe("Options with optional argument", function()
|
||||
@@ -85,7 +87,7 @@ describe("tests related to options", function()
|
||||
args = "?"
|
||||
})
|
||||
local args = parser:parse({})
|
||||
assert.same(args, {})
|
||||
assert.same({}, args)
|
||||
end)
|
||||
|
||||
it("handles option without argument correctly", function()
|
||||
@@ -94,7 +96,7 @@ describe("tests related to options", function()
|
||||
args = "?"
|
||||
})
|
||||
local args = parser:parse({"-p"})
|
||||
assert.same(args, {password = {}})
|
||||
assert.same({password = {}}, args)
|
||||
end)
|
||||
|
||||
it("handles option with argument correctly", function()
|
||||
@@ -103,7 +105,7 @@ describe("tests related to options", function()
|
||||
args = "?"
|
||||
})
|
||||
local args = parser:parse({"-p", "password"})
|
||||
assert.same(args, {password = {"password"}})
|
||||
assert.same({password = {"password"}}, args)
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -113,7 +115,7 @@ describe("tests related to options", function()
|
||||
args = 2
|
||||
})
|
||||
local args = parser:parse({"--pair", "Alice", "Bob"})
|
||||
assert.same(args, {pair = {"Alice", "Bob"}})
|
||||
assert.same({pair = {"Alice", "Bob"}}, args)
|
||||
end)
|
||||
|
||||
describe("Multi-count options", function()
|
||||
@@ -123,7 +125,7 @@ describe("tests related to options", function()
|
||||
count = "*"
|
||||
})
|
||||
local args = parser:parse({"-efoo", "--exclude=bar", "-e", "baz"})
|
||||
assert.same(args, {exclude = {"foo", "bar", "baz"}})
|
||||
assert.same({exclude = {"foo", "bar", "baz"}}, args)
|
||||
end)
|
||||
|
||||
it("handles not used multi-count option correctly", function()
|
||||
@@ -132,7 +134,7 @@ describe("tests related to options", function()
|
||||
count = "*"
|
||||
})
|
||||
local args = parser:parse({})
|
||||
assert.same(args, {exclude = {}})
|
||||
assert.same({exclude = {}}, args)
|
||||
end)
|
||||
|
||||
it("handles multi-count multi-argument option correctly", function()
|
||||
@@ -142,7 +144,7 @@ describe("tests related to options", function()
|
||||
args = 2
|
||||
})
|
||||
local args = parser:parse({"-e", "Alice", "Bob", "-e", "Emma", "Jacob"})
|
||||
assert.same(args, {exclude = {{"Alice", "Bob"}, {"Emma", "Jacob"}}})
|
||||
assert.same({exclude = {{"Alice", "Bob"}, {"Emma", "Jacob"}}}, args)
|
||||
end)
|
||||
|
||||
it("handles multi-count flag correctly", function()
|
||||
@@ -151,7 +153,7 @@ describe("tests related to options", function()
|
||||
count = "*"
|
||||
})
|
||||
local args = parser:parse({"-qq", "--quiet"})
|
||||
assert.same(args, {quiet = 3})
|
||||
assert.same({quiet = 3}, args)
|
||||
end)
|
||||
|
||||
it("overwrites old invocations", function()
|
||||
@@ -160,7 +162,7 @@ describe("tests related to options", function()
|
||||
count = "0-2"
|
||||
})
|
||||
local args = parser:parse({"-uAlice", "--user=Bob", "--user", "John"})
|
||||
assert.same(args, {user = {"Bob", "John"}})
|
||||
assert.same({user = {"Bob", "John"}}, args)
|
||||
end)
|
||||
|
||||
it("handles not used multi-count flag correctly", function()
|
||||
@@ -169,7 +171,7 @@ describe("tests related to options", function()
|
||||
count = "*"
|
||||
})
|
||||
local args = parser:parse({})
|
||||
assert.same(args, {quiet = 0})
|
||||
assert.same({quiet = 0}, args)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user