#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>
#include <string>
#include <boost/test/auto_unit_test.hpp>
#include "parse.hpp"
Go to the source code of this file.
BOOST_AUTO_TEST_CASE |
( |
test_number |
| ) |
|
Definition at line 13 of file test_parse.cpp.
References parse_loop().
15 std::istringstream in(
"1\n3.14159\n1.23e45\n45.67e+8\n");
16 std::ostringstream out;
18 BOOST_CHECK_EQUAL(
"> 1\n> 3.14159\n> 1.23e+45\n> 4.567e+09\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_negative |
| ) |
|
Definition at line 21 of file test_parse.cpp.
References parse_loop().
23 std::istringstream in(
"-1\n-3.14159\n-1.23e-45\n-34.56e-7\n");
24 std::ostringstream out;
26 BOOST_CHECK_EQUAL(
"> -1\n> -3.14159\n> -1.23e-45\n> -3.456e-06\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_add |
| ) |
|
Definition at line 29 of file test_parse.cpp.
References parse_loop().
31 std::istringstream in(
"1 + 2\n1 + 2 + 3");
32 std::ostringstream out;
34 BOOST_CHECK_EQUAL(
"> 3\n> 6\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_subtract |
| ) |
|
Definition at line 37 of file test_parse.cpp.
References parse_loop().
39 std::istringstream in(
"1 - 2\n5 - 1 - 2");
40 std::ostringstream out;
42 BOOST_CHECK_EQUAL(
"> -1\n> 2\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_multiply |
| ) |
|
Definition at line 45 of file test_parse.cpp.
References parse_loop().
47 std::istringstream in(
"1 * 2\n5 * 2 * 1.5");
48 std::ostringstream out;
50 BOOST_CHECK_EQUAL(
"> 2\n> 15\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_divide |
| ) |
|
Definition at line 53 of file test_parse.cpp.
References parse_loop().
55 std::istringstream in(
"1.0 / 2\n10.0 / 2 / 2");
56 std::ostringstream out;
58 BOOST_CHECK_EQUAL(
"> 0.5\n> 2.5\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_mix |
| ) |
|
Definition at line 61 of file test_parse.cpp.
References parse_loop().
63 std::istringstream in(
" 1.5 * 2 + 3 / 1.5 - (10 - 3) + 2 * -1");
64 std::ostringstream out;
66 BOOST_CHECK_EQUAL(
"> -4\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_var |
| ) |
|
Definition at line 69 of file test_parse.cpp.
References parse_loop().
71 std::istringstream in(
" def half = 1.0 / 2\ndef one=1.0\n one + half");
72 std::ostringstream out;
74 BOOST_CHECK_EQUAL(
"> > > 1.5\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_predefined_vars |
| ) |
|
Definition at line 77 of file test_parse.cpp.
References parse_loop().
79 std::istringstream in(
" pi - e");
80 std::ostringstream out;
82 BOOST_CHECK_EQUAL(
"> 0.423311\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_function |
| ) |
|
Definition at line 85 of file test_parse.cpp.
References parse_loop().
87 std::istringstream in(
"def times(a, b) = a * b\ntimes(2, 3)\n");
88 std::ostringstream out;
90 BOOST_CHECK_EQUAL(
"> > 6\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_error1 |
| ) |
|
Definition at line 93 of file test_parse.cpp.
References parse_loop().
95 std::istringstream in(
"1+++2");
96 std::ostringstream out;
98 BOOST_CHECK_EQUAL(
"> syntax error: expected a primary, got +\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_error2 |
| ) |
|
Definition at line 101 of file test_parse.cpp.
References parse_loop().
103 std::istringstream in(
"1..2");
104 std::ostringstream out;
106 BOOST_CHECK_EQUAL(
"> syntax error: expected digit after decimal point, got '.'\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_error3 |
| ) |
|
Definition at line 109 of file test_parse.cpp.
References parse_loop().
111 std::istringstream in(
"1 @ 2");
112 std::ostringstream out;
114 BOOST_CHECK_EQUAL(
"> syntax error: expected digit, got '@'\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_error4 |
| ) |
|
Definition at line 117 of file test_parse.cpp.
References parse_loop().
119 std::istringstream in(
"(1 + 2");
120 std::ostringstream out;
122 BOOST_CHECK_EQUAL(
"> syntax error: expected ')', got end of line\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_error5 |
| ) |
|
Definition at line 125 of file test_parse.cpp.
References parse_loop().
127 std::istringstream in(
"pi(2)");
128 std::ostringstream out;
130 BOOST_CHECK_EQUAL(
"> wrong number of arguments in call to pi(), expected 0, got 1\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_error6 |
| ) |
|
Definition at line 133 of file test_parse.cpp.
References parse_loop().
135 std::istringstream in(
"def times(a, b) = a * b\ntimes(2)");
136 std::ostringstream out;
138 BOOST_CHECK_EQUAL(
"> > wrong number of arguments in call to times(), expected 2, got 1\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_CASE |
( |
test_error7 |
| ) |
|
Definition at line 141 of file test_parse.cpp.
References parse_loop().
143 std::istringstream in(
"def times(a, b) = a * b\ndivide(2, 3)");
144 std::ostringstream out;
146 BOOST_CHECK_EQUAL(
"> > unknown function: divide\n> ", out.str());
void parse_loop(std::istream &input, std::ostream &output)
BOOST_AUTO_TEST_SUITE |
( |
parse_test |
| ) |
|
BOOST_AUTO_TEST_SUITE_END |
( |
| ) |
|