7 #include <boost/test/auto_unit_test.hpp>
13 std::istringstream in(
"1\n3.14159\n1.23e45\n45.67e+8\n");
14 std::ostringstream out;
16 BOOST_CHECK_EQUAL(
"> 1\n> 3.14159\n> 1.23e+45\n> 4.567e+09\n> ", out.str());
21 std::istringstream in(
"-1\n-3.14159\n-1.23e-45\n-34.56e-7\n");
22 std::ostringstream out;
24 BOOST_CHECK_EQUAL(
"> -1\n> -3.14159\n> -1.23e-45\n> -3.456e-06\n> ", out.str());
29 std::istringstream in(
"1 + 2\n1 + 2 + 3");
30 std::ostringstream out;
32 BOOST_CHECK_EQUAL(
"> 3\n> 6\n> ", out.str());
37 std::istringstream in(
"1 - 2\n5 - 1 - 2");
38 std::ostringstream out;
40 BOOST_CHECK_EQUAL(
"> -1\n> 2\n> ", out.str());
45 std::istringstream in(
"1 * 2\n5 * 2 * 1.5");
46 std::ostringstream out;
48 BOOST_CHECK_EQUAL(
"> 2\n> 15\n> ", out.str());
53 std::istringstream in(
"1 / 2\n10 / 2 / 2");
54 std::ostringstream out;
56 BOOST_CHECK_EQUAL(
"> 0.5\n> 2.5\n> ", out.str());
61 std::istringstream in(
" 1.5 * 2 + 3 / 1.5 - (10 - 3) + 2 * -1");
62 std::ostringstream out;
64 BOOST_CHECK_EQUAL(
"> -4\n> ", out.str());
69 std::istringstream in(
" var half = 1 / 2\nvar one=1.0\n one + half");
70 std::ostringstream out;
72 BOOST_CHECK_EQUAL(
"> 0.5\n> 1\n> 1.5\n> ", out.str());
77 std::istringstream in(
" pi - e");
78 std::ostringstream out;
80 BOOST_CHECK_EQUAL(
"> 0.423311\n> ", out.str());
85 std::istringstream in(
"1+++2");
86 std::ostringstream out;
88 BOOST_CHECK_EQUAL(
"> syntax error: expected a primary, but got +\n> ", out.str());
93 std::istringstream in(
"1..2");
94 std::ostringstream out;
96 BOOST_CHECK_EQUAL(
"> syntax error: expected digit after decimal point, got '.'\n> ", out.str());
101 std::istringstream in(
"1 @ 2");
102 std::ostringstream out;
104 BOOST_CHECK_EQUAL(
"> syntax error: expected digit, got '@'\n> ", out.str());
109 std::istringstream in(
"(1 + 2");
110 std::ostringstream out;
112 BOOST_CHECK_EQUAL(
"> syntax error: EOF when expecting ')'\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE(test_number)