summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-04-18 14:06:23 +0300
committerLars Wirzenius <liw@liw.fi>2020-04-19 15:28:48 +0300
commit30447917d785345dd99ee8cfe601b94ff413260c (patch)
tree998c237c45e10b3c752f94c6e26b1b44cc5e1231
parent9f1bd185832c6e8acfafa6c66545a1921891da2e (diff)
downloadsubplot-30447917d785345dd99ee8cfe601b94ff413260c.tar.gz
Add: acceptance criteria for simple patterns
This adds scenarios for regex patterns capture and simple pattern capture from scenario steps, and additionally makes use of simple patterns everywhere possible in the examples.
-rw-r--r--echo.yaml3
-rw-r--r--muck.yaml15
-rw-r--r--subplot.md78
-rw-r--r--subplot.py3
-rw-r--r--subplot.yaml34
5 files changed, 118 insertions, 15 deletions
diff --git a/echo.yaml b/echo.yaml
index f86159d..7be6e96 100644
--- a/echo.yaml
+++ b/echo.yaml
@@ -3,15 +3,18 @@
- when: user runs echo with arguments (?P<args>.+)
function: run_echo_with_args
+ regex: true
- then: exit code is (?P<exit_code>\d+)
function: exit_code_is
+ regex: true
- then: standard output contains a newline
function: stdout_is_a_newline
- then: standard output contains "(?P<text>.*)"
function: stdout_is_text
+ regex: true
- then: standard error is empty
function: stderr_is_empty
diff --git a/muck.yaml b/muck.yaml
index b7bba50..21fe303 100644
--- a/muck.yaml
+++ b/muck.yaml
@@ -1,38 +1,47 @@
- given: "a fresh Muck server"
function: fixme
-- given: "I am (?P<name>\\S+)"
+- given: "I am {name}"
function: fixme
-- given: "I am (?P<name>\\S+), with super capability"
+- given: "I am {name}, with super capability"
function: fixme
- when: "I do POST /res with (?P<json>\\{.*\\})"
function: fixme
+ regex: true
- when: "I do PUT /res with Muck-Id: \\{(?P<id>\\S+)\\}, Muck-Revision: \\{(?P<rev>\\S+)\\}, and body (?P<json>\\{.*\\})"
function: fixme
+ regex: true
- when: "I do GET /res with Muck-Id: \\{(?P<id>\\S+)\\}"
function: fixme
+ regex: true
- when: "I do DELETE /res with Muck-Id: \\{(?P<id>\\S+)\\}"
function: fixme
+ regex: true
- when: "I restart Muck"
function: fixme
+ regex: true
- then: "response code is (?P<code>\\d+)"
function: fixme
+ regex: true
-- then: "header (?P<header>\\S+) is (?P<name>\\S+)"
+- then: "header {header} is {name}"
function: fixme
- then: "header (?P<header>\\S+) matches \\{(?P<name>\\S+)\\}"
function: fixme
+ regex: true
- then: "body matches (?P<json>\\{.*\\})"
function: fixme
+ regex: true
- then: "revisions \\{(?P<rev1>\\S+)\\} and \\{(?P<rev2>\\S+)\\} are different"
function: fixme
+ regex: true
diff --git a/subplot.md b/subplot.md
index 16059be..bc9d932 100644
--- a/subplot.md
+++ b/subplot.md
@@ -683,6 +683,84 @@ then bar was done
~~~~
+Capturing parts of steps for functions
+-----------------------------------------------------------------------------
+
+A scenario step binding can capture parts of a scenario step, to be
+passed to the function implementing the step as an argument. Captures
+can be done using regular expressions.
+
+### Capture using simple patterns
+
+~~~scenario
+given file simplepattern.md
+and file simplepattern.yaml
+and file capture.py
+when I run sp-codegen --run simplepattern.md -o test.py
+then scenario "Simple pattern" was run
+and step "given I am Tomjon" was run
+and function got Tomjon as an argument
+and program finished successfully
+~~~
+
+~~~~{.file #simplepattern.md .markdown .numberLines}
+---
+title: Simple pattern capture
+bindings: simplepattern.yaml
+functions: capture.py
+...
+
+# Simple pattern
+
+~~~scenario
+given I am Tomjon
+~~~
+~~~~
+
+~~~{.file #simplepattern.yaml .yaml .numberLines}
+- given: I am {name}
+ function: func
+~~~
+
+~~~{.file #capture.py .python .numberLines}
+def func(ctx, name=None):
+ print('function got argument name as', name)
+~~~
+
+### Capture using regular expressions
+
+~~~scenario
+given file regex.md
+and file regex.yaml
+and file capture.py
+when I run sp-codegen --run regex.md -o test.py
+then scenario "Regex" was run
+and step "given I am Tomjon" was run
+and function got Tomjon as an argument
+and program finished successfully
+~~~
+
+~~~~{.file #regex.md .markdown .numberLines}
+---
+title: Regex capture
+bindings: regex.yaml
+functions: capture.py
+...
+
+# Regex
+
+~~~scenario
+given I am Tomjon
+~~~
+~~~~
+
+~~~{.file #regex.yaml .yaml .numberLines}
+- given: I am (?P<name>\S+)
+ function: func
+ regex: true
+~~~
+
+
Avoid changing typesetting output file needlessly
-----------------------------------------------------------------------------
diff --git a/subplot.py b/subplot.py
index 48320b6..6852411 100644
--- a/subplot.py
+++ b/subplot.py
@@ -66,6 +66,9 @@ def file_contains(ctx, filename=None, pattern=None):
content = f.read()
assert_eq(pattern in content, True)
+def function_got_arg(ctx, arg=None):
+ stdout_matches(ctx, '\nfunction got arg {}\n'.format(arg))
+
def scenario_was_run(ctx, name=None):
stdout_matches(ctx, '\nrunning scenario: {}\n'.format(name))
diff --git a/subplot.yaml b/subplot.yaml
index 0bb5e23..55e4c6c 100644
--- a/subplot.yaml
+++ b/subplot.yaml
@@ -1,62 +1,72 @@
-- given: file (?P<filename>\S+)
+- given: file {filename}
function: create_file
- given: file (?P<filename>\S+) has modification time (?P<y>\d+)-(?P<mon>\d+)-(?P<d>\d+) (?P<h>\d+):(?P<min>\d+):(?P<s>\d+)
function: touch_file
+ regex: true
-- when: I remember the metadata for (?P<filename>\S+)
+- when: I remember the metadata for {filename}
function: remember_metadata
-- when: I run sp-docgen (?P<md>\S+) -o (?P<output>\S+)
+- when: I run sp-docgen {md} -o {output}
function: run_docgen
-- when: I run sp-docgen (?P<md>\S+) -o (?P<output>\S+) --date=(?P<date>\S+)
+- when: I run sp-docgen {md} -o {output} --date={date}
function: run_docgen_with_date
-- when: I try to run sp-docgen (?P<md>\S+) -o (?P<output>\S+)
+- when: I try to run sp-docgen {md} -o {output}
function: try_docgen
-- when: I run sp-codegen --run (?P<filename>\S+) -o test.py
+- when: I run sp-codegen --run {filename} -o test.py
function: run_codegen
-- when: I try to run sp-codegen --run (?P<filename>\S+) -o test.py
+- when: I try to run sp-codegen --run {filename} -o test.py
function: try_codegen
-- when: I run sp-meta (?P<filename>\S+)
+- when: I run sp-meta {filename}
function: run_meta
-- when: I run pandoc --filter sp-filter (?P<filename>\S+) -o (?P<output>\S+)
+- when: I run pandoc --filter sp-filter {filename} -o {output}
function: run_pandoc_with_filter
- then: exit code is non-zero
function: exit_code_nonzero
-- then: file (?P<filename>\S+) exists
+- then: file {filename} exists
function: file_exists
-- then: file (?P<filename>\S+) does not exist
+- then: file {filename} does not exist
function: file_does_not_exist
- then: file (?P<filename>\S+) matches /(?P<regex>.+)/
function: file_matches
+ regex: true
- then: file (?P<filename>\S+) contains "(?P<pattern>.+)"
function: file_contains
+ regex: true
-- then: (?P<filename>\S+) has the same metadata as before
+- then: "{filename} has the same metadata as before"
function: has_same_metadata_as_remembered
+- then: function got {arg} as an argument
+ function: function_got_arg
+
- then: output matches /(?P<pattern>.+)/
function: stdout_matches
+ regex: true
- then: scenario "(?P<name>.+)" was run
function: scenario_was_run
+ regex: true
- then: step "(?P<keyword>given|when|then) (?P<name>.+)" was run
function: step_was_run
+ regex: true
- then: program finished successfully
function: exit_code_zero
- then: only files (?P<filenames>.+) exist
function: only_these_files_exist
+ regex: true