Skip to content

Commit 4f6415f

Browse files
committed
test.cpp: run tests with filename input
1 parent 04e5208 commit 4f6415f

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

test.cpp

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

2121
enum Input {
2222
Stringstream,
23-
Fstream
23+
Fstream,
24+
File
2425
};
2526

2627
static Input USE_INPUT = Stringstream;
@@ -46,6 +47,8 @@ static const char* inputString(Input input) {
4647
return "Stringstream";
4748
case Fstream:
4849
return "Fstream";
50+
case File:
51+
return "File";
4952
}
5053
}
5154

@@ -106,6 +109,14 @@ static simplecpp::TokenList makeTokenListFromFstream(const char code[], std::siz
106109
return tokenList;
107110
}
108111

112+
static simplecpp::TokenList makeTokenListFromFile(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename, simplecpp::OutputList *outputList)
113+
{
114+
const std::string tmpfile = writeFile(code, size, filename);
115+
simplecpp::TokenList tokenList(tmpfile, filenames, outputList);
116+
remove(tmpfile.c_str());
117+
return tokenList;
118+
}
119+
109120
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)
110121
{
111122
switch (USE_INPUT) {
@@ -115,6 +126,8 @@ static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, s
115126
}
116127
case Fstream:
117128
return makeTokenListFromFstream(code, size, filenames, filename, outputList);
129+
case File:
130+
return makeTokenListFromFile(code, size, filenames, filename, outputList);
118131
}
119132
}
120133

@@ -3004,5 +3017,6 @@ int main(int argc, char **argv)
30043017
{
30053018
runTests(argc, argv, Stringstream);
30063019
runTests(argc, argv, Fstream);
3020+
runTests(argc, argv, File);
30073021
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
30083022
}

0 commit comments

Comments
 (0)