@@ -2481,9 +2481,9 @@ static void location12()
24812481 " /**//**/#/**//**/line/**//**/3/**//**/\" file.c\" /**/\n "
24822482 " __LINE__ __FILE__\n " ;
24832483 ASSERT_EQUALS (" \n "
2484- " #line 3 \" file.c\"\n "
2485- " 3 \" file.c\" " ,
2486- preprocess (code));
2484+ " #line 3 \" file.c\"\n "
2485+ " 3 \" file.c\" " ,
2486+ preprocess (code));
24872487}
24882488
24892489static void missingHeader1 ()
@@ -2749,6 +2749,62 @@ static void nullDirective3()
27492749 ASSERT_EQUALS (" \n\n\n\n x = 1 ;" , preprocess (code));
27502750}
27512751
2752+ static void lineDirective1 ()
2753+ {
2754+ const char code[] = " #line 1\n "
2755+ " #line 2 \" header1.h\"\n "
2756+ " # 1\n "
2757+ " # 2 \" header2.h\"\n "
2758+ " # 3 \" header2.h\" 0\n " ;
2759+
2760+ std::vector<std::string> files;
2761+ const simplecpp::TokenList rawtokens (code, files);
2762+
2763+ ASSERT_EQUALS (" 1: # line 1 # line 2 \" header1.h\"\n "
2764+ " #line 2 \" header1.h\"\n "
2765+ " 2: # 1\n "
2766+ " #line 1 \" header1.h\"\n "
2767+ " 1: # 2 \" header2.h\"\n "
2768+ " #line 2 \" header2.h\"\n "
2769+ " 2: # 3 \" header2.h\" 0" ,
2770+ rawtokens.stringify (true ));
2771+
2772+ simplecpp::FileDataCache cache;
2773+ simplecpp::TokenList out (files);
2774+ simplecpp::DUI dui;
2775+ simplecpp::preprocess (out, rawtokens, files, cache, dui);
2776+
2777+ ASSERT_EQUALS (" " , out.stringify (true ));
2778+ }
2779+
2780+ static void lineDirective2 ()
2781+ {
2782+ const char code[] = " #\n "
2783+ " #line 1\n "
2784+ " include\n "
2785+ " #line 1\n "
2786+ " \" header1.h\"\n " ;
2787+
2788+ std::vector<std::string> files;
2789+ const simplecpp::TokenList rawtokens (code, files);
2790+
2791+ ASSERT_EQUALS (" 1: #\n "
2792+ " 2: # line 1\n "
2793+ " #line 1 \"\"\n "
2794+ " 1: include\n "
2795+ " 2: # line 1\n "
2796+ " #line 1 \"\"\n "
2797+ " 1: \" header1.h\" " ,
2798+ rawtokens.stringify (true ));
2799+
2800+ simplecpp::FileDataCache cache;
2801+ simplecpp::TokenList out (files);
2802+ simplecpp::DUI dui;
2803+ simplecpp::preprocess (out, rawtokens, files, cache, dui);
2804+
2805+ ASSERT_EQUALS (" 1: include \" header1.h\" " , out.stringify (true ));
2806+ }
2807+
27522808static void include1 ()
27532809{
27542810 const char code[] = " #include \" A.h\"\n " ;
@@ -4167,6 +4223,9 @@ static void runTests(int argc, char **argv, Input input)
41674223 TEST_CASE (nullDirective2);
41684224 TEST_CASE (nullDirective3);
41694225
4226+ TEST_CASE (lineDirective1);
4227+ TEST_CASE (lineDirective2);
4228+
41704229 TEST_CASE (include1);
41714230 TEST_CASE (include2);
41724231 TEST_CASE (include3);
0 commit comments