@@ -7,6 +7,7 @@ describe("parsing", ({test, testSkip}) => {
77 let test_or_skip =
88 Sys . backend_type == Other ("js_of_ocaml" ) ? testSkip : test;
99 let assertParse = makeParseRunner(test);
10+ let assertCompileError = makeCompileErrorRunner(test);
1011 let assertFileRun = makeFileRunner(test_or_skip);
1112
1213 // operators
@@ -237,4 +238,137 @@ describe("parsing", ({test, testSkip}) => {
237238 prog_loc: Location . dummy_loc,
238239 },
239240 );
241+
242+ // Whitespace tests
243+
244+ // Reason does not support OCaml's Unicode escapes, which is why these are
245+ // UTF-8 byte sequences instead of pretty Unicode escapes
246+
247+ assertParse(
248+ "whitespace_1" ,
249+ // In order,
250+ // HORIZONTAL TABULATION
251+ // VERTICAL TABULATION
252+ // SPACE
253+ // LEFT-TO-RIGHT MARK
254+ // RIGHT-TO-LEFT MARK
255+ // LINE FEED
256+ // FORM FEED
257+ // CARRIAGE RETURN
258+ // NEXT LINE
259+ // LINE SEPARATOR
260+ // PARAGRAPH SEPARATOR
261+ "
262+ module Test
263+ \x09
264+ \x0b
265+ \x20
266+ \xe2\x80\x8e
267+ \xe2\x80\x8f
268+ \x0a
269+ \x0c
270+ \x0d
271+ \xc2\x85
272+ \xe2\x80\xa8
273+ \xe2\x80\xa9
274+ " ,
275+ {
276+ module_name: Location . mknoloc("Test" ),
277+ statements: [] ,
278+ comments: [] ,
279+ prog_loc: Location . dummy_loc,
280+ },
281+ );
282+
283+ assertCompileError(
284+ "invalid_whitespace_nbsp" ,
285+ "\xc2\xa0 " ,
286+ "Grain lexer doesn't recognize this token" ,
287+ );
288+ assertCompileError(
289+ "invalid_whitespace_emspace" ,
290+ "\xe2\x80\x83 " ,
291+ "Grain lexer doesn't recognize this token" ,
292+ );
293+ assertCompileError(
294+ "invalid_whitespace_hairspace" ,
295+ "\xe2\x80\x8a " ,
296+ "Grain lexer doesn't recognize this token" ,
297+ );
298+ assertCompileError(
299+ "invalid_whitespace_ideographicspace" ,
300+ "\xe3\x80\x80 " ,
301+ "Grain lexer doesn't recognize this token" ,
302+ );
303+
304+ assertParse(
305+ "end_of_statement_linefeed" ,
306+ "module Test; a\x0a b" ,
307+ {
308+ module_name: Location . mknoloc("Test" ),
309+ statements: [ Toplevel . expr(a), Toplevel . expr(b)] ,
310+ comments: [] ,
311+ prog_loc: Location . dummy_loc,
312+ },
313+ );
314+ assertParse(
315+ "end_of_statement_formfeed" ,
316+ "module Test; a\x0c b" ,
317+ {
318+ module_name: Location . mknoloc("Test" ),
319+ statements: [ Toplevel . expr(a), Toplevel . expr(b)] ,
320+ comments: [] ,
321+ prog_loc: Location . dummy_loc,
322+ },
323+ );
324+ assertParse(
325+ "end_of_statement_carriagereturn" ,
326+ "module Test; a\x0d b" ,
327+ {
328+ module_name: Location . mknoloc("Test" ),
329+ statements: [ Toplevel . expr(a), Toplevel . expr(b)] ,
330+ comments: [] ,
331+ prog_loc: Location . dummy_loc,
332+ },
333+ );
334+ assertParse(
335+ "end_of_statement_crlf" ,
336+ "module Test; a\x0d\x0a b" ,
337+ {
338+ module_name: Location . mknoloc("Test" ),
339+ statements: [ Toplevel . expr(a), Toplevel . expr(b)] ,
340+ comments: [] ,
341+ prog_loc: Location . dummy_loc,
342+ },
343+ );
344+ assertParse(
345+ "end_of_statement_nextline" ,
346+ "module Test; a\xc2\x85 b" ,
347+ {
348+ module_name: Location . mknoloc("Test" ),
349+ statements: [ Toplevel . expr(a), Toplevel . expr(b)] ,
350+ comments: [] ,
351+ prog_loc: Location . dummy_loc,
352+ },
353+ );
354+ assertParse(
355+ "end_of_statement_lineseparator" ,
356+ "module Test; a\xe2\x80\xa8 b" ,
357+ {
358+ module_name: Location . mknoloc("Test" ),
359+ statements: [ Toplevel . expr(a), Toplevel . expr(b)] ,
360+ comments: [] ,
361+ prog_loc: Location . dummy_loc,
362+ },
363+ );
364+ assertParse(
365+ "end_of_statement_paragraphseparator" ,
366+ "module Test; a\xe2\x80\xa9 b" ,
367+ {
368+ module_name: Location . mknoloc("Test" ),
369+ statements: [ Toplevel . expr(a), Toplevel . expr(b)] ,
370+ comments: [] ,
371+ prog_loc: Location . dummy_loc,
372+ },
373+ );
240374});
0 commit comments