Handle subdirectories existing in parsers' examples folders
This commit is contained in:
parent
d3ac345644
commit
a8d539023d
2 changed files with 8 additions and 4 deletions
|
|
@ -25,7 +25,10 @@ int get_modified_time(const string &path) {
|
|||
}
|
||||
|
||||
string read_file(const string &path) {
|
||||
struct stat file_stat;
|
||||
if (stat(path.c_str(), &file_stat) != 0 || (file_stat.st_mode & S_IFMT) != S_IFREG) return "";
|
||||
ifstream file(path, std::ios::binary);
|
||||
if (!file.good()) return "";
|
||||
istreambuf_iterator<char> file_iterator(file), end_iterator;
|
||||
string content(file_iterator, end_iterator);
|
||||
file.close();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <regex>
|
||||
#include "helpers/file_helpers.h"
|
||||
|
||||
using std::move;
|
||||
using std::regex;
|
||||
using std::regex_search;
|
||||
using std::regex_replace;
|
||||
|
|
@ -95,10 +96,10 @@ vector<ExampleEntry> examples_for_language(string language_name) {
|
|||
vector<ExampleEntry> result;
|
||||
string examples_directory = join_path({"test", "fixtures", "grammars", language_name, "examples"});
|
||||
for (string &filename : list_directory(examples_directory)) {
|
||||
result.push_back({
|
||||
filename,
|
||||
read_file(join_path({examples_directory, filename}))
|
||||
});
|
||||
auto content = read_file(join_path({examples_directory, filename}));
|
||||
if (!content.empty()) {
|
||||
result.push_back({filename, move(content)});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue