use of io.cucumber.gherkin.GherkinDialectProvider in project cucumber-jvm by cucumber.
the class CommandlineOptionsParser method printI18n.
private byte printI18n(String language) {
IGherkinDialectProvider dialectProvider = new GherkinDialectProvider();
List<String> languages = dialectProvider.getLanguages();
if (language.equalsIgnoreCase("help")) {
if (language.equalsIgnoreCase("help")) {
List<GherkinDialect> dialects = new ArrayList<>();
for (String code : languages) {
GherkinDialect dialect = dialectProvider.getDialect(code, null);
dialects.add(dialect);
}
int widestLanguage = findWidest(dialects, GherkinDialect::getLanguage);
int widestName = findWidest(dialects, GherkinDialect::getName);
int widestNativeName = findWidest(dialects, GherkinDialect::getNativeName);
for (GherkinDialect dialect : dialects) {
printDialect(dialect, widestLanguage, widestName, widestNativeName);
}
return 0x0;
}
}
if (languages.contains(language)) {
return printKeywordsFor(dialectProvider.getDialect(language, null));
}
out.println("Unrecognised ISO language code");
return 0x1;
}
use of io.cucumber.gherkin.GherkinDialectProvider in project cucumber-jvm by cucumber.
the class GherkinMessagesFeatureParser method parse.
@Override
public Optional<Feature> parse(URI path, String source, Supplier<UUID> idGenerator) {
List<Envelope> sources = singletonList(makeSourceEnvelope(source, path.toString()));
List<Envelope> envelopes = Gherkin.fromSources(sources, true, true, true, () -> idGenerator.get().toString()).collect(toList());
GherkinDocument gherkinDocument = envelopes.stream().map(Envelope::getGherkinDocument).filter(Objects::nonNull).findFirst().orElse(null);
if (gherkinDocument == null || gherkinDocument.getFeature() == null) {
List<String> errors = envelopes.stream().map(Envelope::getParseError).filter(Objects::nonNull).map(ParseError::getMessage).collect(toList());
if (!errors.isEmpty()) {
throw new FeatureParserException("Failed to parse resource at: " + path + "\n" + String.join("\n", errors));
}
return Optional.empty();
}
CucumberQuery cucumberQuery = new CucumberQuery();
cucumberQuery.update(gherkinDocument);
GherkinDialectProvider dialectProvider = new GherkinDialectProvider();
io.cucumber.messages.types.Feature feature = gherkinDocument.getFeature();
String language = feature.getLanguage();
GherkinDialect dialect = dialectProvider.getDialect(language, null);
List<io.cucumber.messages.types.Pickle> pickleMessages = envelopes.stream().map(Envelope::getPickle).filter(Objects::nonNull).collect(toList());
List<Pickle> pickles = pickleMessages.stream().map(pickle -> new GherkinMessagesPickle(pickle, path, dialect, cucumberQuery)).collect(toList());
GherkinMessagesFeature messagesFeature = new GherkinMessagesFeature(feature, path, source, pickles, envelopes);
return Optional.of(messagesFeature);
}
Aggregations