This repository was archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
70 lines (54 loc) · 1.31 KB
/
tests.cpp
File metadata and controls
70 lines (54 loc) · 1.31 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include "pyexec.hpp"
void test(const std::string& str1, const std::string& str2)
{
if (str1 == str2)
std::cout << "(\"" << str1 << "\" == \" " << str2 << "\") \033[32mOK\033[0m\n";
else
std::cout << "(\"" << str1 << "\" != \" " << str2 << "\") \033[31mFAILED\033[0m\n";
}
void test_code_execution(const std::string& code, const std::string& ans)
{
py::pyexec exec(std::cout);
test(exec.execute(code.c_str()), ans);
}
#define TEST
#include "pycompile.hpp"
void test_compilation(const std::string& in, const std::string& out)
{
py::pycompile compile(in, out, std::cout);
compile.compile();
}
int main(int argc, char** argv)
{
test_code_execution(
R"CODE(
def __metagenerator__():
return "everything is ok"
)CODE",
"everything is ok"
);
test_code_execution(
R"CODE(__metagenerator__ = "everything is ok")CODE",
"everything is ok"
);
test_code_execution(
R"CODE(__metagenerator__ = 88)CODE",
"88"
);
test_code_execution(
R"CODE(__metagenerator__ = 88 + 1)CODE",
"89"
);
test_code_execution(
R"CODE(
def __metagenerator__():
return 100
)CODE",
"100"
);
std::cout << py::pycompile::extension_of("lalala") << "\n";
std::cout << py::pycompile::extension_of(".lalala") << "\n";
std::cout << py::pycompile::extension_of("la.la") << "\n";
return 0;
}