Skip to content

Commit

Permalink
Use U+00A0 as replacement for ~ in +rm
Browse files Browse the repository at this point in the history
  • Loading branch information
eldipa committed Jul 6, 2020
1 parent df6325c commit b57c7cc
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 321 deletions.
26 changes: 13 additions & 13 deletions docs/advanced/shebang.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ Consider the following example that prints interesting things to standard output
and debug/uninteresting things to standard error:

```
$ cat test/ds/blog-database # byexample: +rm=~
~ >>> from __future__ import print_function
~ >>> import sys
~
~ >>> def load_database():
~ ... print("Loading...")
~ ... print("debug 314kb", file=sys.stderr)
~ ... print("Done")
~
~ >>> load_database()
~ Loading...
~ Done
~
$ cat test/ds/blog-database # byexample: +rm= 
  >>> from __future__ import print_function
  >>> import sys
 
  >>> def load_database():
  ... print("Loading...")
  ... print("debug 314kb", file=sys.stderr)
  ... print("Done")
 
  >>> load_database()
  Loading...
  Done
 
```

Running this will fail because the debug print will be mixed with the normal
Expand Down
42 changes: 21 additions & 21 deletions docs/advanced/terminal-emulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,27 @@ that use ``ncurses``) and require a terminal emulator.
Examples of this are programs like ``less``, ``more``, ``top`` and ``man``.
```shell
$ less test/ds/python-tutorial.v2.md # byexample: +term=ansi +rm=~ +stop-on-timeout
~This is a 101 Python tutorial
~The following is an example written in Python about arithmetics
~
~ ```
~ >>> from __future__ import print_function
~ >>> 1 + 2
~ 3
~ ```
~
~The next examples show you about complex numbers in Python
~
~ ```
~ >>> 2j * 2
~ 4j
~
~ >>> 2j + 4j
~ 6j
~ ```
~
~<...>(END)
$ less test/ds/python-tutorial.v2.md # byexample: +term=ansi +rm=  +stop-on-timeout
 This is a 101 Python tutorial
 The following is an example written in Python about arithmetics
 
  ```
  >>> from __future__ import print_function
  >>> 1 + 2
  3
  ```
 
 The next examples show you about complex numbers in Python
 
  ```
  >>> 2j * 2
  4j
 
  >>> 2j + 4j
  6j
  ```
 
 <...>(END)
```
> Try the above example without ``+term=ansi`` and see what happens.
Expand Down
454 changes: 227 additions & 227 deletions docs/advanced/unicode.md

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions docs/basic/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ however, when a capture tag is found, `byexample` requires at minimum
of text before the input tag and if there is not enough it will complain:

```shell
$ cat test/ds/minimum-ctx-input.md # byexample: +rm=~
<...>
~>>> x = input("say: ") # byexample: +input
sa<...>y: [foo]
~
~>>> x
'foo'
<...>
$ cat test/ds/minimum-ctx-input.md # byexample: +rm= 
 <...>
 >>> x = input("say: ") # byexample: +input
 sa<...>y: [foo]
 
 >>> x
 'foo'
 <...>


$ byexample -l python test/ds/minimum-ctx-input.md
Expand All @@ -137,14 +137,14 @@ the given text; if the example keeps waiting for it the example will
eventually timeout:

```shell
$ cat test/ds/maximum-ctx-input.md # byexample: +rm=~
<...>
~>>> x = input("Some large text: ") # byexample: +input
Some typo! text: [foo]
~
~>>> x
'foo'
<...>
$ cat test/ds/maximum-ctx-input.md # byexample: +rm= 
 <...>
 >>> x = input("Some large text: ") # byexample: +input
 Some typo! text: [foo]
 
 >>> x
 'foo'
 <...>

$ byexample -l python test/ds/maximum-ctx-input.md
<...>=> Execution timedout at example 1 of 2.
Expand Down
18 changes: 9 additions & 9 deletions docs/basic/setup-and-tear-down.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ It is also reasonable to *tear down* the database connection at the end.
You could write:

```
$ cat test/ds/db-stock-model # byexample: +rm=°
$ cat test/ds/db-stock-model # byexample: +rm= 
This is a quick introduction to the database schema.
° >>> import sqlite3
° >>> c = sqlite3.connect(':memory:')
° >>> _ = c.executescript(open('test/ds/stock.sql').read()) # ---> # byexample: +fail-fast
°
  >>> import sqlite3
  >>> c = sqlite3.connect(':memory:')
  >>> _ = c.executescript(open('test/ds/stock.sql').read()) # ---> # byexample: +fail-fast
 
Get the stocks' prices
° >>> _ = c.execute('select price from stocks')
°
  >>> _ = c.execute('select price from stocks')
 
Do not forget to close the connection
° >>> c.close() # ---> # byexample: -skip
°
  >>> c.close() # ---> # byexample: -skip
 
```

In a happy and perfect world this should run smoothly:
Expand Down
16 changes: 8 additions & 8 deletions docs/overview/differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ For this reason ``byexample`` allows you to change the diff algorithm
with ``--diff``:

