NewLang Project
Yet another programm language
Main Page
Namespaces
Classes
Files
File List
File Members
Loading...
Searching...
No Matches
nlc
test
nlc_test.cpp
Go to the documentation of this file.
1
#ifdef BUILD_UNITTEST
2
3
#include "
warning_push.h
"
4
#include <gtest/gtest.h>
5
#include "
warning_pop.h
"
6
7
8
9
#include "
../nlc.h
"
10
#include "
builtin.h
"
11
12
using namespace
newlang
;
13
14
//TEST(NLC, Options) {
15
//
16
// NLC nlc0;
17
// ASSERT_TRUE(nlc0.m_path.empty());
18
// ASSERT_EQ(NLC::Mode::ModeError, nlc0.m_mode);
19
//
20
// NLC nlc1("");
21
// ASSERT_TRUE(nlc1.m_path.empty());
22
// ASSERT_EQ(NLC::Mode::ModeError, nlc1.m_mode);
23
//
24
// NLC nlc2("path");
25
// ASSERT_STREQ("path", nlc2.m_path.c_str());
26
// ASSERT_EQ(NLC::Mode::ModeInter, nlc2.m_mode) << nlc2.m_output;
27
//
28
// NLC nlc3(" path --help ");
29
// ASSERT_STREQ("path", nlc3.m_path.c_str());
30
// ASSERT_EQ(NLC::Mode::ModeHelp, nlc3.m_mode);
31
// ASSERT_FALSE(nlc3.m_output.empty()) << nlc3.m_output;
32
//
33
// NLC nlc4("path -v");
34
// ASSERT_STREQ("path", nlc4.m_path.c_str());
35
// ASSERT_EQ(NLC::Mode::ModeVersion, nlc4.m_mode);
36
//
37
// // NLC nlc5("path --output=output_file -cinput_file");
38
// // ASSERT_STREQ("path", nlc5.m_path.c_str());
39
// // ASSERT_EQ(NLC::COMPILE, nlc5.m_mode) << nlc5.m_output;
40
// // ASSERT_STREQ("output_file", nlc5.m_ofile.c_str());
41
// // ASSERT_STREQ("input_file", nlc5.m_ifile.c_str());
42
//
43
// // NLC nlc6("path --badarg --output=output_file");
44
// // ASSERT_EQ(NLC::ERROR, nlc6.m_mode);
45
//
46
// // NLC nlc7("path func(bad!,,args)");
47
// // ASSERT_EQ(NLC::ERROR, nlc7.m_mode) << nlc7.m_output;
48
//
49
// // NLC nlc8("path -lmodule.nlm --exec=file_name");
50
// // ASSERT_STREQ("path", nlc8.m_path.c_str());
51
// // ASSERT_EQ(NLC::EXEC, nlc8.m_mode);
52
// // ASSERT_STREQ("file_name", nlc8.m_ifile.c_str());
53
// // ASSERT_EQ(1, nlc8.m_modules.size());
54
// // ASSERT_STREQ("module.nlm", nlc8.m_modules[0].c_str());
55
//
56
// NLC nlc9("path --load=module2.nlm call(arg1,100)");
57
// ASSERT_STREQ("path", nlc9.m_path.c_str());
58
// ASSERT_EQ(NLC::Mode::ModeEval, nlc9.m_mode);
59
// ASSERT_EQ(1, nlc9.m_modules.size());
60
// ASSERT_STREQ("module2.nlm", nlc9.m_modules[0].c_str());
61
// ASSERT_STREQ("call(arg1,100)", nlc9.m_eval.c_str());
62
//
63
// NLC nlc10("path --load=module2.nlm,module3.nlm 100+200");
64
// ASSERT_STREQ("path", nlc10.m_path.c_str());
65
// ASSERT_EQ(NLC::Mode::ModeEval, nlc10.m_mode);
66
// ASSERT_EQ(2, nlc10.m_modules.size());
67
// ASSERT_STREQ("module2.nlm", nlc10.m_modules[0].c_str());
68
// ASSERT_STREQ("module3.nlm", nlc10.m_modules[1].c_str());
69
// ASSERT_STREQ("100+200", nlc10.m_eval.c_str());
70
//
71
// NLC nlc11("path --load=module2.nlm,, --load-only=,tt1,tt2,tt3 \"100+200\"");
72
// ASSERT_STREQ("path", nlc11.m_path.c_str());
73
// ASSERT_EQ(NLC::Mode::ModeEval, nlc11.m_mode) << nlc11.m_output;
74
// ASSERT_EQ(1, nlc11.m_modules.size());
75
// ASSERT_STREQ("module2.nlm", nlc11.m_modules[0].c_str());
76
// ASSERT_STREQ("\"100+200\"", nlc11.m_eval.c_str());
77
//
78
// ASSERT_EQ(3, nlc11.m_load_only.size());
79
// ASSERT_STREQ("tt1", nlc11.m_load_only[0].c_str());
80
// ASSERT_STREQ("tt2", nlc11.m_load_only[1].c_str());
81
// ASSERT_STREQ("tt3", nlc11.m_load_only[2].c_str());
82
//
83
// // NLC nlc_empty("path");
84
// // ASSERT_STREQ("path", nlc_empty.m_path.c_str());
85
// // ASSERT_EQ(NLC::HELP, nlc_empty.m_mode);
86
// // ASSERT_FALSE(nlc_empty.m_output.empty()) << nlc_empty.m_output;
87
//}
88
//
89
//TEST(NLC, FileFunc) {
90
//
91
// ASSERT_STREQ("", GetFileExt("").c_str());
92
// ASSERT_STREQ(".", GetFileExt(".").c_str());
93
// ASSERT_STREQ(".", GetFileExt(".").c_str());
94
// ASSERT_STREQ(".", GetFileExt("name.").c_str());
95
// ASSERT_STREQ(".ext", GetFileExt("name.ext").c_str());
96
// ASSERT_STREQ(".ext", GetFileExt(".ext").c_str());
97
//
98
// ASSERT_STREQ("", AddDefaultFileExt("", ".nlm").c_str());
99
// ASSERT_STREQ(".", AddDefaultFileExt(".", ".nlm").c_str());
100
// ASSERT_STREQ("name.nlm", AddDefaultFileExt("name", ".nlm").c_str());
101
// ASSERT_STREQ("name.nlm", AddDefaultFileExt("name.nlm", ".nlm").c_str());
102
// ASSERT_STREQ("name.test", AddDefaultFileExt("name.test", ".nlm").c_str());
103
// ASSERT_STREQ("name.", AddDefaultFileExt("name.", ".nlm").c_str());
104
//
105
// ASSERT_STREQ("", ReplaceFileExt("", ".src", ".nlm").c_str());
106
// ASSERT_STREQ(".", ReplaceFileExt(".", ".src", ".nlm").c_str());
107
// ASSERT_STREQ("name.nlm", ReplaceFileExt("name", ".src", ".nlm").c_str());
108
// ASSERT_STREQ("name.nlm", ReplaceFileExt("name.src", ".src", ".nlm").c_str());
109
// ASSERT_STREQ("name.test.nlm", ReplaceFileExt("name.test", ".src", ".nlm").c_str());
110
// ASSERT_STREQ("name.", ReplaceFileExt("name.", ".src", ".nlm").c_str());
111
//}
112
//
113
//TEST(NLC, Eval) {
114
// NLC nlc6("path --badarg --output=output_file");
115
// ASSERT_EQ(NLC::Mode::ModeEval, nlc6.m_mode);
116
// ASSERT_EQ(1, nlc6.Run());
117
//
118
// NLC nlc7("path func(bad!,,args)");
119
// ASSERT_EQ(NLC::Mode::ModeEval, nlc7.m_mode) << nlc7.m_output;
120
// ASSERT_EQ(1, nlc7.Run());
121
//}
122
//
124
// * #!./dist/Debug/GNU-Linux/nlc --exec
125
// * print(str="") $= { %{ printf("%s", static_cast<char *>($str)); return $str; %} };
126
// * @print("Привет, мир!\n");
127
// */
128
//TEST(NLC, EvalHelloWorld) {
129
//
130
// std::string cmd;
131
// cmd += "#!./dist/Debug/GNU-Linux/nlc --eval\n";
132
// cmd += "hello(str='') := { printf := :Pointer('printf(format:FmtChar, ...):Int32'); printf('%s', $str); $str;};\n";
133
// cmd += "hello('Привет, мир!\\n');";
134
//
135
// std::filesystem::create_directories("temp");
136
// ASSERT_TRUE(std::filesystem::is_directory("temp"));
137
//
138
//
139
// std::ofstream out("temp/hello.temp.sh");
140
// out << cmd;
141
// out.close();
142
//
143
// NLC run;
144
// ObjPtr result = run.m_ctx.ExecStr(cmd, nullptr, Context::CatchType::CATCH_ALL);
145
// ASSERT_TRUE(result);
146
// ASSERT_STREQ("Привет, мир!\n", result->GetValueAsString().c_str());
147
//}
148
//
796
797
#endif
// UNITTEST
builtin.h
newlang
Definition
nlc.h:59
nlc.h
warning_pop.h
warning_push.h
Generated by
1.11.0