Editor test suite ships in tst/ (from dev 4e8c3db2882d)

This commit is contained in:
2026-07-27 01:59:29 +02:00
parent 01b1cc959a
commit 73ed7f3d5d
31 changed files with 419 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
@table
123456789012345678901234567890 | x ||
abcdefghijklmnopqrstuvwxyzabcde | y ||
short | z ||
@

View File

@@ -0,0 +1,5 @@
@table
123456789012345678901234567890 | x ||
abcdefghijklmnopqrstuvwxyzabcde | y ||
short | z ||
@

View File

@@ -0,0 +1,4 @@
@table
one | two | three ||
spanning | wide ||
@

View File

@@ -0,0 +1,4 @@
@table
one | two | three ||
spanning | wide ||
@

View File

@@ -0,0 +1,4 @@
@table
a | | b ||
cc | dd | ee ||
@

View File

@@ -0,0 +1,4 @@
@table
a | | b ||
cc | dd | ee ||
@

View File

@@ -0,0 +1,4 @@
@table
a ^| b | c ||
dd | ee ||
@

View File

@@ -0,0 +1,4 @@
@table
a ^| b | c ||
dd | ee ||
@

12
tst/editor/align_mixed.kt Normal file
View File

@@ -0,0 +1,12 @@
Some text before.
@table :caption Test
First item | Second | A third item that's longer ||
Row 2 | Text | Not as long ||
:column_width f f f
A cell that is way way too long to align nicely here | x | y ||
Multi | line cell
continues here | z ||
@b bold @ | @frac 1 | 2 @ ||
Last | row | here
@
After.

View File

@@ -0,0 +1,12 @@
Some text before.
@table :caption Test
First item | Second | A third item that's longer ||
Row 2 | Text | Not as long ||
:column_width f f f
A cell that is way way too long to align nicely here | x | y ||
Multi | line cell
continues here | z ||
@b bold @ | @frac 1 | 2 @ ||
Last | row | here
@
After.

View File

@@ -0,0 +1,4 @@
@table
xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx ||
xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx ||
@

View File

@@ -0,0 +1,4 @@
@table
xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx ||
xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxxxxxxxxxxxxxxxxxxx ||
@

View File

