-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6-run.test.cpp
54 lines (46 loc) · 1.84 KB
/
6-run.test.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
#include <iostream>
#include <fstream>
#include <cstdio>
#include "doctest.h"
#include "../include/run.hpp"
#include "../include/context.hpp"
#include "../include/runtime.hpp"
#include "../include/miscellaneous.hpp"
#include "../include/values/compositer.hpp"
using namespace std;
DOCTEST_TEST_SUITE("run method") {
SCENARIO("cli") {
shared_ptr<Context> ctx = make_shared<Context>("<tests>");
const string input = "5+5";
unique_ptr<const RuntimeResult> res = runLine(input, ctx);
CHECK(*READ_FILES["<stdin>"] == input);
CHECK(res->get_value() != nullptr);
CHECK(res->get_error() == nullptr);
shared_ptr<Value> res_value = res->get_value();
shared_ptr<ListValue> list_value = cast_value<ListValue>(res_value);
list<shared_ptr<const Value>> elements = list_value->get_elements();
shared_ptr<const Value> front = elements.front();
shared_ptr<const IntegerValue> integer = cast_const_value<IntegerValue>(front);
CHECK(integer->get_actual_value() == 10);
}
SCENARIO("file") {
shared_ptr<Context> ctx = make_shared<Context>("<tests>");
const string input = "6+6";
const char* test_filename = "tests_runfile.bk";
ofstream file = ofstream(test_filename);
CHECK(file.is_open());
file << input;
file.close();
unique_ptr<const RuntimeResult> res = runFile(test_filename, ctx);
CHECK(res != nullptr);
CHECK(res->get_value() != nullptr);
CHECK(res->get_error() == nullptr);
shared_ptr<Value> res_value = res->get_value();
shared_ptr<ListValue> list_value = cast_value<ListValue>(res_value);
list<shared_ptr<const Value>> elements = list_value->get_elements();
shared_ptr<const Value> front = elements.front();
shared_ptr<const IntegerValue> integer = cast_const_value<IntegerValue>(front);
CHECK(integer->get_actual_value() == 12);
remove(test_filename);
}
}