1
1
#include < tests/doctest.h>
2
2
3
3
#include < iostream>
4
- #include < sstream >
4
+ #include < fstream >
5
5
6
6
#include < libasr/diagnostics.h>
7
7
@@ -62,12 +62,19 @@ TEST_CASE("Error Render: primary/secondary labels, single line") {
62
62
Location loc1, loc2, loc3;
63
63
LocationManager lm;
64
64
input = " One line text\n " ;
65
- lm.in_filename = " input" ;
66
- lm.get_newlines (input, lm.in_newlines );
67
- lm.out_start .push_back (0 );
68
- lm.in_start .push_back (0 );
69
- lm.in_start .push_back (input.size ());
70
- lm.out_start .push_back (input.size ());
65
+ {
66
+ std::ofstream out (" input.txt" );
67
+ out << input;
68
+ LocationManager::FileLocations fl;
69
+ fl.in_filename = " input.txt" ;
70
+ lm.get_newlines (input, fl.in_newlines );
71
+ fl.out_start .push_back (0 );
72
+ fl.in_start .push_back (0 );
73
+ fl.in_start .push_back (input.size ());
74
+ fl.out_start .push_back (input.size ());
75
+ lm.files .push_back (fl);
76
+ lm.file_ends .push_back (input.size ());
77
+ }
71
78
72
79
loc1.first = 4 ;
73
80
loc1.last = 7 ;
@@ -83,10 +90,10 @@ TEST_CASE("Error Render: primary/secondary labels, single line") {
83
90
Label (" " , {loc1})
84
91
}
85
92
);
86
- out = render_diagnostic_human (d, input, lm, false , false );
93
+ out = render_diagnostic_human (d, lm, false , false );
87
94
ref = S (R"""(
88
95
semantic error: Error with label no message
89
- --> input:1:5
96
+ --> input.txt :1:5
90
97
|
91
98
1 | One line text
92
99
| ^^^^
@@ -101,10 +108,10 @@ semantic error: Error with label no message
101
108
Label (" label message" , {loc1, loc2})
102
109
}
103
110
);
104
- out = render_diagnostic_human (d, input, lm, false , false );
111
+ out = render_diagnostic_human (d, lm, false , false );
105
112
ref = S (R"""(
106
113
semantic error: Error with label and message
107
- --> input:1:5
114
+ --> input.txt :1:5
108
115
|
109
116
1 | One line text
110
117
| ^^^^ ^^^^ label message
@@ -118,10 +125,10 @@ semantic error: Error with label and message
118
125
Label (" label message" , {loc1, loc2, loc3})
119
126
}
120
127
);
121
- out = render_diagnostic_human (d, input, lm, false , false );
128
+ out = render_diagnostic_human (d, lm, false , false );
122
129
ref = S (R"""(
123
130
semantic error: Error with label and message
124
- --> input:1:5
131
+ --> input.txt :1:5
125
132
|
126
133
1 | One line text
127
134
| ^^^^ ^^^^ label message
@@ -139,10 +146,10 @@ semantic error: Error with label and message
139
146
Label (" label2 message" , {loc2})
140
147
}
141
148
);
142
- out = render_diagnostic_human (d, input, lm, false , false );
149
+ out = render_diagnostic_human (d, lm, false , false );
143
150
ref = S (R"""(
144
151
semantic error: Error with two labels and message
145
- --> input:1:5
152
+ --> input.txt :1:5
146
153
|
147
154
1 | One line text
148
155
| ^^^^ label1 message
@@ -161,10 +168,10 @@ semantic error: Error with two labels and message
161
168
Label (" label3 message" , {loc3})
162
169
}
163
170
);
164
- out = render_diagnostic_human (d, input, lm, false , false );
171
+ out = render_diagnostic_human (d, lm, false , false );
165
172
ref = S (R"""(
166
173
semantic error: Error with two labels and message
167
- --> input:1:5
174
+ --> input.txt :1:5
168
175
|
169
176
1 | One line text
170
177
| ^^^^ label1 message
@@ -186,10 +193,10 @@ semantic error: Error with two labels and message
186
193
Label (" label3 secondary message" , {loc3}, false )
187
194
}
188
195
);
189
- out = render_diagnostic_human (d, input, lm, false , false );
196
+ out = render_diagnostic_human (d, lm, false , false );
190
197
ref = S (R"""(
191
198
semantic error: Error with two labels and message
192
- --> input:1:5
199
+ --> input.txt :1:5
193
200
|
194
201
1 | One line text
195
202
| ^^^^ label1 primary message
@@ -211,10 +218,10 @@ semantic error: Error with two labels and message
211
218
Label (" label3 secondary message" , {loc3}, false )
212
219
}
213
220
);
214
- out = render_diagnostic_human (d, input, lm, false , false );
221
+ out = render_diagnostic_human (d, lm, false , false );
215
222
ref = S (R"""(
216
223
semantic error: Error with three labels and message, two spans
217
- --> input:1:5
224
+ --> input.txt :1:5
218
225
|
219
226
1 | One line text
220
227
| ~~~~ ~~~~ label1 secondary message
@@ -233,13 +240,19 @@ TEST_CASE("Error Render: primary/secondary labels, multi line") {
233
240
Location loc1, loc2, loc3;
234
241
LocationManager lm;
235
242
input = " One line text\n Second line text\n Third line text\n " ;
236
- lm.in_filename = " input" ;
237
- lm.get_newlines (input, lm.in_newlines );
238
- lm.out_start .push_back (0 );
239
- lm.in_start .push_back (0 );
240
- lm.in_start .push_back (input.size ());
241
- lm.out_start .push_back (input.size ());
242
-
243
+ {
244
+ std::ofstream out (" input.txt" );
245
+ out << input;
246
+ LocationManager::FileLocations fl;
247
+ fl.in_filename = " input.txt" ;
248
+ lm.get_newlines (input, fl.in_newlines );
249
+ fl.out_start .push_back (0 );
250
+ fl.in_start .push_back (0 );
251
+ fl.in_start .push_back (input.size ());
252
+ fl.out_start .push_back (input.size ());
253
+ lm.files .push_back (fl);
254
+ lm.file_ends .push_back (input.size ());
255
+ }
243
256
loc1.first = 4 ; // 1 line
244
257
loc1.last = 24 ; // 2 line
245
258
loc2.first = 9 ; // 1 text
@@ -254,10 +267,10 @@ TEST_CASE("Error Render: primary/secondary labels, multi line") {
254
267
Label (" Multilines" , {loc1})
255
268
}
256
269
);
257
- out = render_diagnostic_human (d, input, lm, false , false );
270
+ out = render_diagnostic_human (d, lm, false , false );
258
271
ref = S (R"""(
259
272
semantic error: Error with label no message
260
- --> input:1:5 - 2:11
273
+ --> input.txt :1:5 - 2:11
261
274
|
262
275
1 | One line text
263
276
| ^^^^^^^^^...
@@ -275,10 +288,10 @@ semantic error: Error with label no message
275
288
Label (" Two spans" , {loc1, loc2})
276
289
}
277
290
);
278
- out = render_diagnostic_human (d, input, lm, false , false );
291
+ out = render_diagnostic_human (d, lm, false , false );
279
292
ref = S (R"""(
280
293
semantic error: Error with label, two spans
281
- --> input:1:5 - 2:11
294
+ --> input.txt :1:5 - 2:11
282
295
|
283
296
1 | One line text
284
297
| ^^^^^^^^^...
@@ -303,10 +316,10 @@ semantic error: Error with label, two spans
303
316
Label (" Two spans" , {loc3, loc2})
304
317
}
305
318
);
306
- out = render_diagnostic_human (d, input, lm, false , false );
319
+ out = render_diagnostic_human (d, lm, false , false );
307
320
ref = S (R"""(
308
321
semantic error: Error with label, two spans
309
- --> input:1:1
322
+ --> input.txt :1:1
310
323
|
311
324
1 | One line text
312
325
| ^^^ Two spans
0 commit comments