@@ -0,0 +1,30 @@
;;; editor_driver.el --- drive the Emacs editor units over fixtures -*- lexical-binding: t; -*-
;; Usage:
;; emacs --batch -L EMACSDIR -l klammertext-mode -l klammertext-indent
;; -l klammertext-align -l editor_driver.el MODE INFILE OUTFILE ...
;;
;; MODE is "indent" or "align"; each triple applies that tool to INFILE and
;; writes the result to OUTFILE. Called by editor_test.sh.
(let ((args command-line-args-left))
(setq command-line-args-left nil) ; keep batch Emacs from visiting them
(while args
(let ((mode (pop args))
(in (pop args))
(out (pop args)))
(with-temp-buffer
(insert-file-contents in)
(klammertext-mode)
(cond
((string= mode "indent")
(indent-region (point-min) (point-max)))
((string= mode "align")
(goto-char (point-min))
(when (search-forward "|" nil t)
(goto-char (1- (point))))
(klammertext-align-table))
(t (error "editor_driver.el: unknown mode %s" mode)))
(write-region (point-min) (point-max) out nil 'silent)))))
;;; editor_driver.el ends here

View File

@@ -0,0 +1,63 @@
#!/usr/bin/env python3
"""Drive the Sublime Text editor cores over fixture files, outside Sublime.
Usage: editor_driver.py SUBLIME_DIR (MODE INFILE OUTFILE)...
MODE is `indent` or `align`; each triple applies that tool to INFILE and
writes the result to OUTFILE. The Sublime plugin files import without the
`sublime` module (their try/except guard), so the pure cores run under plain
python3. Also asserts the built-in error path (no enclosing table).
Called by editor_test.sh; exits nonzero on an internal error.
"""
import sys
def apply_indent(KI, s):
bols = [0] + [i + 1 for i, ch in enumerate(s)
if ch == '\n' and i + 1 < len(s)]
out = s
for a, b, new in sorted(KI.reindent_lines(s, bols), reverse=True):
out = out[:a] + new + out[b:]
return out
def apply_align(KA, s):
caret = s.index('|') if '|' in s else 0
span = KA.enclosing_span(s, caret, KA.ALIGN_KLAMMERS)
if span is None:
return s
_name, cs, ce = span
edits, _msg = KA.compute_edits(s[cs:ce])
out = s
for a, b, new in sorted(edits, reverse=True):
out = out[:cs + a] + new + out[cs + b:]
return out
def main():
sublime_dir = sys.argv[1]
sys.path.insert(0, sublime_dir)
import Klammertext_indent as KI
import Klammertext_align as KA
args = sys.argv[2:]
for k in range(0, len(args), 3):
mode, infile, outfile = args[k:k + 3]
with open(infile) as f:
s = f.read()
if mode == 'indent':
out = apply_indent(KI, s)
elif mode == 'align':
out = apply_align(KA, s)
else:
sys.exit("editor_driver.py: unknown mode: " + mode)
with open(outfile, 'w') as f:
f.write(out)
# Error path: no enclosing table klammer.
assert KA.enclosing_span("no table here\n", 3, KA.ALIGN_KLAMMERS) is None
if __name__ == '__main__':
main()

12
tst/editor/indent_defs.kt Normal file
View File

@@ -0,0 +1,12 @@
@@note.k s :label Note :color 1.0,1.0,0.9
:level.int 0
: Rectangular block for a special note @@
@@quote.txt ::
@eval block.block_indent(K) eval@
@@
@@@state Word_max
:desc Maximum words
:value 7
@@@

View File

@@ -0,0 +1,12 @@
@@note.k s :label Note :color 1.0,1.0,0.9
:level.int 0
: Rectangular block for a special note @@
@@quote.txt ::
@eval block.block_indent(K) eval@
@@
@@@state Word_max
:desc Maximum words
:value 7
@@@

View File

@@ -0,0 +1,10 @@
@document :structure plain :text
This is a normal paragraph, at the left margin.
@ol
One
| Two
@
More text after the list.
@

View File

@@ -0,0 +1,10 @@
@document :structure plain :text
This is a normal paragraph, at the left margin.
@ol
One
| Two
@
More text after the list.
@

View File

@@ -0,0 +1,5 @@
@ol
Item one
| ^| a literal bar item
^@ a literal at line
@

View File

@@ -0,0 +1,5 @@
@ol
Item one
| ^| a literal bar item
^@ a literal at line
@

11
tst/editor/indent_list.kt Normal file
View File

@@ -0,0 +1,11 @@
@ol
Item one
| Item two
| Item three
@ol
Embedded item one
| Embedded item two
@
| Item four
| Item five
@

View File

@@ -0,0 +1,11 @@
@ol
Item one
| Item two
| Item three
@ol
Embedded item one
| Embedded item two
@
| Item four
| Item five
@

View File

@@ -0,0 +1,10 @@
@document :structure plain :text
Text at the margin.
@quote
Quoted text.
quote@
document@
@@mydef arg :
Body of the definition.
mydef@@

View File

@@ -0,0 +1,10 @@
@document :structure plain :text
Text at the margin.
@quote
Quoted text.
quote@
document@
@@mydef arg :
Body of the definition.
mydef@@

View File

@@ -0,0 +1,4 @@
@table
First item | Second | A third item that's longer ||
Row 2 | Text | Not as long ||
@

View File

@@ -0,0 +1,4 @@
@table
First item | Second | A third item that's longer ||
Row 2 | Text | Not as long ||
@

View File

@@ -0,0 +1,14 @@
@code
def f(x):
if x:
return 1
code@
@eval
def g(y):
return y + 1
g(2)
@
@@@state Word_max
:desc A description line
:value 7
@@@

View File

@@ -0,0 +1,14 @@
@code
def f(x):
if x:
return 1
code@
@eval
def g(y):
return y + 1
g(2)
@
@@@state Word_max
:desc A description line
:value 7
@@@