@@ -2504,7 +2504,7 @@ static void readfile_nullbyte()
25042504 const char code[] = " ab\0 cd" ;
25052505 simplecpp::OutputList outputList;
25062506 ASSERT_EQUALS (" ab cd" , readfile (code,sizeof (code), &outputList));
2507- ASSERT_EQUALS (true , outputList.empty ()); // should warning be written?
2507+ ASSERT_EQUALS (true , outputList.empty ()); // TODO: should warning be written?
25082508}
25092509
25102510static void readfile_char ()
@@ -2654,6 +2654,41 @@ static void readfile_file_not_found()
26542654 ASSERT_EQUALS (" file0,1,file_not_found,File is missing: NotAFile\n " , toString (outputList));
26552655}
26562656
2657+ static void readfile_empty ()
2658+ {
2659+ const char code[] = " " ;
2660+ simplecpp::OutputList outputList;
2661+ ASSERT_EQUALS (" " , readfile (code,sizeof (code), &outputList));
2662+ ASSERT_EQUALS (true , outputList.empty ());
2663+ }
2664+
2665+ // the BOM/UTF-16 detection reads two bytes
2666+ static void readfile_onebyte ()
2667+ {
2668+ const char code[] = " ." ;
2669+ simplecpp::OutputList outputList;
2670+ ASSERT_EQUALS (" ." , readfile (code,sizeof (code), &outputList));
2671+ ASSERT_EQUALS (true , outputList.empty ());
2672+ }
2673+
2674+ static void readfile_utf16_unsupported ()
2675+ {
2676+ const char code[] = " \xfe\xff\xd8\x3d\xde\x42 " ; // smiley emoji
2677+ simplecpp::OutputList outputList;
2678+ ASSERT_EQUALS (" " , readfile (code,sizeof (code), &outputList));
2679+ 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));
2680+ }
2681+
2682+ static void readfile_utf16_incomplete ()
2683+ {
2684+ const char code[] = " \xfe\xff\x00\x31\x00\x32\x00 " ; // the last UTF16 char is incomplete
2685+ simplecpp::OutputList outputList;
2686+ ASSERT_EQUALS (" 12" , readfile (code,sizeof (code), &outputList));
2687+ ASSERT_EQUALS (true , outputList.empty ());
2688+ }
2689+
2690+ // TODO: test with incomplete BOMs
2691+
26572692static void stringify1 ()
26582693{
26592694 const char code_c[] = " #include \" A.h\"\n "
@@ -3532,6 +3567,10 @@ int main(int argc, char **argv)
35323567 TEST_CASE (readfile_unhandled_chars);
35333568 TEST_CASE (readfile_error);
35343569 TEST_CASE (readfile_file_not_found);
3570+ TEST_CASE (readfile_empty);
3571+ TEST_CASE (readfile_onebyte);
3572+ TEST_CASE (readfile_utf16_unsupported);
3573+ TEST_CASE (readfile_utf16_incomplete);
35353574
35363575 TEST_CASE (stringify1);
35373576
0 commit comments