Context based definition of an example to make easier to write examples that expect empty lines #250
Labels
enhancement
something nice to have but it is not neither critical nor urgent
far in the future
something that it could be cool but it is too hard to implement
request for comments
a draft idea that needs more brainstorming, comments are welcome!
Describe the feature you'd like
When an example's expected output has an empty line, the user must (1) not write an empty line and use
+norm-ws
or (2) write a dummy character like~
in the empty line and delete it before the comparison with the obtained output with+rm=~
byexample
defines an example's expected output from the first line after the example's code/snippet and until the line where another prompt for the same language begins or until an empty line.So the following works (
byexample -l python,shell
):However the following don't
In order to make it work we can use
+norm-ws
or+rm
The proposed feature is to use the context of the example to hint
byexample
to where the example really ends.First, if another runner is enabled, the prompt of it should mark as the end of the former example:
For example the following does not work because the
$ echo.....
is interpreted as part of the python example's expected output:With the proposed feature, the example above should work as
$
works as the end of the python example.For a fenced-code block based zones, the end of the zone is clearly another end-marker. The following example will work
Here the python example will expect an empty new line after the
world
line but becausebyexample
currently removes it, it should not bring any trouble (however this depends on+term
).The shell example ends at the line where the zone ends (the end of the fenced-code block)
For non-fenced-code blocks, a zone finder could use indentation
Notice that the indentation of the snippet defines the indentation of the output. Also note that empty lines like the above between "Hello" and "world" may not be indented but they should be part of the output.
Note also the cases where the line is not really empty but it is semantically empty like here (Ruby example):
Describe alternatives you've considered (optional)
And
EOF
marker could be used but it looks weird.Additional context (optional)
This feature breaks assumptions that are deeply inside
byexample
since its root. AnExampleFinder
uses a regex to find an example and it uses an empty line and its own prompt as end-markers.Changing that will require that the regex knows about others' prompts so this is much complicated. If we don't stop at the begin of another prompt, a fenced-code based zone where two or more languages are mixed will break:
In the above case, the python example would span until the end of the zone.
Because this feature could potentially break a lot of examples, it should be enabled optionally. Moreover, this requires supports from each
ExampleFinder
(regex) andZonerFinder
(to decide if it is fenced-code or indentation based) and probably fromExampleParser
(to strip possibly the indentation)The text was updated successfully, but these errors were encountered: