Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.idea
*.iml
.php-cs-fixer.cache
2 changes: 2 additions & 0 deletions cpp/include/messages/cucumber/messages/hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <nlohmann/json.hpp>

#include <cucumber/messages/source_reference.hpp>
#include <cucumber/messages/hook_type.hpp>

namespace cucumber::messages {

Expand All @@ -24,6 +25,7 @@ struct hook
std::optional<std::string> name;
cucumber::messages::source_reference source_reference;
std::optional<std::string> tag_expression;
std::optional<cucumber::messages::hook_type> type;

std::string to_string() const;

Expand Down
21 changes: 21 additions & 0 deletions cpp/include/messages/cucumber/messages/hook_type.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <string_view>

namespace cucumber::messages {

enum class hook_type
{
BEFORE,
AFTER,
BEFORE_STEP,
AFTER_STEP
};

std::string_view
to_string(hook_type v);

std::ostream&
operator<<(std::ostream& os, hook_type v);

}
2 changes: 2 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ hook::to_string() const
cucumber::messages::to_string(oss, ", name=", name);
cucumber::messages::to_string(oss, ", source_reference=", source_reference);
cucumber::messages::to_string(oss, ", tag_expression=", tag_expression);
cucumber::messages::to_string(oss, ", type=", type);

return oss.str();
}
Expand All @@ -25,6 +26,7 @@ hook::to_json(json& j) const
cucumber::messages::to_json(j, camelize("name"), name);
cucumber::messages::to_json(j, camelize("source_reference"), source_reference);
cucumber::messages::to_json(j, camelize("tag_expression"), tag_expression);
cucumber::messages::to_json(j, camelize("type"), type);
}

std::string
Expand Down
31 changes: 31 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/hook_type.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include <unordered_map>

#include <cucumber/messages/hook_type.hpp>

namespace cucumber::messages {

std::string_view
to_string(hook_type v)
{
using map_type = std::unordered_map<hook_type, std::string_view>;

static const map_type m = {
{ hook_type::BEFORE, "BEFORE" },
{ hook_type::AFTER, "AFTER" },
{ hook_type::BEFORE_STEP, "BEFORE_STEP" },
{ hook_type::AFTER_STEP, "AFTER_STEP" }
};

return m.at(v);
}

std::ostream&
operator<<(std::ostream& os, hook_type v)
{
os << to_string(v);

return os;
}

}
25 changes: 25 additions & 0 deletions go/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ type Hook struct {
Name string `json:"name,omitempty"`
SourceReference *SourceReference `json:"sourceReference"`
TagExpression string `json:"tagExpression,omitempty"`
Type HookType `json:"type,omitempty"`
}

type Location struct {
Expand Down Expand Up @@ -391,6 +392,30 @@ func (e AttachmentContentEncoding) String() string {
}
}

type HookType string

const (
HookType_BEFORE HookType = "BEFORE"
HookType_AFTER HookType = "AFTER"
HookType_BEFORE_STEP HookType = "BEFORE_STEP"
HookType_AFTER_STEP HookType = "AFTER_STEP"
)

func (e HookType) String() string {
switch e {
case HookType_BEFORE:
return "BEFORE"
case HookType_AFTER:
return "AFTER"
case HookType_BEFORE_STEP:
return "BEFORE_STEP"
case HookType_AFTER_STEP:
return "AFTER_STEP"
default:
panic("Bad enum value for HookType")
}
}

type PickleStepType string

