]> granicus.if.org Git - icinga2/commitdiff
Implement a unit test for nullary lambdas
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Feb 2015 13:02:32 +0000 (14:02 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 3 Feb 2015 13:02:32 +0000 (14:02 +0100)
fixes #7805

lib/base/function.hpp
lib/icinga/macroprocessor.cpp
test/config-ops.cpp

index e19782d497fba4f784ed8e47c430b8ed3b5921b6..16c5285bbfa8831881a96edbc7e10a177e868bdb 100644 (file)
@@ -44,7 +44,7 @@ public:
 
        Function(const Callback& function);
 
-       Value Invoke(const std::vector<Value>& arguments);
+       Value Invoke(const std::vector<Value>& arguments = std::vector<Value>());
 
        static Object::Ptr GetPrototype(void);
 
index e8e6259ba5f108eb9f023676ed4e9831cce992bc..8a578842b99893274490329ba55e865e8f444a6c 100644 (file)
@@ -184,8 +184,7 @@ Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const Resolver
            recursionLevel)));
 
        ScriptFrame frame(resolvers_this);
-       std::vector<Value> args;
-       return func->Invoke(args);
+       return func->Invoke();
 }
 
 Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverList& resolvers,
index f9686d62c89cea2ffe95c9ceedb1d86defc67f05..4293b24971ada63ecebafc39c569a40dded561b4 100644 (file)
@@ -209,6 +209,7 @@ BOOST_AUTO_TEST_CASE(advanced)
 {
        ScriptFrame frame;
        Expression *expr;
+       Function::Ptr func;
 
        expr = ConfigCompiler::CompileText("<test>", "regex(\"^Hello\", \"Hello World\")");
        BOOST_CHECK(expr->Evaluate(frame));
@@ -319,6 +320,11 @@ BOOST_AUTO_TEST_CASE(advanced)
        expr = ConfigCompiler::CompileText("<test>", "Array.x");
        BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError);
        delete expr;
+
+       expr = ConfigCompiler::CompileText("<test>", "{{ 3 }}");
+       func = expr->Evaluate(frame);
+       BOOST_CHECK(func->Invoke() == 3);
+       delete expr;
 }
 
 BOOST_AUTO_TEST_SUITE_END()