@@ -67,6 +67,38 @@ fn empty_source() -> Result<(), MietteError> {
67
67
Ok ( ( ) )
68
68
}
69
69
70
+ #[ test]
71
+ fn single_line_highlight_span_full_line ( ) {
72
+ #[ derive( Error , Debug , Diagnostic ) ]
73
+ #[ error( "oops!" ) ]
74
+ #[ diagnostic( severity( Error ) ) ]
75
+ struct MyBad {
76
+ #[ source_code]
77
+ src : NamedSource ,
78
+ #[ label( "This bit here" ) ]
79
+ bad_bit : SourceSpan ,
80
+ }
81
+ let err = MyBad {
82
+ src : NamedSource :: new ( "issue" , "source\n text" ) ,
83
+ bad_bit : ( 7 , 4 ) . into ( ) ,
84
+ } ;
85
+ let out = fmt_report ( err. into ( ) ) ;
86
+ println ! ( "Error: {}" , out) ;
87
+
88
+ let expected = r#"
89
+ × oops!
90
+ ╭─[issue:1:1]
91
+ 1 │ source
92
+ 2 │ text
93
+ · ──┬─
94
+ · ╰── This bit here
95
+ ╰────
96
+ "#
97
+ . to_string ( ) ;
98
+
99
+ assert_eq ! ( expected, out) ;
100
+ }
101
+
70
102
#[ test]
71
103
fn single_line_with_wide_char ( ) -> Result < ( ) , MietteError > {
72
104
#[ derive( Debug , Diagnostic , Error ) ]
@@ -290,6 +322,42 @@ fn single_line_highlight_offset_zero() -> Result<(), MietteError> {
290
322
Ok ( ( ) )
291
323
}
292
324
325
+ #[ test]
326
+ fn single_line_higlight_offset_end_of_line ( ) -> Result < ( ) , MietteError > {
327
+ #[ derive( Debug , Diagnostic , Error ) ]
328
+ #[ error( "oops!" ) ]
329
+ #[ diagnostic( code( oops:: my:: bad) , help( "try doing it better next time?" ) ) ]
330
+ struct MyBad {
331
+ #[ source_code]
332
+ src : NamedSource ,
333
+ #[ label( "this bit here" ) ]
334
+ highlight : SourceSpan ,
335
+ }
336
+
337
+ let src = "source\n text\n here" . to_string ( ) ;
338
+ let err = MyBad {
339
+ src : NamedSource :: new ( "bad_file.rs" , src) ,
340
+ highlight : ( 6 , 0 ) . into ( ) ,
341
+ } ;
342
+ let out = fmt_report ( err. into ( ) ) ;
343
+ println ! ( "Error: {}" , out) ;
344
+ let expected = r#"oops::my::bad
345
+
346
+ × oops!
347
+ ╭─[bad_file.rs:1:1]
348
+ 1 │ source
349
+ · ▲
350
+ · ╰── this bit here
351
+ 2 │ text
352
+ ╰────
353
+ help: try doing it better next time?
354
+ "#
355
+ . trim_start ( )
356
+ . to_string ( ) ;
357
+ assert_eq ! ( expected, out) ;
358
+ Ok ( ( ) )
359
+ }
360
+
293
361
#[ test]
294
362
fn single_line_highlight_with_empty_span ( ) -> Result < ( ) , MietteError > {
295
363
#[ derive( Debug , Diagnostic , Error ) ]
0 commit comments