diff options
Diffstat (limited to 'sam')
| -rw-r--r-- | sam/README.md | 49 | ||||
| -rw-r--r-- | sam/commands/loop-lines.in | 10 | ||||
| -rw-r--r-- | sam/commands/loop-lines1.cmd | 3 | ||||
| l---------[-rw-r--r--] | sam/commands/loop-lines1.in | 11 | ||||
| -rw-r--r-- | sam/commands/loop-lines2.cmd | 3 | ||||
| l---------[-rw-r--r--] | sam/commands/loop-lines2.in | 11 | ||||
| -rw-r--r-- | sam/commands/loop-lines3.cmd | 1 | ||||
| l--------- | sam/commands/loop-lines3.in | 1 | ||||
| -rw-r--r-- | sam/commands/loop-lines4.cmd | 1 | ||||
| l--------- | sam/commands/loop-lines4.in | 1 | ||||
| -rw-r--r-- | sam/commands/loop-lines5.cmd | 1 | ||||
| l--------- | sam/commands/loop-lines5.in | 1 | ||||
| -rw-r--r-- | sam/commands/loop-lines6.cmd | 1 | ||||
| l--------- | sam/commands/loop-lines6.in | 1 | ||||
| -rw-r--r-- | sam/commands/loop-lines7.cmd | 1 | ||||
| l--------- | sam/commands/loop-lines7.in | 1 | ||||
| -rw-r--r-- | sam/commands/loop-lines8.cmd | 1 | ||||
| l--------- | sam/commands/loop-lines8.in | 1 | ||||
| -rw-r--r-- | sam/commands/pipe-in.cmd | 2 | ||||
| -rwxr-xr-x | sam/test.sh | 7 | ||||
| -rw-r--r-- | sam/visrc.lua | 15 |
21 files changed, 63 insertions, 60 deletions
diff --git a/sam/README.md b/sam/README.md index 64b14e2..83cf2af 100644 --- a/sam/README.md +++ b/sam/README.md @@ -3,8 +3,10 @@ Tests for vis - structural regular expression support We test the structural regular expression implementation by supplying the same command to both vis and [sam](http://sam.cat-v.org/). More -concretely, we use `ssam(1)` the non-graphical streaming interface to -sam. These tests are intended to be run on a system with +concretely, we use a `ssam(1)` like script drive the non-graphical +streaming interface of sam. + +These tests are intended to be run on a system with [9base](http://tools.suckless.org/9base) or [plan9port](https://swtch.com/plan9port/) installed. @@ -19,50 +21,39 @@ when writing tests: infrastructure. * _different semantics_: some language constructs have slightly - different semantics. Of particular relevance is the different grouping - implementation. In sam each command of a group is executed with - the same initial file state and all changes are later applied in parallel - (if no conflict occurred and all changes were in sequence). Whereas - vis applies the changes immediately and subsequent commands will - operate on the modified file content. + different semantics. As an example in `sam` searches wrap around + while in `vis` they stop at the start/end of the file. - As a consequence the following snippet to swap two words does currently - not work in vis: + * _changes need to be in sequence_: sam will reject changes which are not + in sequence (i.e. all changes need to be performed in monotonically + increasing file position). The following will not work: ``` - ,x/[a-zA-Z]+/{ - g/Emacs/ v/....../ c/vi/ - g/vi/ v/.../ c/Emacs/ + ,x/pattern/ { + a/</ + i/>/ } + ?changes not in sequence ``` - This is particularly relevant for the tests because they are all - executed in an implicit group. - - * _changes need to be in sequence_: sam will reject changes which are not - in sequence (i.e. all changes need to be performed in ascending file - position). The following will not work: + In contrast vis only requires that the changes are non-overlapping. + The above works as expected, but the following is rejected: ``` - { - 10d - 5d + ,x/pattern/ { + c/foo/ + c/bar/ } ?changes not in sequence ``` - However, due to the aforementioned vis grouping semantics, swapping - the line numbers around, will not produce the same result either - (line 5 will already be deleted by the time the address of line 10 - is evaluated, thus the original line 11 will be deleted instead). - * _spurious white spaces_: in sam an empty line/command affects the dot (current range to operate on), namely it is extended to cover the whole line. However in vis we ignore all white space between commands. In order to avoid differing behavior avoid spurious white space between your commands in the test cases. -For now the tests need to take these quirks into account, some of the +For now the tests need to take these differences into account, some of the vis behavior might be changed in the future. A test constitutes of 3 files, the first 2 of which are mandatory: @@ -74,6 +65,8 @@ A test constitutes of 3 files, the first 2 of which are mandatory: * `test.ref` if omitted, the output from sam will be considered as reference. +All commands of a `test.cmd` are executed in an implicit group `.{ ... }`. + The top level shell script `test.sh` looks for these files in sub directories, executes both editors and compares the resulting output. diff --git a/sam/commands/loop-lines.in b/sam/commands/loop-lines.in new file mode 100644 index 0000000..f00c965 --- /dev/null +++ b/sam/commands/loop-lines.in @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/sam/commands/loop-lines1.cmd b/sam/commands/loop-lines1.cmd index 88ca881..f947289 100644 --- a/sam/commands/loop-lines1.cmd +++ b/sam/commands/loop-lines1.cmd @@ -1,4 +1 @@ ,x/^.*$/ a,\\, -,x/$/ c/#/ -,y/\n/ a/*/ -,x a/--/ diff --git a/sam/commands/loop-lines1.in b/sam/commands/loop-lines1.in index f00c965..0ad8301 100644..120000 --- a/sam/commands/loop-lines1.in +++ b/sam/commands/loop-lines1.in @@ -1,10 +1 @@ -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 +loop-lines.in
\ No newline at end of file diff --git a/sam/commands/loop-lines2.cmd b/sam/commands/loop-lines2.cmd index a773f97..696aab4 100644 --- a/sam/commands/loop-lines2.cmd +++ b/sam/commands/loop-lines2.cmd @@ -1,4 +1 @@ ,x/^.*$/ i,//, -,x/^/ c/#/ -,y/\n/ i/*/ -,x i/--/ diff --git a/sam/commands/loop-lines2.in b/sam/commands/loop-lines2.in index f00c965..0ad8301 100644..120000 --- a/sam/commands/loop-lines2.in +++ b/sam/commands/loop-lines2.in @@ -1,10 +1 @@ -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 +loop-lines.in
\ No newline at end of file diff --git a/sam/commands/loop-lines3.cmd b/sam/commands/loop-lines3.cmd new file mode 100644 index 0000000..9f16753 --- /dev/null +++ b/sam/commands/loop-lines3.cmd @@ -0,0 +1 @@ +,x/^/ c/#/ diff --git a/sam/commands/loop-lines3.in b/sam/commands/loop-lines3.in new file mode 120000 index 0000000..0ad8301 --- /dev/null +++ b/sam/commands/loop-lines3.in @@ -0,0 +1 @@ +loop-lines.in
\ No newline at end of file diff --git a/sam/commands/loop-lines4.cmd b/sam/commands/loop-lines4.cmd new file mode 100644 index 0000000..4ce51bf --- /dev/null +++ b/sam/commands/loop-lines4.cmd @@ -0,0 +1 @@ +,x/$/ c/#/ diff --git a/sam/commands/loop-lines4.in b/sam/commands/loop-lines4.in new file mode 120000 index 0000000..0ad8301 --- /dev/null +++ b/sam/commands/loop-lines4.in @@ -0,0 +1 @@ +loop-lines.in
\ No newline at end of file diff --git a/sam/commands/loop-lines5.cmd b/sam/commands/loop-lines5.cmd new file mode 100644 index 0000000..45539d5 --- /dev/null +++ b/sam/commands/loop-lines5.cmd @@ -0,0 +1 @@ +,y/\n/ i/*/ diff --git a/sam/commands/loop-lines5.in b/sam/commands/loop-lines5.in new file mode 120000 index 0000000..0ad8301 --- /dev/null +++ b/sam/commands/loop-lines5.in @@ -0,0 +1 @@ +loop-lines.in
\ No newline at end of file diff --git a/sam/commands/loop-lines6.cmd b/sam/commands/loop-lines6.cmd new file mode 100644 index 0000000..8204e7d --- /dev/null +++ b/sam/commands/loop-lines6.cmd @@ -0,0 +1 @@ +,y/\n/ a/*/ diff --git a/sam/commands/loop-lines6.in b/sam/commands/loop-lines6.in new file mode 120000 index 0000000..0ad8301 --- /dev/null +++ b/sam/commands/loop-lines6.in @@ -0,0 +1 @@ +loop-lines.in
\ No newline at end of file diff --git a/sam/commands/loop-lines7.cmd b/sam/commands/loop-lines7.cmd new file mode 100644 index 0000000..b948c78 --- /dev/null +++ b/sam/commands/loop-lines7.cmd @@ -0,0 +1 @@ +,x i/--/ diff --git a/sam/commands/loop-lines7.in b/sam/commands/loop-lines7.in new file mode 120000 index 0000000..0ad8301 --- /dev/null +++ b/sam/commands/loop-lines7.in @@ -0,0 +1 @@ +loop-lines.in
\ No newline at end of file diff --git a/sam/commands/loop-lines8.cmd b/sam/commands/loop-lines8.cmd new file mode 100644 index 0000000..3cb435a --- /dev/null +++ b/sam/commands/loop-lines8.cmd @@ -0,0 +1 @@ +,x a/--/ diff --git a/sam/commands/loop-lines8.in b/sam/commands/loop-lines8.in new file mode 120000 index 0000000..0ad8301 --- /dev/null +++ b/sam/commands/loop-lines8.in @@ -0,0 +1 @@ +loop-lines.in
\ No newline at end of file diff --git a/sam/commands/pipe-in.cmd b/sam/commands/pipe-in.cmd index 054bf73..1a67edb 100644 --- a/sam/commands/pipe-in.cmd +++ b/sam/commands/pipe-in.cmd @@ -1,3 +1,3 @@ -1 < echo Replace first line 0 < echo Before first line +1 < echo Replace first line $ < echo New Last line diff --git a/sam/test.sh b/sam/test.sh index 0cbce36..a6d5b4e 100755 --- a/sam/test.sh +++ b/sam/test.sh @@ -32,7 +32,6 @@ TESTS_OK=0 for t in $TESTS; do IN="$t.in" - CMD="$(cat $t.cmd)" SAM_OUT="$t.sam.out" SAM_ERR="$t.sam.err" VIS_OUT="$t.vis.out" @@ -43,10 +42,8 @@ for t in $TESTS; do { echo ',{' - echo k - echo '}' - echo 0k cat "$t.cmd" + echo '}' echo , } | $SAM -d "$IN" > "$SAM_OUT" 2>/dev/null @@ -71,7 +68,7 @@ for t in $TESTS; do TESTS_RUN=$((TESTS_RUN+1)) - $VIS "+,{ $NL $CMD $NL wq! $VIS_OUT $NL }" "$IN" 2>/dev/null + $VIS "$IN" </dev/null 2>/dev/null printf "Running test %s with vis ... " "$t" if [ $? -ne 0 -o ! -e "$VIS_OUT" ]; then diff --git a/sam/visrc.lua b/sam/visrc.lua index e69de29..c5cda31 100644 --- a/sam/visrc.lua +++ b/sam/visrc.lua @@ -0,0 +1,15 @@ +vis.events = {} +vis.events.win_open = function(win) + -- test.in file passed to vis + local in_file = win.file.name + if in_file then + -- use the corresponding test.cmd file + local cmd_file_name = string.gsub(in_file, '%.in$', '.cmd'); + local cmd_file = io.open(cmd_file_name) + local cmd = cmd_file:read('*all') + vis:command(string.format(",{\n %s\n }", cmd)) + local out_file_name = string.gsub(in_file, '%.in$', '.vis.out') + vis:command(string.format("wq! %s", out_file_name)) + end + vis:command('qall!') +end |
