Current section
Files
Jump to
Current section
Files
src/dream_test@gherkin@types.erl
-module(dream_test@gherkin@types).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/dream_test/gherkin/types.gleam").
-export([keyword_to_string/1, keyword_from_string/1, resolve_keyword/2, empty_examples/0, empty_background/0]).
-export_type([step_keyword/0, step_argument/0, step/0, background/0, examples_table/0, scenario/0, feature/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Gherkin types for dream_test.\n"
"\n"
" This module defines the data structures representing parsed Gherkin\n"
" `.feature` files. These types are used by the parser and converted\n"
" to dream_test's `TestCase` and `TestSuite` types for execution.\n"
"\n"
" ## Type Overview\n"
"\n"
" | Type | Purpose |\n"
" |-------------------|--------------------------------------------------|\n"
" | `Feature` | A parsed `.feature` file |\n"
" | `Scenario` | A single scenario or scenario outline |\n"
" | `Step` | A Given/When/Then step with text |\n"
" | `StepKeyword` | The keyword type (Given, When, Then, And, But) |\n"
" | `StepArgument` | Optional DocString or DataTable |\n"
" | `Background` | Steps to run before each scenario |\n"
" | `ExamplesTable` | Data table for Scenario Outline expansion |\n"
"\n"
" ## Gherkin Syntax Reference\n"
"\n"
" ```gherkin\n"
" @tag1 @tag2\n"
" Feature: Shopping Cart\n"
" As a customer\n"
" I want to manage my cart\n"
"\n"
" Background:\n"
" Given I am logged in\n"
"\n"
" Scenario: Adding items\n"
" Given I have an empty cart\n"
" When I add 3 items of \"Widget\"\n"
" Then my cart should have 3 items\n"
"\n"
" Scenario Outline: Multiple products\n"
" Given I have an empty cart\n"
" When I add <quantity> items of \"<product>\"\n"
" Then my cart should have <quantity> items\n"
"\n"
" Examples:\n"
" | quantity | product |\n"
" | 1 | Widget |\n"
" | 5 | Gadget |\n"
" ```\n"
).
-type step_keyword() :: given | 'when' | then | 'and' | but.
-type step_argument() :: {doc_string, binary(), gleam@option:option(binary())} |
{data_table, list(list(binary()))}.
-type step() :: {step,
step_keyword(),
binary(),
gleam@option:option(step_argument())}.
-type background() :: {background, list(step())}.
-type examples_table() :: {examples_table, list(binary()), list(list(binary()))}.
-type scenario() :: {scenario, binary(), list(binary()), list(step())} |
{scenario_outline, binary(), list(binary()), list(step()), examples_table()}.
-type feature() :: {feature,
binary(),
gleam@option:option(binary()),
list(binary()),
gleam@option:option(background()),
list(scenario())}.
-file("src/dream_test/gherkin/types.gleam", 315).
?DOC(
" Convert a StepKeyword to its string representation.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" keyword_to_string(Given) // -> \"Given\"\n"
" keyword_to_string(And) // -> \"And\"\n"
" ```\n"
).
-spec keyword_to_string(step_keyword()) -> binary().
keyword_to_string(Keyword) ->
case Keyword of
given ->
<<"Given"/utf8>>;
'when' ->
<<"When"/utf8>>;
then ->
<<"Then"/utf8>>;
'and' ->
<<"And"/utf8>>;
but ->
<<"But"/utf8>>
end.
-file("src/dream_test/gherkin/types.gleam", 336).
?DOC(
" Parse a string to a StepKeyword.\n"
"\n"
" Returns the keyword if recognized, or None for unknown strings.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" keyword_from_string(\"Given\") // -> Some(Given)\n"
" keyword_from_string(\"Hello\") // -> None\n"
" ```\n"
).
-spec keyword_from_string(binary()) -> gleam@option:option(step_keyword()).
keyword_from_string(Text) ->
case Text of
<<"Given"/utf8>> ->
{some, given};
<<"When"/utf8>> ->
{some, 'when'};
<<"Then"/utf8>> ->
{some, then};
<<"And"/utf8>> ->
{some, 'and'};
<<"But"/utf8>> ->
{some, but};
_ ->
none
end.
-file("src/dream_test/gherkin/types.gleam", 360).
?DOC(
" Resolve And/But to the effective keyword based on previous step.\n"
"\n"
" In Gherkin, `And` and `But` inherit meaning from the previous step.\n"
" This function resolves them to their effective keyword type.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" resolve_keyword(And, Given) // -> Given\n"
" resolve_keyword(But, Then) // -> Then\n"
" resolve_keyword(When, Given) // -> When (non-And/But unchanged)\n"
" ```\n"
).
-spec resolve_keyword(step_keyword(), step_keyword()) -> step_keyword().
resolve_keyword(Keyword, Previous) ->
case Keyword of
'and' ->
Previous;
but ->
Previous;
Other ->
Other
end.
-file("src/dream_test/gherkin/types.gleam", 375).
?DOC(
" Create an empty examples table.\n"
"\n"
" Useful as a default value or for testing.\n"
).
-spec empty_examples() -> examples_table().
empty_examples() ->
{examples_table, [], []}.
-file("src/dream_test/gherkin/types.gleam", 383).
?DOC(
" Create an empty background.\n"
"\n"
" Useful as a default value or for testing.\n"
).
-spec empty_background() -> background().
empty_background() ->
{background, []}.