const (
Expand Down
16 changes: 13 additions & 3 deletions java/src/generated/java/io/cucumber/messages/types/Hook.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ public final class Hook {
private final String name;
private final SourceReference sourceReference;
private final String tagExpression;
private final HookType type;

public Hook(
String id,
String name,
SourceReference sourceReference,
String tagExpression
String tagExpression,
HookType type
) {
this.id = requireNonNull(id, "Hook.id cannot be null");
this.name = name;
this.sourceReference = requireNonNull(sourceReference, "Hook.sourceReference cannot be null");
this.tagExpression = tagExpression;
this.type = type;
}

public String getId() {
Expand All @@ -47,6 +50,10 @@ public Optional<String> getTagExpression() {
return Optional.ofNullable(tagExpression);
}

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

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -56,7 +63,8 @@ public boolean equals(Object o) {
id.equals(that.id) &&
Objects.equals(name, that.name) &&
sourceReference.equals(that.sourceReference) &&
Objects.equals(tagExpression, that.tagExpression);
Objects.equals(tagExpression, that.tagExpression) &&
Objects.equals(type, that.type);
}

@Override
Expand All @@ -65,7 +73,8 @@ public int hashCode() {
id,
name,
sourceReference,
tagExpression
tagExpression,
type
);
}

Expand All @@ -76,6 +85,7 @@ public String toString() {
", name=" + name +
", sourceReference=" + sourceReference +
", tagExpression=" + tagExpression +
", type=" + type +
'}';
}
}
38 changes: 38 additions & 0 deletions java/src/generated/java/io/cucumber/messages/types/HookType.java
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 HookType {

BEFORE("BEFORE"),

AFTER("AFTER"),

BEFORE_STEP("BEFORE_STEP"),

AFTER_STEP("AFTER_STEP");

private final String value;

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

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

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

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

tagExpression?: string

type?: HookType
}

export class Location {
Expand Down Expand Up @@ -675,6 +677,13 @@ export enum AttachmentContentEncoding {
BASE64 = 'BASE64',
}

export enum HookType {
BEFORE = 'BEFORE',
AFTER = 'AFTER',
BEFORE_STEP = 'BEFORE_STEP',
AFTER_STEP = 'AFTER_STEP',
}

export enum PickleStepType {
UNKNOWN = 'Unknown',
CONTEXT = 'Context',
Expand Down
9 changes: 9 additions & 0 deletions jsonschema/Hook.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
},
"tagExpression": {
"type": "string"
},
"type": {
"type": "string",
"enum": [
"BEFORE",
"AFTER",
"BEFORE_STEP",
"AFTER_STEP"
]
}
},
"type": "object"
Expand Down
11 changes: 11 additions & 0 deletions messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ will only have one of its fields set, which indicates the payload of the message
| `name` | string | no | |
| `sourceReference` | [SourceReference](#sourcereference) | yes | |
| `tagExpression` | string | no | |
| `type` | [HookType](#hooktype) | no | |

## Location

Expand Down Expand Up @@ -494,6 +495,16 @@ One of the following:
* `"BASE64"`


## HookType

One of the following:

* `"BEFORE"`
* `"AFTER"`
* `"BEFORE_STEP"`
* `"AFTER_STEP"`


## PickleStepType

One of the following:
Expand Down
34 changes: 34 additions & 0 deletions perl/lib/Cucumber/Messages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,7 @@ my %types = (
name => 'string',
source_reference => 'Cucumber::Messages::SourceReference',
tag_expression => 'string',
type => '',
);

# This is a work-around for the fact that Moo doesn't have introspection
Expand Down Expand Up @@ -2080,6 +2081,39 @@ has tag_expression =>
);


=head4 type



Available constants for valid values of this field:

=over

=item * TYPE_BEFORE

=item * TYPE_AFTER

=item * TYPE_BEFORE_STEP

=item * TYPE_AFTER_STEP

=back

=cut


use constant {
TYPE_BEFORE => 'BEFORE',
TYPE_AFTER => 'AFTER',
TYPE_BEFORE_STEP => 'BEFORE_STEP',
TYPE_AFTER_STEP => 'AFTER_STEP',
};

has type =>
(is => 'ro',
);


}

package Cucumber::Messages::Location {
Expand Down
13 changes: 13 additions & 0 deletions php/src-generated/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(
public readonly ?string $name = null,
public readonly SourceReference $sourceReference = new SourceReference(),
public readonly ?string $tagExpression = null,
public readonly ?Hook\Type $type = null,
) {
}

Expand All @@ -43,12 +44,14 @@ public static function fromArray(array $arr): self
self::ensureName($arr);
self::ensureSourceReference($arr);
self::ensureTagExpression($arr);
self::ensureType($arr);

return new self(
(string) $arr['id'],
isset($arr['name']) ? (string) $arr['name'] : null,
SourceReference::fromArray($arr['sourceReference']),
isset($arr['tagExpression']) ? (string) $arr['tagExpression'] : null,
isset($arr['type']) ? Hook\Type::from((string) $arr['type']) : null,
);
}

Expand Down Expand Up @@ -97,4 +100,14 @@ private static function ensureTagExpression(array $arr): void
throw new SchemaViolationException('Property \'tagExpression\' was array');
}
}

/**
* @psalm-assert array{type?: string|int|bool} $arr
*/
private static function ensureType(array $arr): void
{
if (array_key_exists('type', $arr) && is_array($arr['type'])) {
throw new SchemaViolationException('Property \'type\' was array');
}
}
}
17 changes: 17 additions & 0 deletions php/src-generated/Hook/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/**
* This code was auto-generated by {this script}[https://github.com/cucumber/messages/blob/main/jsonschema/scripts/codegen.rb]
*/

namespace Cucumber\Messages\Hook;

enum Type: string
{
case BEFORE = 'BEFORE';
case AFTER = 'AFTER';
case BEFORE_STEP = 'BEFORE_STEP';
case AFTER_STEP = 'AFTER_STEP';
}
Loading