Skip to content

Add location to pickle #308

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 2 additions & 0 deletions cpp/include/messages/cucumber/messages/pickle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cucumber/messages/pickle_step.hpp>
#include <cucumber/messages/pickle_tag.hpp>
#include <cucumber/messages/location.hpp>

namespace cucumber::messages {

Expand Down Expand Up @@ -41,6 +42,7 @@ struct pickle
std::vector<cucumber::messages::pickle_step> steps;
std::vector<cucumber::messages::pickle_tag> tags;
std::vector<std::string> ast_node_ids;
std::optional<cucumber::messages::location> location;

std::string to_string() const;

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/pickle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pickle::to_string() const
cucumber::messages::to_string(oss, ", steps=", steps);
cucumber::messages::to_string(oss, ", tags=", tags);
cucumber::messages::to_string(oss, ", ast_node_ids=", ast_node_ids);
cucumber::messages::to_string(oss, ", location=", location);

return oss.str();
}
Expand All @@ -31,6 +32,7 @@ pickle::to_json(json& j) const
cucumber::messages::to_json(j, camelize("steps"), steps);
cucumber::messages::to_json(j, camelize("tags"), tags);
cucumber::messages::to_json(j, camelize("ast_node_ids"), ast_node_ids);
cucumber::messages::to_json(j, camelize("location"), location);
}

std::string
Expand Down
14 changes: 12 additions & 2 deletions dotnet/Cucumber.Messages/generated/Pickle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public sealed class Pickle
* id originating from the `Scenario` AST node, and the second from the `TableRow` AST node.
*/
public List<string> AstNodeIds { get; private set; }
/**
* The location of this pickle in source file. A pickle constructed from `Examples` will point to the example row.
*/
public Location Location { get; private set; }


public Pickle(
Expand All @@ -69,7 +73,8 @@ public Pickle(
string language,
List<PickleStep> steps,
List<PickleTag> tags,
List<string> astNodeIds
List<string> astNodeIds,
Location location
)
{
RequireNonNull<string>(id, "Id", "Pickle.Id cannot be null");
Expand All @@ -86,6 +91,7 @@ List<string> astNodeIds
this.Tags = new List<PickleTag>(tags);
RequireNonNull<List<string>>(astNodeIds, "AstNodeIds", "Pickle.AstNodeIds cannot be null");
this.AstNodeIds = new List<string>(astNodeIds);
this.Location = location;
}

public override bool Equals(Object o)
Expand All @@ -100,7 +106,8 @@ public override bool Equals(Object o)
Language.Equals(that.Language) &&
Steps.Equals(that.Steps) &&
Tags.Equals(that.Tags) &&
AstNodeIds.Equals(that.AstNodeIds);
AstNodeIds.Equals(that.AstNodeIds) &&
Object.Equals(Location, that.Location);
}

public override int GetHashCode()
Expand All @@ -120,6 +127,8 @@ public override int GetHashCode()
hash = hash * 31 + Tags.GetHashCode();
if (AstNodeIds != null)
hash = hash * 31 + AstNodeIds.GetHashCode();
if (Location != null)
hash = hash * 31 + Location.GetHashCode();
return hash;
}

Expand All @@ -133,6 +142,7 @@ public override string ToString()
", steps=" + Steps +
", tags=" + Tags +
", astNodeIds=" + AstNodeIds +
", location=" + Location +
'}';
}

Expand Down
1 change: 1 addition & 0 deletions go/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ type Pickle struct {
Steps []*PickleStep `json:"steps"`
Tags []*PickleTag `json:"tags"`
AstNodeIds []string `json:"astNodeIds"`
Location *Location `json:"location,omitempty"`
}

