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 1 commit
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
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
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
4 changes: 3 additions & 1 deletion messages/javascript/test/messagesTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert'
import { Envelope, parseEnvelope } from '../src/index.js'
import { Envelope, parseEnvelope, StepKeywordType } from '../src/index.js'

describe('messages', () => {
it('defaults missing fields when deserialising from JSON', () => {
Expand All @@ -18,6 +18,7 @@ describe('messages', () => {
{
id: '0',
keyword: 'Given ',
keywordType: StepKeywordType.CONTEXT,
location: { column: 5, line: 4 },
text: 'the minimalism',
},
Expand Down Expand Up @@ -61,6 +62,7 @@ describe('messages', () => {
{
id: '0',
keyword: 'Given ',
keywordType: StepKeywordType.CONTEXT,
location: { column: 5, line: 4 },
text: 'the minimalism',
},
Expand Down
12 changes: 12 additions & 0 deletions messages/jsonschema/GherkinDocument.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,20 @@
"description": "The location of the steps' `keyword`"
},
"keyword": {
"description": "The actual keyword as it appeared in the source.",
"type": "string"
},
"keywordType": {
"description": "The test phase signalled by the keyword: Context definition (Given), Action performance (When), Outcome assertion (Then). Other keywords signal Continuation (And and But) from a prior keyword. Please note that all translations which a dialect maps to multiple keywords (`*` is in this category for all dialects), map to 'Unknown'.",
"type": "string",
"enum": [
"Unknown",
"Context",
"Action",
"Outcome",
"Conjunction"
]
},
"text": {
"type": "string"
},
Expand Down
10 changes: 10 additions & 0 deletions messages/jsonschema/Pickle.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
"description": "A unique ID for the PickleStep",
"type": "string"
},
"type": {
"description": "The context in which the step was specified: context (Given), action (When) or outcome (Then).\n\nNote that the keywords `But` and `And` inherit their meaning from prior steps and the `*` 'keyword' doesn't have specific meaning (hence Unknown)",
"type": "string",
"enum": [
"Unknown",
"Context",
"Action",
"Outcome"
]
},
"text": {
"type": "string"
}
Expand Down
Loading