1+ use std:: fs;
2+
13use c_parser:: * ;
24
35const SEP : & str = "\n --------------------\n " ;
@@ -25,6 +27,8 @@ fn test_string_error(content: &str, output: &str) {
2527 } else {
2628 res. get_displayed_errors ( files, "lexer" )
2729 } ;
30+ fs:: write ( "displayed.txt" , & displayed) . unwrap ( ) ;
31+ fs:: write ( "expected.txt" , output) . unwrap ( ) ;
2832 assert ! (
2933 output == displayed,
3034 "Mismatch! Expected:\n !{output}!\n != Computed\n !{displayed}!"
@@ -49,9 +53,8 @@ make_string_tests!(
4953
5054digraphs:
5155 "
52- int arr<:3:> = { 1, 2, 3} ; // Equivalent to int arr[3];
56+ int arr<:3:> = <% 1, 2, 3%> ; // Equivalent to int arr[3];
5357 arr<:1:> = 42; // Equivalent to arr[1] = 42;
54- // int map<%2%>; // Equivalent to int map{2}; //TODO
5558 "
5659 =>
5760 "[(((int arr)[3]) = {1, 2, 3}), ((arr[1]) = 42), \u{2205} ..]"
@@ -114,6 +117,10 @@ nested_braces:
114117 =>
115118 "[[\u{2205} , \u{2205} , \u{2205} , \u{2205} , [(a = 1), (b = 2), \u{2205} ], (c = 3), \u{2205} ]..]"
116119
120+ char_array:
121+ "char x[4] = {'b', 12+'5', '3', '\0 ' };"
122+ =>
123+ "[(((char x)[4]) = {'b', (12 + '5'), '3', '\0 '}), \u{2205} ..]"
117124
118125nested_block_functions:
119126 "f(a+b) { g(!x) { a = 1; b = 2; } c = 3;
@@ -184,29 +191,60 @@ macro_rules! make_string_error_tests {
184191
185192make_string_error_tests ! (
186193
187- lengths:
188- "x = \" blob\" bob;"
194+ lengths_literal:
195+ "x = 'c' blob;"
196+ =>
197+ ":1:9: parser error: Found 2 consecutive literals: block [(x = 'c')..] followed by blob.
198+ 1 | x = 'c' blob;
199+ ^~~~
200+ "
201+
202+ lengths_symbols:
203+ "<<="
189204 =>
190- ":1:12 : parser error: Found 2 consecutive literals: block [(x = \" blob \" )..] followed by bob .
191- 1 | x = \" blob \" bob;
192- ^~~
205+ ":1:1 : parser error: Tried to call binary operator <<= on without a left argument .
206+ 1 | <<=
207+ ^~~
193208"
194209
195210digraphs:
196211 "%:include <stdio.h>"
197212 =>
198- ":1:3 : lexer error: Found invalid character '#', found by replacing digraph '%:'.
213+ ":1:1 : lexer error: Found invalid character '#', found by replacing digraph '%:'.
199214 1 | %:include <stdio.h>
200- ^
215+ ^~
201216"
202217
203- // trigraphs:
204- // "
205- // int ??= 1;
206- // int a ??( 10 ??);
207- // char b = '??/';
208- // char q ??'!'??';
209- // int c ??- 5;
210- // " => ""
218+ trigraphs:
219+ "
220+ char b??(5??) = ??< 'b', 'l', 'o',??/
221+ 'b', '\0 ' ??>;
222+ int x = 1 ??' ??- 2 ??! 3;
223+ " =>
224+ ":2:7: lexer warning: Trigraphs are deprecated in C23. Please remove them: replace '??(' by '['.
225+ 2 | char b??(5??) = ??< 'b', 'l', 'o',??/
226+ ^~~
227+ :2:11: lexer warning: Trigraphs are deprecated in C23. Please remove them: replace '??)' by ']'.
228+ 2 | char b??(5??) = ??< 'b', 'l', 'o',??/
229+ ^~~
230+ :2:17: lexer warning: Trigraphs are deprecated in C23. Please remove them: replace '??<' by '{'.
231+ 2 | char b??(5??) = ??< 'b', 'l', 'o',??/
232+ ^~~
233+ :2:35: lexer warning: Trigraphs are deprecated in C23. Please remove them: replace '??/' by '\\ '.
234+ 2 | char b??(5??) = ??< 'b', 'l', 'o',??/
235+ ^~~
236+ :3:30: lexer warning: Trigraphs are deprecated in C23. Please remove them: replace '??>' by '}'.
237+ 3 | 'b', '\0 ' ??>;
238+ ^~~
239+ :4:11: lexer warning: Trigraphs are deprecated in C23. Please remove them: replace '??'' by '^'.
240+ 4 | int x = 1 ??' ??- 2 ??! 3;
241+ ^~~
242+ :4:15: lexer warning: Trigraphs are deprecated in C23. Please remove them: replace '??-' by '~'.
243+ 4 | int x = 1 ??' ??- 2 ??! 3;
244+ ^~~
245+ :4:21: lexer warning: Trigraphs are deprecated in C23. Please remove them: replace '??!' by '|'.
246+ 4 | int x = 1 ??' ??- 2 ??! 3;
247+ ^~~
248+ "
211249
212250) ;
0 commit comments