-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprogram_test.cpp
More file actions
83 lines (72 loc) · 1.75 KB
/
Copy pathprogram_test.cpp
File metadata and controls
83 lines (72 loc) · 1.75 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
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "../lich/push_to_primitive.h"
#include "../lich/push_to_string.h"
#include "../lich/program.h"
#include "../lich/ref.h"
#include "must.h"
using namespace std;
void program_test_do(lua_State* L)
{
MUST_EQUAL(lua_gettop(L), 0);
// run_program/빈 프로그램
{
tuple<> rv;
MUST_EQUAL(
lich::run_program(L, "", "", rv),
make_pair(true, string()));
}
MUST_EQUAL(lua_gettop(L), 0);
// run_program/리턴 하나
{
tuple<int> rv;
MUST_EQUAL(
lich::run_program(L, "return 42", "", rv),
make_pair(true, string()));
MUST_EQUAL(get<0>(rv), 42);
}
MUST_EQUAL(lua_gettop(L), 0);
// run_program/여러 타입 리턴
{
tuple<string, float, double> rv;
auto result = lich::run_program(L, "return '5', 7, 3", "", rv);
MUST_EQUAL(result, make_pair(true, string()));
MUST_EQUAL(get<0>(rv), "5");
MUST_EQUAL(get<1>(rv), 7.0f);
MUST_EQUAL(get<2>(rv), 3.0);
}
MUST_EQUAL(lua_gettop(L), 0);
// run program/컴파일 에러
{
tuple<> rv0;
auto result = lich::run_program(L, "local local", "", rv0);
MUST_EQUAL(
result,
make_pair(false, string("[string \"\"]:1: '<name>' expected near 'local'")));
}
MUST_EQUAL(lua_gettop(L), 0);
// run program/런타임 에러
{
tuple<> rv0;
auto result = lich::run_program(L, "print('b' + 'c')", "", rv0);
MUST_EQUAL(result.first, false);
MUST_TRUE(result.second.find("perform arithmetic") != string::npos);
}
MUST_EQUAL(lua_gettop(L), 0);
}
void program_test()
{
// openlibs 하고 테스트
{
lua_State* L = luaL_newstate();
luaL_openlibs(L);
lich::enable_ref(L);
program_test_do(L);
lua_close(L);
}
// openlibs 없이 테스트 (debug 라이브러리 없음)
{
lua_State* L = luaL_newstate();
lich::enable_ref(L);
program_test_do(L);
lua_close(L);
}
}