@@ -1097,6 +1097,102 @@ mod tests {
1097
1097
"### ) ;
1098
1098
}
1099
1099
1100
+ #[ test]
1101
+ fn empty_input ( ) {
1102
+ let source = "" ;
1103
+ let msg = Report :: < Range < usize > > :: build ( ReportKind :: Error , ( ) , 0 )
1104
+ . with_config ( no_color_and_ascii ( ) )
1105
+ . with_message ( "unexpected end of file" )
1106
+ . with_label ( Label :: new ( 0 ..0 ) . with_message ( "No more fruit!" ) )
1107
+ . finish ( )
1108
+ . write_to_string ( Source :: from ( source) ) ;
1109
+
1110
+ assert_snapshot ! ( msg, @r###"
1111
+ Error: unexpected end of file
1112
+ ,-[<unknown>:1:1]
1113
+ |
1114
+ 1 |
1115
+ | |
1116
+ | `- No more fruit!
1117
+ ---'
1118
+ "### ) ;
1119
+ }
1120
+
1121
+ #[ test]
1122
+ fn empty_input_help ( ) {
1123
+ let source = "" ;
1124
+ let msg = Report :: < Range < usize > > :: build ( ReportKind :: Error , ( ) , 0 )
1125
+ . with_config ( no_color_and_ascii ( ) )
1126
+ . with_message ( "unexpected end of file" )
1127
+ . with_label ( Label :: new ( 0 ..0 ) . with_message ( "No more fruit!" ) )
1128
+ . with_help ( "have you tried going to the farmer's market?" )
1129
+ . finish ( )
1130
+ . write_to_string ( Source :: from ( source) ) ;
1131
+
1132
+ assert_snapshot ! ( msg, @r###"
1133
+ Error: unexpected end of file
1134
+ ,-[<unknown>:1:1]
1135
+ |
1136
+ 1 |
1137
+ | |
1138
+ | `- No more fruit!
1139
+ |
1140
+ | Help: have you tried going to the farmer's market?
1141
+ ---'
1142
+ "### ) ;
1143
+ }
1144
+
1145
+ #[ test]
1146
+ fn empty_input_note ( ) {
1147
+ let source = "" ;
1148
+ let msg = Report :: < Range < usize > > :: build ( ReportKind :: Error , ( ) , 0 )
1149
+ . with_config ( no_color_and_ascii ( ) )
1150
+ . with_message ( "unexpected end of file" )
1151
+ . with_label ( Label :: new ( 0 ..0 ) . with_message ( "No more fruit!" ) )
1152
+ . with_note ( "eat your greens!" )
1153
+ . finish ( )
1154
+ . write_to_string ( Source :: from ( source) ) ;
1155
+
1156
+ assert_snapshot ! ( msg, @r###"
1157
+ Error: unexpected end of file
1158
+ ,-[<unknown>:1:1]
1159
+ |
1160
+ 1 |
1161
+ | |
1162
+ | `- No more fruit!
1163
+ |
1164
+ | Note: eat your greens!
1165
+ ---'
1166
+ "### ) ;
1167
+ }
1168
+
1169
+ #[ test]
1170
+ fn empty_input_help_note ( ) {
1171
+ let source = "" ;
1172
+ let msg = Report :: < Range < usize > > :: build ( ReportKind :: Error , ( ) , 0 )
1173
+ . with_config ( no_color_and_ascii ( ) )
1174
+ . with_message ( "unexpected end of file" )
1175
+ . with_label ( Label :: new ( 0 ..0 ) . with_message ( "No more fruit!" ) )
1176
+ . with_note ( "eat your greens!" )
1177
+ . with_help ( "have you tried going to the farmer's market?" )
1178
+ . finish ( )
1179
+ . write_to_string ( Source :: from ( source) ) ;
1180
+
1181
+ assert_snapshot ! ( msg, @r###"
1182
+ Error: unexpected end of file
1183
+ ,-[<unknown>:1:1]
1184
+ |
1185
+ 1 |
1186
+ | |
1187
+ | `- No more fruit!
1188
+ |
1189
+ | Help: have you tried going to the farmer's market?
1190
+ |
1191
+ | Note: eat your greens!
1192
+ ---'
1193
+ "### ) ;
1194
+ }
1195
+
1100
1196
#[ test]
1101
1197
fn byte_spans_never_crash ( ) {
1102
1198
let source = "apple\n p\n \n empty\n " ;
0 commit comments