-
-
Notifications
You must be signed in to change notification settings - Fork 689
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
[messages - elixir] Convert proto-based messages to json schema based messages #1952
Changes from all commits
91f826a
4173fdc
bf28218
080b499
1c57e00
6864a7c
bf9e23f
a1ac0e0
fd21557
3e922b1
6007042
c305c72
176bd7e
a703c12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,19 @@ defmodule CucumberGherkin.AstBuilder do | |
@moduledoc false | ||
alias CucumberGherkin.{ParserContext, AstNode, Token, AstBuilderError, ParserException} | ||
alias CucumberMessages.GherkinDocument.Comment, as: CommentMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Tag, as: MessageTag | ||
alias CucumberMessages.GherkinDocument.Feature.Scenario, as: MessageScenario | ||
alias CucumberMessages.GherkinDocument.Feature.Step, as: StepMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Step.DataTable, as: DataTableMessage | ||
alias CucumberMessages.GherkinDocument.Feature.TableRow, as: TableRowMessage | ||
alias CucumberMessages.GherkinDocument.Feature.TableRow.TableCell, as: TableCellMessage | ||
alias CucumberMessages.GherkinDocument.Tag, as: MessageTag | ||
alias CucumberMessages.GherkinDocument.Scenario, as: MessageScenario | ||
alias CucumberMessages.GherkinDocument.Step, as: StepMessage | ||
alias CucumberMessages.GherkinDocument.DataTable, as: DataTableMessage | ||
alias CucumberMessages.GherkinDocument.TableRow, as: TableRowMessage | ||
alias CucumberMessages.GherkinDocument.TableCell, as: TableCellMessage | ||
alias CucumberMessages.GherkinDocument.Feature, as: FeatureMessage | ||
alias CucumberMessages.GherkinDocument.Feature.FeatureChild, as: FeatureChildMessage | ||
alias CucumberMessages.GherkinDocument.FeatureChild, as: FeatureChildMessage | ||
alias CucumberMessages.GherkinDocument, as: GherkinDocumentMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Step.DocString, as: DocStringMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Background, as: BackgroundMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Scenario.Examples, as: ExamplesMessage | ||
alias CucumberMessages.GherkinDocument.Feature.FeatureChild.Rule, as: RuleMessage | ||
alias CucumberMessages.GherkinDocument.DocString, as: DocStringMessage | ||
alias CucumberMessages.GherkinDocument.Background, as: BackgroundMessage | ||
alias CucumberMessages.GherkinDocument.Examples, as: ExamplesMessage | ||
alias CucumberMessages.GherkinDocument.Rule, as: RuleMessage | ||
|
||
@me __MODULE__ | ||
|
||
|
@@ -58,7 +58,15 @@ defmodule CucumberGherkin.AstBuilder do | |
Comment -> | ||
loc = Token.get_location(token) | ||
comment_message = %CommentMessage{location: loc, text: token.line.content} | ||
# TODO: Normally your struct should default to an empty list instead of nil. | ||
# Due to the limited converter in the messages library, we make a case clause and "catch" this unexpected `nil` value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an option to make the converter smarter? It's nice not to have to maintain this workaround "forever". |
||
# updated_comments = | ||
# case builder.gherkin_doc.comments do | ||
# nil -> [comment_message] | ||
# list -> list ++ [comment_message] | ||
# end | ||
updated_comments = builder.gherkin_doc.comments ++ [comment_message] | ||
|
||
updated_gherkin_doc = %{builder.gherkin_doc | comments: updated_comments} | ||
updated_builder = %{builder | gherkin_doc: updated_gherkin_doc} | ||
%{context | ast_builder: updated_builder} | ||
|
@@ -281,9 +289,12 @@ defmodule CucumberGherkin.AstBuilder do | |
|> add_scen_def_children_to(scenarios) | ||
|> tuplize(updated_context) | ||
else | ||
{:header?, _} -> nil | ||
{:rule_line?, _} -> nil | ||
|> tuplize(context) | ||
{:header?, _} -> | ||
nil | ||
|
||
{:rule_line?, _} -> | ||
nil | ||
|> tuplize(context) | ||
end | ||
end | ||
|
||
|
@@ -393,31 +404,51 @@ defmodule CucumberGherkin.AstBuilder do | |
defp add_mediatype_to(%DocStringMessage{} = m, d), do: %{m | media_type: d} | ||
|
||
defp add_datatable_to(%StepMessage{} = m, nil), do: m | ||
defp add_datatable_to(%StepMessage{} = m, d), do: %{m | argument: {:data_table, d}} | ||
defp add_datatable_to(%StepMessage{} = m, d), do: %{m | data_table: d} | ||
|
||
defp add_docstring_to(%StepMessage{} = m, nil), do: m | ||
defp add_docstring_to(%StepMessage{} = m, d), do: %{m | argument: {:doc_string, d}} | ||
defp add_docstring_to(%StepMessage{} = m, d), do: %{m | doc_string: d} | ||
|
||
defp add_background_to(m, nil), do: m | ||
|
||
defp add_background_to(%{__struct__: t} = m, d) when t in [FeatureMessage, RuleMessage] do | ||
child = %FeatureChildMessage{value: {:background, d}} | ||
child = %FeatureChildMessage{background: d} | ||
# TODO: Normally your struct should default to an empty list instead of nil. | ||
# Due to the limited converter in the messages library, we make a case clause and "catch" this unexpected `nil` value. | ||
# case m.children do | ||
# nil -> %{m | children: [child]} | ||
# list -> %{m | children: list ++ [child]} | ||
# end | ||
|
||
%{m | children: m.children ++ [child]} | ||
end | ||
|
||
defp add_scen_def_children_to(%{__struct__: t} = m, scenario_definition_items) | ||
when t in [FeatureMessage, RuleMessage] do | ||
scenario_definition_items | ||
|> Enum.reduce(m, fn scenario_def, feature_message_acc -> | ||
child = %FeatureChildMessage{value: {:scenario, scenario_def}} | ||
child = %FeatureChildMessage{scenario: scenario_def} | ||
# TODO: Normally your struct should default to an empty list instead of nil. | ||
# Due to the limited converter in the messages library, we make a case clause and "catch" this unexpected `nil` value. | ||
# case feature_message_acc.children do | ||
# nil -> %{feature_message_acc | children: [child]} | ||
# list -> %{feature_message_acc | children: list ++ [child]} | ||
# end | ||
%{feature_message_acc | children: feature_message_acc.children ++ [child]} | ||
end) | ||
end | ||
|
||
defp add_rule_children_to(%FeatureMessage{} = m, rule_items) do | ||
rule_items | ||
|> Enum.reduce(m, fn rule, feature_message_acc -> | ||
child = %FeatureChildMessage{value: {:rule, rule}} | ||
child = %FeatureChildMessage{rule: rule} | ||
|
||
# TODO: Normally your struct should default to an empty list instead of nil. | ||
# Due to the limited converter in the messages library, we make a case clause and "catch" this unexpected `nil` value. | ||
# case feature_message_acc.children do | ||
# nil -> %{feature_message_acc | children: [child]} | ||
# list -> %{feature_message_acc | children: list ++ [child]} | ||
# end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually not seeing the case statement; I'm not all that great at elixir, but the code you describe really isn't there? |
||
%{feature_message_acc | children: feature_message_acc.children ++ [child]} | ||
end) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,23 +3,26 @@ defmodule CucumberGherkin.PickleCompiler do | |
defstruct id_gen: nil, pickles: [], language: nil, uri: nil | ||
|
||
alias CucumberMessages.GherkinDocument.Feature, as: FeatureMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Scenario, as: ScenarioMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Step, as: StepMessage | ||
alias CucumberMessages.GherkinDocument.Feature.TableRow, as: TableRowMessage | ||
alias CucumberMessages.GherkinDocument.Scenario, as: ScenarioMessage | ||
alias CucumberMessages.GherkinDocument.Step, as: StepMessage | ||
alias CucumberMessages.GherkinDocument.TableRow, as: TableRowMessage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are inconsistent with |
||
alias CucumberMessages.Pickle, as: PickleMessage | ||
alias CucumberMessages.Pickle.PickleStep, as: PickleStepMessage | ||
alias CucumberMessages.Pickle.PickleTag, as: PickleTagMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Tag, as: TagMessage | ||
alias CucumberMessages.GherkinDocument.Feature.FeatureChild, as: FeatureChildMessage | ||
alias CucumberMessages.GherkinDocument.Feature.FeatureChild.Rule, as: RuleMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Scenario.Examples, as: ExampleMessage | ||
alias CucumberMessages.PickleStepArgument.PickleTable, as: PickleTableMessage | ||
alias CucumberMessages.GherkinDocument.Tag, as: TagMessage | ||
alias CucumberMessages.GherkinDocument.FeatureChild, as: FeatureChildMessage | ||
alias CucumberMessages.GherkinDocument.Rule, as: RuleMessage | ||
alias CucumberMessages.GherkinDocument.Examples, as: ExampleMessage | ||
alias CucumberMessages.Pickle.PickleTable, as: PickleTableMessage | ||
|
||
alias CucumberMessages.PickleStepArgument.PickleTable.PickleTableRow.PickleTableCell, | ||
alias CucumberMessages.Pickle.PickleTableCell, | ||
as: PickleTableCellMessage | ||
|
||
alias CucumberMessages.PickleStepArgument.PickleTable.PickleTableRow, as: PickleTableRowMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Step.DataTable, as: DataTableMessage | ||
alias CucumberMessages.Pickle.PickleTableRow, as: PickleTableRowMessage | ||
alias CucumberMessages.GherkinDocument.DataTable, as: DataTableMessage | ||
|
||
alias CucumberMessages.Pickle.PickleDocString, as: PickleDocStringMessage | ||
alias CucumberMessages.GherkinDocument.DocString, as: DocStringMessage | ||
|
||
@me __MODULE__ | ||
|
||
|
@@ -44,16 +47,27 @@ defmodule CucumberGherkin.PickleCompiler do | |
} | ||
|
||
Enum.reduce(f.children, meta_info, fn child, m_acc -> | ||
case child.value do | ||
{:background, bg} -> | ||
%{m_acc | feature_backgr_steps: bg.steps} | ||
cond do | ||
child.background != nil -> | ||
%{m_acc | feature_backgr_steps: child.background.steps} | ||
|
||
{:rule, rule} -> | ||
compile_rule(m_acc, rule) | ||
child.rule != nil -> | ||
compile_rule(m_acc, child.rule) | ||
|
||
{:scenario, s} -> | ||
compile_scenario(m_acc, s, :feature_backgr_steps) | ||
child.scenario != nil -> | ||
compile_scenario(m_acc, child.scenario, :feature_backgr_steps) | ||
end | ||
|
||
# case child.value do | ||
# {:background, bg} -> | ||
# %{m_acc | feature_backgr_steps: bg.steps} | ||
|
||
# {:rule, rule} -> | ||
# compile_rule(m_acc, rule) | ||
|
||
# {:scenario, s} -> | ||
# compile_scenario(m_acc, s, :feature_backgr_steps) | ||
# end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the value of this comment block? It looks like it's preserving the old code, but once we're moved over, we have the old code in Git for historic reference. No need to keep a copy? |
||
end) | ||
end | ||
|
||
|
@@ -62,10 +76,10 @@ defmodule CucumberGherkin.PickleCompiler do | |
rule_tags = meta_info.feature_tags ++ r.tags | ||
|
||
Enum.reduce(r.children, resetted_meta_info, fn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was already there, but |
||
%FeatureChildMessage{value: {:background, bg}}, m_acc -> | ||
%FeatureChildMessage{background: bg}, m_acc when not is_nil(bg) -> | ||
%{m_acc | rule_backgr_steps: m_acc.rule_backgr_steps ++ bg.steps} | ||
|
||
%FeatureChildMessage{value: {:scenario, s}}, m_acc -> | ||
%FeatureChildMessage{scenario: s}, m_acc when not is_nil(s) -> | ||
%{m_acc | feature_tags: rule_tags} |> compile_scenario(s, :rule_backgr_steps) | ||
end) | ||
end | ||
|
@@ -213,14 +227,12 @@ defmodule CucumberGherkin.PickleCompiler do | |
%PickleTableMessage{rows: table_row_messages} | ||
end | ||
|
||
alias CucumberMessages.PickleStepArgument.PickleDocString, as: PickleDocStringMessage | ||
alias CucumberMessages.GherkinDocument.Feature.Step.DocString, as: DocStringMessage | ||
|
||
defp pickle_doc_string_creator(%DocStringMessage{} = d, variable_cells, value_cells) do | ||
content = interpolate(d.content, variable_cells, value_cells) | ||
|
||
media_type = | ||
case d.media_type do | ||
nil -> nil | ||
"" -> "" | ||
media_type -> interpolate(media_type, variable_cells, value_cells) | ||
end | ||
|
@@ -237,34 +249,49 @@ defmodule CucumberGherkin.PickleCompiler do | |
defp add_ast_node_id(%PickleStepMessage{ast_node_ids: ids} = m, %TableRowMessage{} = row), | ||
do: %{m | ast_node_ids: ids ++ [row.id]} | ||
|
||
defp add_datatable(%PickleStepMessage{} = m, %StepMessage{argument: nil}, _, _), do: m | ||
defp add_datatable( | ||
%PickleStepMessage{} = m, | ||
%StepMessage{doc_string: nil, data_table: nil}, | ||
_, | ||
_ | ||
), | ||
do: m | ||
|
||
defp add_datatable(%PickleStepMessage{} = m, %StepMessage{argument: {:doc_string, _}}, _, _), | ||
defp add_datatable(%PickleStepMessage{} = m, %StepMessage{doc_string: ds}, _, _) when ds != nil, | ||
do: m | ||
|
||
defp add_datatable( | ||
%PickleStepMessage{} = m, | ||
%StepMessage{argument: {:data_table, d}}, | ||
%StepMessage{data_table: d}, | ||
variable_cells, | ||
value_cells | ||
) do | ||
) | ||
when d != nil do | ||
result = pickle_data_table_creator(d, variable_cells, value_cells) | ||
%{m | argument: result} | ||
%{m | argument: %{data_table: result}} | ||
end | ||
|
||
defp add_doc_string(%PickleStepMessage{} = m, %StepMessage{argument: nil}, _, _), do: m | ||
defp add_doc_string( | ||
%PickleStepMessage{} = m, | ||
%StepMessage{doc_string: nil, data_table: nil}, | ||
_, | ||
_ | ||
), | ||
do: m | ||
|
||
defp add_doc_string(%PickleStepMessage{} = m, %StepMessage{argument: {:data_table, _}}, _, _), | ||
do: m | ||
defp add_doc_string(%PickleStepMessage{} = m, %StepMessage{data_table: dt}, _, _) | ||
when dt != nil, | ||
do: m | ||
|
||
defp add_doc_string( | ||
%PickleStepMessage{} = m, | ||
%StepMessage{argument: {:doc_string, d}}, | ||
%StepMessage{doc_string: d}, | ||
variable_cells, | ||
value_cells | ||
) do | ||
) | ||
when d != nil do | ||
result = pickle_doc_string_creator(d, variable_cells, value_cells) | ||
%{m | argument: result} | ||
%{m | argument: %{doc_string: result}} | ||
end | ||
|
||
defp get_id_and_update_compiler_acc(%@me{id_gen: gen} = compiler_acc) do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WannesFransen1994 is this document manually maintained? I see an inconsistency here:
StepMessage
where all the others are calledMessage*
?