Skip to content

Commit e8c1fd9

Browse files
committed
test.cpp: run tests with filename input
1 parent 40ab6df commit e8c1fd9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
enum Input {
2727
Stringstream,
28-
Fstream
28+
Fstream,
29+
File
2930
};
3031

3132
static Input USE_INPUT = Stringstream;
@@ -51,6 +52,8 @@ static const char* inputString(Input input) {
5152
return "Stringstream";
5253
case Fstream:
5354
return "Fstream";
55+
case File:
56+
return "File";
5457
}
5558
}
5659

@@ -111,6 +114,14 @@ static simplecpp::TokenList makeTokenListFromFstream(const char code[], std::siz
111114
return tokenList;
112115
}
113116

117+
static simplecpp::TokenList makeTokenListFromFile(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename, simplecpp::OutputList *outputList)
118+
{
119+
const std::string tmpfile = writeFile(code, size, filename);
120+
simplecpp::TokenList tokenList(tmpfile, filenames, outputList);
121+
remove(tmpfile.c_str());
122+
return tokenList;
123+
}
124+
114125
static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
115126
{
116127
switch (USE_INPUT) {
@@ -120,6 +131,8 @@ static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, s
120131
}
121132
case Fstream:
122133
return makeTokenListFromFstream(code, size, filenames, filename, outputList);
134+
case File:
135+
return makeTokenListFromFile(code, size, filenames, filename, outputList);
123136
}
124137
}
125138

@@ -2815,5 +2828,6 @@ int main(int argc, char **argv)
28152828
{
28162829
runTests(argc, argv, Stringstream);
28172830
runTests(argc, argv, Fstream);
2831+
runTests(argc, argv, File);
28182832
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
28192833
}

0 commit comments

Comments
 (0)