Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand the messages protocol with keyword types (extracted from #1741) #1966

Merged
merged 4 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gherkin/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>[18.0.0,19.0.0)</version>
<version>19.0.0-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Optional;
import java.util.Set;

import static java.util.Collections.unmodifiableSet;
import static java.util.Objects.requireNonNull;

public final class GherkinDialectProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ private Object getTransformedNode(AstNode node) {
return new Step(
getLocation(stepLine, 0),
stepLine.matchedKeyword,
// TODO: do not pass null - fix this in 1741
null,
stepLine.matchedText,
node.getSingle(RuleType.DocString, null),
node.getSingle(RuleType.DataTable, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ private PickleStep pickleStep(Step step, List<TableCell> variableCells, TableRow
argument,
astNodeIds,
idGenerator.newId(),
// TODO: do not pass null - fix this in 1741
null,
stepText
);
}
Expand Down
5 changes: 5 additions & 0 deletions messages/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

* Expand the messages protocol with keyword types ([#1966](https://github.com/cucumber/common/pull/1966))

### Changed

* [Java] the `PickleStep` constructor has changed - it now needs an extra `PickleStepType` argument.
* [Java] the `Step` constructor has changed - it now needs an extra `StepKeywordType` argument.

### Deprecated

### Removed
Expand Down
65 changes: 59 additions & 6 deletions messages/go/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ type Scenario struct {
}

type Step struct {
Location *Location `json:"location"`
Keyword string `json:"keyword"`
Text string `json:"text"`
DocString *DocString `json:"docString,omitempty"`
DataTable *DataTable `json:"dataTable,omitempty"`
Id string `json:"id"`
Location *Location `json:"location"`
Keyword string `json:"keyword"`
KeywordType StepKeywordType `json:"keywordType,omitempty"`
Text string `json:"text"`
DocString *DocString `json:"docString,omitempty"`
DataTable *DataTable `json:"dataTable,omitempty"`
Id string `json:"id"`
}

type TableCell struct {
Expand Down Expand Up @@ -219,6 +220,7 @@ type PickleStep struct {
Argument *PickleStepArgument `json:"argument,omitempty"`
AstNodeIds []string `json:"astNodeIds"`
Id string `json:"id"`
Type PickleStepType `json:"type,omitempty"`
Text string `json:"text"`
}

Expand Down Expand Up @@ -379,6 +381,30 @@ func (e AttachmentContentEncoding) String() string {
}
}

type PickleStepType string

const (
PickleStepType_UNKNOWN PickleStepType = "Unknown"
PickleStepType_CONTEXT PickleStepType = "Context"
PickleStepType_ACTION PickleStepType = "Action"
PickleStepType_OUTCOME PickleStepType = "Outcome"
)

func (e PickleStepType) String() string {
switch e {
case PickleStepType_UNKNOWN:
return "Unknown"
case PickleStepType_CONTEXT:
return "Context"
case PickleStepType_ACTION:
return "Action"
case PickleStepType_OUTCOME:
return "Outcome"
default:
panic("Bad enum value for PickleStepType")
}
}

type SourceMediaType string

const (
Expand Down Expand Up @@ -415,6 +441,33 @@ func (e StepDefinitionPatternType) String() string {
}
}

type StepKeywordType string

const (
StepKeywordType_UNKNOWN StepKeywordType = "Unknown"
StepKeywordType_CONTEXT StepKeywordType = "Context"
StepKeywordType_ACTION StepKeywordType = "Action"
StepKeywordType_OUTCOME StepKeywordType = "Outcome"
StepKeywordType_CONJUNCTION StepKeywordType = "Conjunction"
)

func (e StepKeywordType) String() string {
switch e {
case StepKeywordType_UNKNOWN:
return "Unknown"
case StepKeywordType_CONTEXT:
return "Context"
case StepKeywordType_ACTION:
return "Action"
case StepKeywordType_OUTCOME:
return "Outcome"
case StepKeywordType_CONJUNCTION:
return "Conjunction"
default:
panic("Bad enum value for StepKeywordType")
}
}

type TestStepResultStatus string

const (
Expand Down
2 changes: 1 addition & 1 deletion messages/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<version>2.3.2</version>
</parent>
<artifactId>messages</artifactId>
<version>18.0.1-SNAPSHOT</version>
<version>19.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Cucumber Messages</name>
<description>JSON schema-based messages for Cucumber's inter-process communication</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ public final class PickleStep {
private final PickleStepArgument argument;
private final java.util.List<String> astNodeIds;
private final String id;
private final PickleStepType type;
private final String text;

public PickleStep(
PickleStepArgument argument,
java.util.List<String> astNodeIds,
String id,
PickleStepType type,
String text
) {
this.argument = argument;
this.astNodeIds = unmodifiableList(new ArrayList<>(requireNonNull(astNodeIds, "PickleStep.astNodeIds cannot be null")));
this.id = requireNonNull(id, "PickleStep.id cannot be null");
this.type = type;
this.text = requireNonNull(text, "PickleStep.text cannot be null");
}

Expand All @@ -39,6 +42,10 @@ public String getId() {
return id;
}

public Optional<PickleStepType> getType() {
return Optional.ofNullable(type);
}

public String getText() {
return text;
}
Expand All @@ -52,6 +59,7 @@ public boolean equals(Object o) {
Objects.equals(argument, that.argument) &&
astNodeIds.equals(that.astNodeIds) &&
id.equals(that.id) &&
Objects.equals(type, that.type) &&
text.equals(that.text);
}

Expand All @@ -61,6 +69,7 @@ public int hashCode() {
argument,
astNodeIds,
id,
type,
text
);
}
Expand All @@ -71,6 +80,7 @@ public String toString() {
"argument=" + argument +
", astNodeIds=" + astNodeIds +
", id=" + id +
", type=" + type +
", text=" + text +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.cucumber.messages.types;

// Generated code
@SuppressWarnings("unused")
public enum PickleStepType {

UNKNOWN("Unknown"),

CONTEXT("Context"),

ACTION("Action"),

OUTCOME("Outcome");

private final String value;

PickleStepType(String value) {
this.value = value;
}

@Override
public String toString() {
return this.value;
}

public String value() {
return this.value;
}

public static PickleStepType fromValue(String value) {
for (PickleStepType v : values()) {
if (v.value.equals(value)) {
return v;
}
}
throw new IllegalArgumentException(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public final class Step {
private final Location location;
private final String keyword;
private final StepKeywordType keywordType;
private final String text;
private final DocString docString;
private final DataTable dataTable;
Expand All @@ -20,13 +21,15 @@ public final class Step {
public Step(
Location location,
String keyword,
StepKeywordType keywordType,
String text,
DocString docString,
DataTable dataTable,
String id
) {
this.location = requireNonNull(location, "Step.location cannot be null");
this.keyword = requireNonNull(keyword, "Step.keyword cannot be null");
this.keywordType = keywordType;
this.text = requireNonNull(text, "Step.text cannot be null");
this.docString = docString;
this.dataTable = dataTable;
Expand All @@ -41,6 +44,10 @@ public String getKeyword() {
return keyword;
}

public Optional<StepKeywordType> getKeywordType() {
return Optional.ofNullable(keywordType);
}

public String getText() {
return text;
}
Expand All @@ -65,6 +72,7 @@ public boolean equals(Object o) {
return
location.equals(that.location) &&
keyword.equals(that.keyword) &&
Objects.equals(keywordType, that.keywordType) &&
text.equals(that.text) &&
Objects.equals(docString, that.docString) &&
Objects.equals(dataTable, that.dataTable) &&
Expand All @@ -76,6 +84,7 @@ public int hashCode() {
return Objects.hash(
location,
keyword,
keywordType,
text,
docString,
dataTable,
Expand All @@ -88,6 +97,7 @@ public String toString() {
return "Step{" +
"location=" + location +
", keyword=" + keyword +
", keywordType=" + keywordType +
", text=" + text +
", docString=" + docString +
", dataTable=" + dataTable +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.cucumber.messages.types;

// Generated code
@SuppressWarnings("unused")
public enum StepKeywordType {

UNKNOWN("Unknown"),

CONTEXT("Context"),

ACTION("Action"),

OUTCOME("Outcome"),

CONJUNCTION("Conjunction");

private final String value;

StepKeywordType(String value) {
this.value = value;
}

@Override
public String toString() {
return this.value;
}

public String value() {
return this.value;
}

public static StepKeywordType fromValue(String value) {
for (StepKeywordType v : values()) {
if (v.value.equals(value)) {
return v;
}
}
throw new IllegalArgumentException(value);
}
}
19 changes: 19 additions & 0 deletions messages/javascript/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ export class Step {

keyword: string = ''

keywordType?: StepKeywordType

text: string = ''

@Type(() => DocString)
Expand Down Expand Up @@ -418,6 +420,8 @@ export class PickleStep {

id: string = ''

type?: PickleStepType

text: string = ''
}

Expand Down Expand Up @@ -651,6 +655,13 @@ export enum AttachmentContentEncoding {
BASE64 = 'BASE64',
}

export enum PickleStepType {
UNKNOWN = 'Unknown',
CONTEXT = 'Context',
ACTION = 'Action',
OUTCOME = 'Outcome',
}

export enum SourceMediaType {
TEXT_X_CUCUMBER_GHERKIN_PLAIN = 'text/x.cucumber.gherkin+plain',
TEXT_X_CUCUMBER_GHERKIN_MARKDOWN = 'text/x.cucumber.gherkin+markdown',
Expand All @@ -661,6 +672,14 @@ export enum StepDefinitionPatternType {
REGULAR_EXPRESSION = 'REGULAR_EXPRESSION',
}

export enum StepKeywordType {
UNKNOWN = 'Unknown',
CONTEXT = 'Context',
ACTION = 'Action',
OUTCOME = 'Outcome',
CONJUNCTION = 'Conjunction',
}

export enum TestStepResultStatus {
UNKNOWN = 'UNKNOWN',
PASSED = 'PASSED',
Expand Down
Loading