type PickleDocString struct {
Expand Down
19 changes: 16 additions & 3 deletions java/src/generated/java/io/cucumber/messages/types/Pickle.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class Pickle {
private final java.util.List<PickleStep> steps;
private final java.util.List<PickleTag> tags;
private final java.util.List<String> astNodeIds;
private final Location location;

public Pickle(
String id,
Expand All @@ -42,7 +43,8 @@ public Pickle(
String language,
java.util.List<PickleStep> steps,
java.util.List<PickleTag> tags,
java.util.List<String> astNodeIds
java.util.List<String> astNodeIds,
Location location
) {
this.id = requireNonNull(id, "Pickle.id cannot be null");
this.uri = requireNonNull(uri, "Pickle.uri cannot be null");
Expand All @@ -51,6 +53,7 @@ public Pickle(
this.steps = unmodifiableList(new ArrayList<>(requireNonNull(steps, "Pickle.steps cannot be null")));
this.tags = unmodifiableList(new ArrayList<>(requireNonNull(tags, "Pickle.tags cannot be null")));
this.astNodeIds = unmodifiableList(new ArrayList<>(requireNonNull(astNodeIds, "Pickle.astNodeIds cannot be null")));
this.location = location;
}

/**
Expand Down Expand Up @@ -105,6 +108,13 @@ public java.util.List<String> getAstNodeIds() {
return astNodeIds;
}

/**
* The location of this pickle in source file. A pickle constructed from `Examples` will point to the example row.
*/
public Optional<Location> getLocation() {
return Optional.ofNullable(location);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -117,7 +127,8 @@ public boolean equals(Object o) {
language.equals(that.language) &&
steps.equals(that.steps) &&
tags.equals(that.tags) &&
astNodeIds.equals(that.astNodeIds);
astNodeIds.equals(that.astNodeIds) &&
Objects.equals(location, that.location);
}

@Override
Expand All @@ -129,7 +140,8 @@ public int hashCode() {
language,
steps,
tags,
astNodeIds
astNodeIds,
location
);
}

Expand All @@ -143,6 +155,7 @@ public String toString() {
", steps=" + steps +
", tags=" + tags +
", astNodeIds=" + astNodeIds +
", location=" + location +
'}';
}
}
3 changes: 3 additions & 0 deletions javascript/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ export class Pickle {
tags: readonly PickleTag[] = []

astNodeIds: readonly string[] = []

@Type(() => Location)
location?: Location
}

export class PickleDocString {
Expand Down
1 change: 1 addition & 0 deletions jsonschema/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ will only have one of its fields set, which indicates the payload of the message
| `steps` | [PickleStep](#picklestep)[] | yes | |
| `tags` | [PickleTag](#pickletag)[] | yes | |
| `astNodeIds` | string[] | yes | |
| `location` | [Location](#location) | no | |

## PickleDocString

Expand Down
4 changes: 4 additions & 0 deletions jsonschema/src/Pickle.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
},
"type": "array",
"minItems": 1
},
"location": {
"description": "The location of this pickle in source file. A pickle constructed from `Examples` will point to the example row.",
"$ref": "./Location.json"
}
},
"type": "object"
Expand Down
11 changes: 11 additions & 0 deletions perl/lib/Cucumber/Messages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2737,6 +2737,7 @@ my %types = (
steps => '[]Cucumber::Messages::PickleStep',
tags => '[]Cucumber::Messages::PickleTag',
ast_node_ids => '[]string',
location => 'Cucumber::Messages::Location',
);

# This is a work-around for the fact that Moo doesn't have introspection
Expand Down Expand Up @@ -2837,6 +2838,16 @@ has ast_node_ids =>
);


=head4 location

The location of this pickle in source file. A pickle constructed from `Examples` will point to the example row.
=cut

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


}

package Cucumber::Messages::PickleDocString {
Expand Down
17 changes: 17 additions & 0 deletions php/src-generated/Pickle.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function __construct(
* id originating from the `Scenario` AST node, and the second from the `TableRow` AST node.
*/
public readonly array $astNodeIds = [],

/**
* The location of this pickle in source file. A pickle constructed from `Examples` will point to the example row.
*/
public readonly ?Location $location = null,
) {
}

Expand All @@ -94,6 +99,7 @@ public static function fromArray(array $arr): self
self::ensureSteps($arr);
self::ensureTags($arr);
self::ensureAstNodeIds($arr);
self::ensureLocation($arr);

return new self(
(string) $arr['id'],
Expand All @@ -103,6 +109,7 @@ public static function fromArray(array $arr): self
array_values(array_map(fn (array $member) => PickleStep::fromArray($member), $arr['steps'])),
array_values(array_map(fn (array $member) => PickleTag::fromArray($member), $arr['tags'])),
array_values(array_map(fn (mixed $member) => (string) $member, $arr['astNodeIds'])),
isset($arr['location']) ? Location::fromArray($arr['location']) : null,
);
}

Expand Down Expand Up @@ -196,4 +203,14 @@ private static function ensureAstNodeIds(array $arr): void
throw new SchemaViolationException('Property \'astNodeIds\' was not array');
}
}

/**
* @psalm-assert array{location?: array} $arr
*/
private static function ensureLocation(array $arr): void
{
if (array_key_exists('location', $arr) && !is_array($arr['location'])) {
throw new SchemaViolationException('Property \'location\' was not array');
}
}
}
1 change: 1 addition & 0 deletions python/src/cucumber_messages/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class Pickle:
"""

uri: str # The uri of the source file
location: Optional[Location] = None # The location of this pickle in source file. A pickle constructed from `Examples` will point to the example row.


@dataclass
Expand Down
12 changes: 10 additions & 2 deletions ruby/lib/cucumber/messages/pickle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ class Pickle < Message
##
attr_reader :ast_node_ids

##
# The location of this pickle in source file. A pickle constructed from `Examples` will point to the example row.
##
attr_reader :location

def initialize(
id: '',
uri: '',
name: '',
language: '',
steps: [],
tags: [],
ast_node_ids: []
ast_node_ids: [],
location: nil
)
@id = id
@uri = uri
Expand All @@ -79,6 +85,7 @@ def initialize(
@steps = steps
@tags = tags
@ast_node_ids = ast_node_ids
@location = location
super()
end

Expand All @@ -99,7 +106,8 @@ def self.from_h(hash)
language: hash[:language],
steps: hash[:steps]&.map { |item| PickleStep.from_h(item) },
tags: hash[:tags]&.map { |item| PickleTag.from_h(item) },
ast_node_ids: hash[:astNodeIds]
ast_node_ids: hash[:astNodeIds],
location: Location.from_h(hash[:location])
)
end
end
Expand Down
Loading