Skip to content

Fix for Gherkin's localization #63

Description

@demidovsursu

I try to use .feature files with the language option and found 2 bugs.

  1. In GSteps.h need use "type" not "keyword" because "keyword" contains localized word.
    std::string keyword = children["type"];
  2. 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;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions