File tree 2 files changed +51
-1
lines changed
2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -1149,7 +1149,7 @@ fn format_header<'a>(
1149
1149
..
1150
1150
} = item
1151
1151
{
1152
- if main_range >= range. 0 && main_range <= range. 1 + end_line . len ( ) {
1152
+ if main_range >= range. 0 && main_range < range. 1 + max ( * end_line as usize , 1 ) {
1153
1153
let char_column = text[ 0 ..( main_range - range. 0 ) . min ( text. len ( ) ) ]
1154
1154
. chars ( )
1155
1155
. count ( ) ;
Original file line number Diff line number Diff line change @@ -905,3 +905,53 @@ error: unused optional dependency
905
905
let renderer = Renderer :: plain ( ) ;
906
906
assert_data_eq ! ( renderer. render( input) . to_string( ) , expected) ;
907
907
}
908
+
909
+ #[ test]
910
+ fn origin_correct_start_line ( ) {
911
+ let source = "aaa\n bbb\n ccc\n ddd\n " ;
912
+ let input = Level :: Error . title ( "title" ) . snippet (
913
+ Snippet :: source ( source)
914
+ . origin ( "origin.txt" )
915
+ . fold ( false )
916
+ . annotation ( Level :: Error . span ( 8 ..8 + 3 ) . label ( "annotation" ) ) ,
917
+ ) ;
918
+
919
+ let expected = str![ [ r#"
920
+ error: title
921
+ --> origin.txt:3:1
922
+ |
923
+ 1 | aaa
924
+ 2 | bbb
925
+ 3 | ccc
926
+ | ^^^ annotation
927
+ 4 | ddd
928
+ |
929
+ "# ] ] ;
930
+ let renderer = Renderer :: plain ( ) ;
931
+ assert_data_eq ! ( renderer. render( input) . to_string( ) , expected) ;
932
+ }
933
+
934
+ #[ test]
935
+ fn origin_correct_mid_line ( ) {
936
+ let source = "aaa\n bbb\n ccc\n ddd\n " ;
937
+ let input = Level :: Error . title ( "title" ) . snippet (
938
+ Snippet :: source ( source)
939
+ . origin ( "origin.txt" )
940
+ . fold ( false )
941
+ . annotation ( Level :: Error . span ( 8 + 1 ..8 + 3 ) . label ( "annotation" ) ) ,
942
+ ) ;
943
+
944
+ let expected = str![ [ r#"
945
+ error: title
946
+ --> origin.txt:3:2
947
+ |
948
+ 1 | aaa
949
+ 2 | bbb
950
+ 3 | ccc
951
+ | ^^ annotation
952
+ 4 | ddd
953
+ |
954
+ "# ] ] ;
955
+ let renderer = Renderer :: plain ( ) ;
956
+ assert_data_eq ! ( renderer. render( input) . to_string( ) , expected) ;
957
+ }
You can’t perform that action at this time.
0 commit comments