-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_tests.cpp
59 lines (32 loc) · 1.2 KB
/
parse_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "catch.hpp"
#include "parse.hpp"
TEST_CASE("Test parser with expected input", "[parse]") {
std::string program = "(begin (define r 10) (* pi (* r r)))";
std::istringstream iss(program);
TokenSequenceType tokens = tokenize(iss);
REQUIRE(parse(tokens) != Expression()); // if everything is valid, it will return a tree. else, return expression
}
TEST_CASE("Test unbalanced parens", "[parse]") {
std::string program = "((begin (+ 1))))))";
std::istringstream iss(program);
TokenSequenceType tokens = tokenize(iss);
REQUIRE(parse(tokens) == Expression());
}
TEST_CASE( "Test bad Number literal", "[parse]" ) {
std::string program = "(define a 1.2abc)";
std::istringstream iss(program);
TokenSequenceType tokens = tokenize(iss);
REQUIRE(parse(tokens) == Expression());
}
TEST_CASE( "Test missing parens", "[parse]" ) {
std::string program = "+ 1 2";
std::istringstream iss(program);
TokenSequenceType tokens = tokenize(iss);
REQUIRE(parse(tokens) == Expression());
}
TEST_CASE( "Test empty parens", "[parse]" ) {
std::string program = "()";
std::istringstream iss(program);
TokenSequenceType tokens = tokenize(iss);
REQUIRE(parse(tokens) == Expression());
}