@@ -2575,7 +2575,7 @@ static void readfile_nullbyte()
25752575 const char code[] = " ab\0 cd" ;
25762576 simplecpp::OutputList outputList;
25772577 ASSERT_EQUALS (" ab cd" , readfile (code,sizeof (code), &outputList));
2578- ASSERT_EQUALS (true , outputList.empty ()); // should warning be written?
2578+ ASSERT_EQUALS (true , outputList.empty ()); // TODO: should warning be written?
25792579}
25802580
25812581static void readfile_char ()
@@ -2725,6 +2725,41 @@ static void readfile_file_not_found()
27252725 ASSERT_EQUALS (" file0,1,file_not_found,File is missing: NotAFile\n " , toString (outputList));
27262726}
27272727
2728+ static void readfile_empty ()
2729+ {
2730+ const char code[] = " " ;
2731+ simplecpp::OutputList outputList;
2732+ ASSERT_EQUALS (" " , readfile (code,sizeof (code), &outputList));
2733+ ASSERT_EQUALS (true , outputList.empty ());
2734+ }
2735+
2736+ // the BOM/UTF-16 detection reads two bytes
2737+ static void readfile_onebyte ()
2738+ {
2739+ const char code[] = " ." ;
2740+ simplecpp::OutputList outputList;
2741+ ASSERT_EQUALS (" ." , readfile (code,sizeof (code), &outputList));
2742+ ASSERT_EQUALS (true , outputList.empty ());
2743+ }
2744+
2745+ static void readfile_utf16_unsupported ()
2746+ {
2747+ const char code[] = " \xfe\xff\xd8\x3d\xde\x42 " ; // smiley emoji
2748+ simplecpp::OutputList outputList;
2749+ ASSERT_EQUALS (" " , readfile (code,sizeof (code), &outputList));
2750+ ASSERT_EQUALS (" file0,1,unhandled_char_error,The code contains unhandled character(s) (character code=255). Neither unicode nor extended ascii is supported.\n " , toString (outputList));
2751+ }
2752+
2753+ static void readfile_utf16_incomplete ()
2754+ {
2755+ const char code[] = " \xfe\xff\x00\x31\x00\x32\x00 " ; // the last UTF16 char is incomplete
2756+ simplecpp::OutputList outputList;
2757+ ASSERT_EQUALS (" 12" , readfile (code,sizeof (code), &outputList));
2758+ ASSERT_EQUALS (true , outputList.empty ());
2759+ }
2760+
2761+ // TODO: test with incomplete BOMs
2762+
27282763static void stringify1 ()
27292764{
27302765 const char code_c[] = " #include \" A.h\"\n "
@@ -3609,6 +3644,10 @@ int main(int argc, char **argv)
36093644 TEST_CASE (readfile_unhandled_chars);
36103645 TEST_CASE (readfile_error);
36113646 TEST_CASE (readfile_file_not_found);
3647+ TEST_CASE (readfile_empty);
3648+ TEST_CASE (readfile_onebyte);
3649+ TEST_CASE (readfile_utf16_unsupported);
3650+ TEST_CASE (readfile_utf16_incomplete);
36123651
36133652 TEST_CASE (stringify1);
36143653
0 commit comments