]> granicus.if.org Git - icinga2/commitdiff
Add unit tests for the "var" keyword
authorGunnar Beutner <gunnar@beutner.name>
Mon, 15 Dec 2014 15:42:34 +0000 (16:42 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 15 Dec 2014 15:42:34 +0000 (16:42 +0100)
refs #8074

lib/config/config_parser.yy
test/config-ops.cpp

index ad2fcff99a663d72790323e999c9ba14e480d95c..eb8a046d30167c96b198ca75814c958adf81adcd 100644 (file)
@@ -641,6 +641,18 @@ lterm: type
                $$ = new SetExpression(MakeIndexer(ScopeGlobal, $2), OpSetLiteral, $4);
                free($2);
        }
+       | T_VAR rterm
+       {
+               Expression *expr = $2;
+               BindToScope(expr, ScopeLocal);
+               $$ = new SetExpression(expr, OpSetLiteral, MakeLiteral(), DebugInfoRange(@1, @2));
+       }
+       | T_VAR rterm combined_set_op rterm
+       {
+               Expression *expr = $2;
+               BindToScope(expr, ScopeLocal);
+               $$ = new SetExpression(expr, $3, $4, DebugInfoRange(@1, @4));
+       }
        | rterm
        {
                $$ = $1;
@@ -752,18 +764,6 @@ rterm: T_STRING
        {
                $$ = new GetScopeExpression(ScopeThis);
        }
-       | T_VAR rterm
-       {
-               Expression *expr = $2;
-               BindToScope(expr, ScopeLocal);
-               $$ = new SetExpression(expr, OpSetLiteral, MakeLiteral(), DebugInfoRange(@1, @2));
-       }
-       | T_VAR rterm combined_set_op rterm
-       {
-               Expression *expr = $2;
-               BindToScope(expr, ScopeLocal);
-               $$ = new SetExpression(expr, $3, $4, DebugInfoRange(@1, @4));
-       }
        | rterm_array
        {
                $$ = $1;
index 6b0ec39531806a813849e1c45a937a6a7f891a68..ca74749cf51d002dc1504157cc46ce7d6774a3df 100644 (file)
@@ -299,6 +299,14 @@ BOOST_AUTO_TEST_CASE(advanced)
        expr = ConfigCompiler::CompileText("<test>", "3 = 3");
        BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError);
        delete expr;
+
+       expr = ConfigCompiler::CompileText("<test>", "var e; e");
+       BOOST_CHECK(expr->Evaluate(frame).IsEmpty());
+       delete expr;
+
+       expr = ConfigCompiler::CompileText("<test>", "var e = 3; e");
+       BOOST_CHECK(expr->Evaluate(frame) == 3);
+       delete expr;
 }
 
 BOOST_AUTO_TEST_SUITE_END()