From 0e367c6f7705a677e491d25f0811693a18be974e Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sun, 19 Jan 2014 14:28:08 +0400 Subject: [PATCH] fixed ugly curry in tests --- spec/arguments_spec.lua | 28 +++++++++++----------------- spec/options_spec.lua | 16 +++++----------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/spec/arguments_spec.lua b/spec/arguments_spec.lua index de052f8..dc3be80 100644 --- a/spec/arguments_spec.lua +++ b/spec/arguments_spec.lua @@ -1,12 +1,6 @@ local argparse = require "argparse" 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() it("handles empty parser correctly", function() local parser = argparse.parser() @@ -80,28 +74,28 @@ describe("tests related to positional arguments", function() it("handles extra arguments with empty parser correctly", function() 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) it("handles extra arguments with one argument correctly", function() local parser = argparse.parser() 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) it("handles sudden option correctly", function() local parser = argparse.parser() 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) it("handles too few arguments with one argument correctly", function() local parser = argparse.parser() parser:argument "foo" - assert.has_error(curry(parser.parse, parser, {}), "too few arguments") + assert.has_error(function() parser:parse{} end, "too few arguments") end) 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 "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) 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 "foo2" - assert.has_error(curry(parser.parse, parser, {"bar"}), "too few arguments") + assert.has_error(function() parser:parse{"bar"} end, "too few arguments") end) it("handles too few arguments with multi-argument correctly", function() @@ -125,7 +119,7 @@ describe("tests related to positional arguments", function() parser:argument "foo" { args = "+" } - assert.has_error(curry(parser.parse, parser, {}), "too few arguments") + assert.has_error(function() parser:parse{} end, "too few arguments") end) it("handles too many arguments with multi-argument correctly", function() @@ -133,7 +127,7 @@ describe("tests related to positional arguments", function() parser:argument "foo" { 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) it("handles too few arguments with multi-argument correctly", function() @@ -141,7 +135,7 @@ describe("tests related to positional arguments", function() parser:argument("foo", { 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) 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", { 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) 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", { args = "*" }) - assert.has_error(curry(parser.parse, parser, {}), "too few arguments") + assert.has_error(function() parser:parse{} end, "too few arguments") end) end) end) diff --git a/spec/options_spec.lua b/spec/options_spec.lua index 82e6679..dc19df2 100644 --- a/spec/options_spec.lua +++ b/spec/options_spec.lua @@ -1,12 +1,6 @@ local argparse = require "argparse" 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() it("handles no options passed correctly", function() local parser = argparse.parser() @@ -184,19 +178,19 @@ describe("tests related to options", function() it("handles lack of required argument correctly", function() local parser = argparse.parser() 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) it("handles too many arguments correctly", function() local parser = argparse.parser() 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) it("doesn't accept GNU-like long options when it doesn't need arguments", function() local parser = argparse.parser() 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) it("handles too many invocations correctly", function() @@ -205,7 +199,7 @@ describe("tests related to options", function() count = 1, 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) it("handles too few invocations correctly", function() @@ -213,7 +207,7 @@ describe("tests related to options", function() 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") + assert.has_error(function() parser:parse{"-fFOO", "-fBAR"} end, "option -f must be used at least 3 times") end) end) end)