You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.5 KiB

10 years ago
//
// Created by Marek Kotewicz on 27/04/15.
//
#include <boost/test/unit_test.hpp>
#include <libjsengine/JSV8Engine.h>
10 years ago
#include <libjsengine/JSV8Printer.h>
10 years ago
using namespace std;
using namespace dev;
using namespace dev::eth;
BOOST_AUTO_TEST_SUITE(jsv8engine)
BOOST_AUTO_TEST_CASE(evalInteger)
{
10 years ago
JSV8Engine engine;
JSV8Printer printer(engine);
auto value = engine.eval("1 + 1");
string result = printer.print(value);
10 years ago
BOOST_CHECK_EQUAL(result, "2");
}
BOOST_AUTO_TEST_CASE(evalString)
{
10 years ago
JSV8Engine engine;
JSV8Printer printer(engine);
auto value = engine.eval("'hello ' + 'world'");
string result = printer.print(value);
10 years ago
BOOST_CHECK_EQUAL(result, "hello world");
}
BOOST_AUTO_TEST_CASE(evalEmpty)
{
10 years ago
JSV8Engine engine;
JSV8Printer printer(engine);
auto value = engine.eval("");
string result = printer.print(value);
10 years ago
BOOST_CHECK_EQUAL(result, "undefined");
}
BOOST_AUTO_TEST_CASE(evalAssignment)
{
JSV8Engine engine;
JSV8Printer printer(engine);
auto value = engine.eval("x = 5");
string result = printer.print(value);
BOOST_CHECK_EQUAL(result, "5");
}
BOOST_AUTO_TEST_CASE(evalIncorrectExpression)
{
JSV8Engine engine;
JSV8Printer printer(engine);
auto value = engine.eval("[");
string result = printer.print(value);
BOOST_CHECK_EQUAL(result, "Error: Uncaught SyntaxError: Unexpected end of input");
}
BOOST_AUTO_TEST_CASE(evalNull)
{
JSV8Engine engine;
JSV8Printer printer(engine);
auto value = engine.eval("null");
string result = printer.print(value);
BOOST_CHECK_EQUAL(result, "null");
}
10 years ago
BOOST_AUTO_TEST_SUITE_END()