-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_lexical_stage.cpp
More file actions
149 lines (113 loc) · 3.1 KB
/
test_lexical_stage.cpp
File metadata and controls
149 lines (113 loc) · 3.1 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// #define NDEBUG
#include <cassert>
#include <iostream>
#include <fstream>
#include "Scanner.cpp"
using namespace std;
void files_equals(string s1, string s2) {
string str1, str2;
ifstream fin1(s1);
ifstream fin2(s2);
int line = 1;
while(!fin1.eof() && !fin2.eof()) {
getline(fin1, str1);
getline(fin2, str2);
if(str1 != str2) {
cout << "Error in line : " << line << endl;
cout << "Received : " << str2 << endl;
cout << "Exepted : " << str1 << endl;
exit(0);
}
line++;
}
assert(fin1.eof() && fin2.eof());
fin1.close();
fin2.close();
}
void test_keywords() {
try {
Scanner S("lexical_stage_tests/test_keywords.txt");
ofstream fout("test_keywords_out.txt");
Lex l;
while (1) {
l = S.get_lex();
if (l.get_type() != LEX_NULL)
fout << l;
else
break;
}
fout.close();
files_equals("lexical_stage_tests/test_keywords_key.txt", "test_keywords_out.txt");
cout << "test_keywords DONE" << endl;
} catch(Exception &l) {
cout << l << endl;
}
remove("test_keywords_out.txt");
}
void test_delimetrs() {
try {
Scanner S("lexical_stage_tests/test_delimetrs.txt");
ofstream fout("test_delimetrs_out.txt");
Lex l;
while (1) {
l = S.get_lex();
if (l.get_type() != LEX_NULL)
fout << l;
else
break;
}
fout.close();
files_equals("lexical_stage_tests/test_delimetrs_key.txt", "test_delimetrs_out.txt");
cout << "test_delimetrs DONE" << endl;
} catch(Exception &l) {
cout << l << endl;
}
remove("test_delimetrs_out.txt");
}
void test_num() {
try {
Scanner S("lexical_stage_tests/test_num.txt");
ofstream fout("test_num_out.txt");
Lex l;
while (1) {
l = S.get_lex();
if (l.get_type() != LEX_NULL)
fout << l;
else
break;
}
fout.close();
files_equals("lexical_stage_tests/test_num_key.txt", "test_num_out.txt");
cout << "test_num DONE" << endl;
} catch(Exception &l) {
cout << l << endl;
}
remove("test_num_out.txt");
}
void test_all() {
try {
Scanner S("lexical_stage_tests/test_all.txt");
ofstream fout("test_all_out.txt");
Lex l;
while (1) {
l = S.get_lex();
if (l.get_type() != LEX_NULL)
fout << l;
else
break;
}
fout.close();
files_equals("lexical_stage_tests/test_all_key.txt", "test_all_out.txt");
cout << "test_all DONE" << endl;
} catch(Exception &l) {
cout << l << endl;
}
remove("test_all_out.txt");
}
int main() {
test_keywords();
test_delimetrs();
test_num();
test_all();
return 0;
}