Browse Source

fixed natspec evaluator result on error

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
3fd2bf6b96
  1. 3
      libnatspec/NatspecExpressionEvaluator.cpp
  2. 15
      test/natspec.cpp

3
libnatspec/NatspecExpressionEvaluator.cpp

@ -52,7 +52,8 @@ QString NatspecExpressionEvaluator::evalExpression(QString const& _expression)
QJSValue result = m_engine.evaluate("evaluateExpression(\"" + _expression + "\")"); QJSValue result = m_engine.evaluate("evaluateExpression(\"" + _expression + "\")");
if (result.isError()) if (result.isError())
{ {
cerr << "Could not evaluate expression: " << _expression.toStdString() << ". result: " << result.toString().toStdString() << endl; cerr << "Could not evaluate expression: \"" << _expression.toStdString() << "\"" << endl;
return _expression;
} }
return result.toString(); return result.toString();
} }

15
test/natspec.cpp

@ -62,7 +62,6 @@ BOOST_AUTO_TEST_CASE(natspec_create_custom_function)
// given // given
NatspecExpressionEvaluator e; NatspecExpressionEvaluator e;
// when // when
auto x = e.evalExpression("`test = function (x) { return x + 'ok'; }`"); // ommit var, make it global auto x = e.evalExpression("`test = function (x) { return x + 'ok'; }`"); // ommit var, make it global
string result = e.evalExpression("`test(5)`").toStdString(); string result = e.evalExpression("`test(5)`").toStdString();
@ -121,4 +120,18 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params)
BOOST_CHECK_EQUAL(result, "Will multiply 4 by 7 and return 28."); BOOST_CHECK_EQUAL(result, "Will multiply 4 by 7 and return 28.");
} }
BOOST_AUTO_TEST_CASE(natspec_js_eval_error)
{
cnote << "testing natspec evaluation of incorrect input";
// given
NatspecExpressionEvaluator e;
// when
string result = e.evalExpression("`test(`").toStdString();
// then
BOOST_CHECK_EQUAL(result, "`test(`");
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save