```
$ byexample -l shell --diff ndiff test/ds/about-lic.doc # byexample: +rm=~
$ byexample -l shell --diff ndiff test/ds/about-lic.doc # byexample: +rm= 
<...>
Differences:
- To protect your rights, we need to prevent others from denying you
? ^^ --
~
 
+ To protect your rights, we need to prevent no-one from denying you
? + ^^^
~
 
- these rights or asking you to surrender the rights. Therefore, you have
+ these rights or asking you to surrender the rights. Therefore, you don't have
? ++++++
~
 
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
<...>
Expand Down Expand Up @@ -152,15 +152,15 @@ and *replaced* the tags by the captured text.
These *guesses* makes the differences shorter and more easy to spot:

```
$ byexample -l shell --diff ndiff test/ds/about-lic-with-tags.doc # byexample: +rm=~
$ byexample -l shell --diff ndiff test/ds/about-lic-with-tags.doc # byexample: +rm= 
<...>
Differences:
- To protect your rights, we need to prevent others from <prevent1>
? ^^ -- ^^^^^ ^^^
~
 
+ To protect your rights, we need to prevent no-one from denying you
? + ^^^ ^ ^^^^^^^^
~
 
- or <prevent2>. Therefore, you have
+ these rights or asking you to surrender the rights. Therefore, you don't have
certain responsibilities if you distribute copies of the software, or if
Expand All @@ -183,7 +183,7 @@ You can disable this with the ``--no-enhance-diff`` from the command line.
You will see a much harder to interpreter diff with more errors:

```shell
$ byexample -l shell --diff ndiff --no-enhance-diff test/ds/about-lic-with-tags.doc # byexample: +rm=~
$ byexample -l shell --diff ndiff --no-enhance-diff test/ds/about-lic-with-tags.doc # byexample: +rm= 
<...>
Differences:
- To protect <protect>, we need to prevent others from <prevent1>
Expand Down
10 changes: 10 additions & 0 deletions docs/overview/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ Line1
Line3
```

Tip: you can use the invisible unicode character U+00A0 (` `) instead
of an `~`:

```python
>>> print("Line1\n\nLine3") # byexample: +rm= 
Line1

Line3
```

### How to ignore the capture tag ``<xxx>``?

If the output of your example has the literal ``<xxx>`` and you want
Expand Down
54 changes: 27 additions & 27 deletions docs/overview/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ So you open your favorite editor, write some comments, you enhance them with
real ``Python`` examples and you get something like this:

```
$ cat test/ds/python-tutorial.v1.md # byexample: +rm=~
$ cat test/ds/python-tutorial.v1.md # byexample: +rm= 
This is a 101 Python tutorial
The following is an example written in Python about arithmetics
~
~ ```
~ >>> from __future__ import print_function
~ >>> 1 + 2
~ 3
~ ```
~
 
  ```
  >>> from __future__ import print_function
  >>> 1 + 2
  3
  ```
 
The next examples show you about complex numbers in Python
~
~ ```
~ >>> 2j * 2
~ 4
~
~ >>> 2j + 4j
~ 6
~ ```
 
  ```
  >>> 2j * 2
  4
 
  >>> 2j + 4j
  6
  ```
```
Now we want to be sure that the examples in the blog are correct.
Expand Down Expand Up @@ -89,25 +89,25 @@ The help included in ``byexample`` should give you a quick overview of its
capabilities
```
$ byexample -h # byexample: +norm-ws -tags +rm=~ +diff=ndiff
$ byexample -h # byexample: +norm-ws -tags +rm=  +diff=ndiff
usage: byexample -l <languages> [--ff] [--timeout <secs>] [-j <n>] [--dry]
[--skip <file> [<file> ...]]
[-d {none,unified,ndiff,context,tool}] [--difftool <cmd>]
[--no-enhance-diff] [-o <options>] [--show-options]
[-m <dir>] [--encoding <enc>] [--pretty {none,all}] [-V]
[-v | -q] [-h | -xh]
~
 
Write snippets of code in C++, Python, Ruby, and others as documentation and
execute them as regression tests.
~
 
positional arguments:
<file> files that have the examples to run.
~
 
Language Selection:
-l <languages>, --language <languages>, --languages <languages>
select which languages to parse and run. Comma
separated syntax is also accepted.
~
 
Execution Options:
--ff, --fail-fast if an example fails, fail and stop all the execution.
--timeout <secs> timeout in seconds to complete each example (2 by
Expand All @@ -120,7 +120,7 @@ Execution Options:
--dry do not run any example, only parse them.
--skip <file> [<file> ...]
skip these files
~
 
Diff Options:
-d {none,unified,ndiff,context,tool}, --diff {none,unified,ndiff,context,tool}
select diff algorithm (none by default).
Expand All @@ -132,7 +132,7 @@ Diff Options:
to to understand: non-printable characters are
visible; captured string shown, and more; this flag
disables all of that.
~
 
Miscellaneous Options:
-o <options>, --options <options>
add additional options; see --show-options to list
Expand All @@ -144,22 +144,22 @@ Miscellaneous Options:
--encoding <enc> select the encoding (default: utf-8).
--pretty {none,all} control how to pretty print the output.
-V, --version show byexample's version and license, then exit
~
 
Logging:
-v verbosity level, add more flags to increase the level.
-q, --quiet quiet mode, do not print anything even if an example
fails; suppress the progress output.
~
 
Help Options:
-h, --help show this help message and exit
-xh show this help message plus the one for the advanced
options and exit
~
 
Examples:
byexample -l python file.py
byexample -l python,ruby --ff --timeout=8 file.md
byexample -l python,ruby --show-options
~
 
See https://byexamples.github.io for the full documentation
and more examples.
```
9 changes: 9 additions & 0 deletions docs/overview/where-should-I-write-the-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ hello
world!
```

Any symbol can be used as well like `°` or even ` ` (the invisible
unicode character U+00A0)

```python
>>> print("hello\n\nworld!") # byexample: +rm= 
hello

world!
```

## New lines at the end are ignored

Expand Down

0 comments on commit b57c7cc

Please sign in to comment.