From d77cd6a5d17f94c39fc8200b9e923453c02ab941 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Sat, 17 Mar 2018 14:26:45 +0300 Subject: [PATCH] Add tests for property validation --- spec/invalid_property_spec.lua | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spec/invalid_property_spec.lua diff --git a/spec/invalid_property_spec.lua b/spec/invalid_property_spec.lua new file mode 100644 index 0000000..258e85c --- /dev/null +++ b/spec/invalid_property_spec.lua @@ -0,0 +1,41 @@ +local Parser = require "argparse" + +describe("invalid property detection", function() + it("detects properties with invalid type", function() + assert.has_error(function() + Parser():name(12345) + end, "bad property 'name' (string expected, got number)") + + assert.has_error(function() + Parser():option "--foo":convert(true) + end, "bad property 'convert' (function or table expected, got boolean)") + end) + + it("detects invalid count and args properties", function() + assert.has_error(function() + Parser():option "--foo":count(false) + end, "bad property 'count' (number or string expected, got boolean)") + + assert.has_error(function() + Parser():option "--foo":args({}) + end, "bad property 'args' (number or string expected, got table)") + + assert.has_error(function() + Parser():option "--foo":count("foobar") + end, "bad property 'count'") + + assert.has_error(function() + Parser():option "--foo":args("123-") + end, "bad property 'args'") + end) + + it("detects unknown named actions", function() + assert.has_error(function() + Parser():option "--foo":action(false) + end, "bad property 'action' (function or string expected, got boolean)") + + assert.has_error(function() + Parser():option "--foo":action("catcat") + end, "unknown action 'catcat'") + end) +end)