GUnit
GUnit copied to clipboard
Fix for Gherkin's localization
I try to use .feature files with the language option and found 2 bugs.
- In GSteps.h need use "type" not "keyword" because "keyword" contains localized word.
std::string keyword = children["type"];
- The function read_data in GUnit/Detail/FileUtils.h read chars from utf8 files. I fixed this bug using UnicodeUtilities_read_code_point_from_utf8_source from gherkin-c library.
extern "C" {
typedef struct Utf8Source Utf8Source;
long UnicodeUtilities_read_code_point_from_utf8_source(Utf8Source* utf8_source);
Utf8Source* FileUtf8Source_new(FILE* file);
unsigned char Utf8Source_read(Utf8Source* utf8_source);
void Utf8Source_delete(Utf8Source* utf8_source);
}
inline std::wstring read_file(const std::string &feature) {
FILE* file = fopen(feature.c_str(), "rb");
if (!file) {
throw std::runtime_error("File \"" + feature + "\" not found!");
}
std::wstring r;
Utf8Source* utf8_source = FileUtf8Source_new(file);
for(;;) {
long code = UnicodeUtilities_read_code_point_from_utf8_source(utf8_source);
if (code == WEOF) break;
r+=(wchar_t)code;
}
Utf8Source_delete(utf8_source);
fclose(file);
return r;
}