Current section

Files

Jump to
dream_test src dream_test@gherkin@types.erl
Raw

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"
" These are the data structures produced by the Gherkin parser and consumed\n"
" by the feature/discovery APIs. Most users won’t construct them directly,\n"
" but they’re useful when you’re integrating your own parser or tooling.\n"
"\n"
" ## Example\n"
"\n"
" Use this when building BDD suites (e.g. in a snippet `tests()` function).\n"
"\n"
" ```gleam\n"
" keyword_to_string(Given)\n"
" |> should\n"
" |> be_equal(\"Given\")\n"
" |> or_fail_with(\"expected Given\")\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", 261).
?DOC(
" Convert a StepKeyword to its string representation.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" keyword_to_string(Given)\n"
" |> should\n"
" |> be_equal(\"Given\")\n"
" |> or_fail_with(\"expected Given\")\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", 284).
?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(\"Then\")\n"
" |> should\n"
" |> be_equal(Some(Then))\n"
" |> or_fail_with(\"expected Some(Then)\")\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", 309).
?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)\n"
" |> should\n"
" |> be_equal(Given)\n"
" |> or_fail_with(\"expected And after Given to resolve to Given\")\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", 333).
?DOC(
" Create an empty examples table.\n"
"\n"
" Useful as a default value or for testing.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" empty_examples()\n"
" |> should\n"
" |> be_equal(ExamplesTable(headers: [], rows: []))\n"
" |> or_fail_with(\"expected empty examples table\")\n"
" ```\n"
).
-spec empty_examples() -> examples_table().
empty_examples() ->
{examples_table, [], []}.
-file("src/dream_test/gherkin/types.gleam", 350).
?DOC(
" Create an empty background.\n"
"\n"
" Useful as a default value or for testing.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" empty_background()\n"
" |> should\n"
" |> be_equal(Background(steps: []))\n"
" |> or_fail_with(\"expected empty background\")\n"
" ```\n"
).
-spec empty_background() -> background().
empty_background() ->
{background, []}.