diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 03:35:02 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 04:08:29 -0300 |
| commit | a9529fa5712298e9005b77b471400529a2ebbc32 (patch) | |
| tree | 50633449f495e32f0a263277c260c7bef1a0db4d /test/hxcases | |
| parent | c40b95b8f938e01b7e8846bae53f16b0c1cd5654 (diff) | |
| download | pardes-a9529fa5712298e9005b77b471400529a2ebbc32.tar.gz pardes-a9529fa5712298e9005b77b471400529a2ebbc32.zip | |
hxdiff: a case may name its file pane ("path", whose extension picks the grammar), and test/hxcases/indent.jsonl pins the new line's indent in a Zig, a Python, a Rust and a plain-text file against the reference helix with its grammars, typed into a real hx in a pty by hx_indent.py since the harness runs without any; zig build hxdiff runs it before the suite
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/hxcases')
| -rw-r--r-- | test/hxcases/hx_indent.py | 89 | ||||
| -rw-r--r-- | test/hxcases/indent-goldens.jsonl | 25 | ||||
| -rw-r--r-- | test/hxcases/indent.jsonl | 25 |
3 files changed, 139 insertions, 0 deletions
diff --git a/test/hxcases/hx_indent.py b/test/hxcases/hx_indent.py new file mode 100644 index 00000000..c85c9417 --- /dev/null +++ b/test/hxcases/hx_indent.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +"""The goldens of indent.jsonl from helix itself, in a pty: $HX (else `hx` +on PATH) with its grammars and queries ($HELIX_RUNTIME) and its defaults +(auto-pairs on), LSP and auto-format off. They were made by the reference +helix (docs/helix-keys.md), 278b24389's `hx` built from the genizah checkout +with HELIX_RUNTIME its runtime/. Each case's file is named by its "path" (its +extension picks the language) and holds its "text"; the keys are typed, then +a marker where the cursor is, then `:wq!`. The marker's place is the cursor, +and the anchor: every case ends in insert mode with one cursor no wider than +helix's block (no `a` or `c` over a selection, whose anchor stays behind). + + HX=... HELIX_RUNTIME=... python3 -B test/hxcases/hx_indent.py \ + test/hxcases/indent.jsonl > test/hxcases/indent-goldens.jsonl +""" +import json, os, pty, select, struct, sys, tempfile, time, fcntl, termios + +MARK = "ยง" +KEYS = {"ret": "\r", "esc": "\x1b", "tab": "\t", "backspace": "\x7f", "lt": "<", "gt": ">"} + + +def keys(spec): + out, i = [], 0 + while i < len(spec): + if spec[i] == "<": + j = spec.index(">", i) + out.append(KEYS[spec[i + 1 : j]]) + i = j + 1 + else: + out.append(spec[i]) + i += 1 + return out + + +def drain(fd, secs): + end = time.time() + secs + while time.time() < end: + r, _, _ = select.select([fd], [], [], 0.02) + if r: + try: + os.read(fd, 65536) + except OSError: + return + + +def run(case, home): + path = os.path.join(home, os.path.basename(case["path"])) + with open(path, "w") as f: + f.write(case["text"]) + cfg = os.path.join(home, "config.toml") + with open(cfg, "w") as f: + f.write("[editor]\nauto-format = false\n[editor.lsp]\nenable = false\n") + pid, fd = pty.fork() + if pid == 0: + for v in ("CONFIG", "CACHE", "DATA", "STATE"): + os.environ["XDG_%s_HOME" % v] = home + os.environ["TERM"] = "xterm-256color" + hx = os.environ.get("HX", "hx") + os.execvp(hx, [hx, "-c", cfg, path]) + fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 24, 80, 0, 0)) + drain(fd, 1.0) + for k in keys(case["keys"]) + [MARK, "\x1b"]: + os.write(fd, k.encode()) + drain(fd, 0.25 if k == "\x1b" else 0.05) + for k in ":wq!\r": + os.write(fd, k.encode()) + drain(fd, 0.05) + for _ in range(100): + done, _ = os.waitpid(pid, os.WNOHANG) + if done: + break + drain(fd, 0.05) + else: + os.kill(pid, 9) + os.waitpid(pid, 0) + sys.exit("hx did not quit on case " + case["name"]) + os.close(fd) + with open(path) as f: + text = f.read() + at = text.index(MARK) + row = text.count("\n", 0, at) + col = len(text[text.rfind("\n", 0, at) + 1 : at].encode()) + cursor = {"row": row, "col": col} + return {"name": case["name"], "text": text.replace(MARK, "", 1), "mode": "insert", "cursor": cursor, "anchor": cursor} + + +with tempfile.TemporaryDirectory() as home: + for line in open(sys.argv[1]): + if line.strip(): + print(json.dumps(run(json.loads(line), home), separators=(",", ":"), ensure_ascii=False)) diff --git a/test/hxcases/indent-goldens.jsonl b/test/hxcases/indent-goldens.jsonl new file mode 100644 index 00000000..8e1b0f21 --- /dev/null +++ b/test/hxcases/indent-goldens.jsonl @@ -0,0 +1,25 @@ +{"name":"zig-ret-after-opener","text":"fn f() void {\n \n}\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"zig-ret-inside-block","text":"fn f() void {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"zig-ret-nested-block","text":"fn f() void {\n if (x) {\n \n a();\n }\n}\n","mode":"insert","cursor":{"row":2,"col":8},"anchor":{"row":2,"col":8}} +{"name":"zig-ret-before-closer","text":"fn f() void {\n a();\n}\n","mode":"insert","cursor":{"row":2,"col":0},"anchor":{"row":2,"col":0}} +{"name":"zig-ret-between-braces","text":"fn f() void {\n \n}\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"zig-o","text":"fn f() void {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"zig-O-after-opener","text":"fn f() void {\n \n a();\n}\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"zig-O-before-closer","text":"fn f() void {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"zig-typed-closer-stays","text":"fn f() void {\n a();\n }\n}\n","mode":"insert","cursor":{"row":2,"col":5},"anchor":{"row":2,"col":5}} +{"name":"py-ret-after-colon","text":"def f():\n \n pass\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"py-ret-inside-block","text":"def f():\n x = 1\n \n y = 2\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"py-ret-after-last-line","text":"def f():\n x = 1\n\n","mode":"insert","cursor":{"row":2,"col":0},"anchor":{"row":2,"col":0}} +{"name":"py-ret-after-return","text":"def f():\n return 1\n\n","mode":"insert","cursor":{"row":2,"col":0},"anchor":{"row":2,"col":0}} +{"name":"py-o","text":"if x:\n \n y()\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"py-O","text":"if x:\n \n y()\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"py-ret-between-brackets","text":"x = [\n \n]\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"rs-ret-after-opener","text":"fn f() {\n \n}\n","mode":"insert","cursor":{"row":1,"col":4},"anchor":{"row":1,"col":4}} +{"name":"rs-ret-inside-block","text":"fn f() {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"rs-ret-before-closer","text":"fn f() {\n a();\n}\n","mode":"insert","cursor":{"row":2,"col":0},"anchor":{"row":2,"col":0}} +{"name":"rs-ret-between-parens","text":"fn g() {\n f(\n \n );\n}\n","mode":"insert","cursor":{"row":2,"col":8},"anchor":{"row":2,"col":8}} +{"name":"rs-o","text":"fn f() {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"rs-O","text":"fn f() {\n a();\n \n}\n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"txt-ret-copies-indent","text":"a\n b\n \n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} +{"name":"txt-ret-between-braces","text":"a\n x {\n \n }\n","mode":"insert","cursor":{"row":2,"col":8},"anchor":{"row":2,"col":8}} +{"name":"txt-o","text":"a\n b\n \n","mode":"insert","cursor":{"row":2,"col":4},"anchor":{"row":2,"col":4}} diff --git a/test/hxcases/indent.jsonl b/test/hxcases/indent.jsonl new file mode 100644 index 00000000..8330badf --- /dev/null +++ b/test/hxcases/indent.jsonl @@ -0,0 +1,25 @@ +{"name": "zig-ret-after-opener", "path": "/x.zig", "text": "fn f() void {\n}\n", "keys": "A<ret>"} +{"name": "zig-ret-inside-block", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jA<ret>"} +{"name": "zig-ret-nested-block", "path": "/x.zig", "text": "fn f() void {\n if (x) {\n a();\n }\n}\n", "keys": "jA<ret>"} +{"name": "zig-ret-before-closer", "path": "/x.zig", "text": "fn f() void {\n a();}\n", "keys": "jgli<ret>"} +{"name": "zig-ret-between-braces", "path": "/x.zig", "text": "fn f() void {}\n", "keys": "gli<ret>"} +{"name": "zig-o", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jo"} +{"name": "zig-O-after-opener", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jO"} +{"name": "zig-O-before-closer", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jjO"} +{"name": "zig-typed-closer-stays", "path": "/x.zig", "text": "fn f() void {\n a();\n}\n", "keys": "jo}"} +{"name": "py-ret-after-colon", "path": "/x.py", "text": "def f():\n pass\n", "keys": "A<ret>"} +{"name": "py-ret-inside-block", "path": "/x.py", "text": "def f():\n x = 1\n y = 2\n", "keys": "jA<ret>"} +{"name": "py-ret-after-last-line", "path": "/x.py", "text": "def f():\n x = 1\n", "keys": "jA<ret>"} +{"name": "py-ret-after-return", "path": "/x.py", "text": "def f():\n return 1\n", "keys": "jA<ret>"} +{"name": "py-o", "path": "/x.py", "text": "if x:\n y()\n", "keys": "o"} +{"name": "py-O", "path": "/x.py", "text": "if x:\n y()\n", "keys": "jO"} +{"name": "py-ret-between-brackets", "path": "/x.py", "text": "x = []\n", "keys": "gli<ret>"} +{"name": "rs-ret-after-opener", "path": "/x.rs", "text": "fn f() {\n}\n", "keys": "A<ret>"} +{"name": "rs-ret-inside-block", "path": "/x.rs", "text": "fn f() {\n a();\n}\n", "keys": "jA<ret>"} +{"name": "rs-ret-before-closer", "path": "/x.rs", "text": "fn f() {\n a();}\n", "keys": "jgli<ret>"} +{"name": "rs-ret-between-parens", "path": "/x.rs", "text": "fn g() {\n f();\n}\n", "keys": "jglhi<ret>"} +{"name": "rs-o", "path": "/x.rs", "text": "fn f() {\n a();\n}\n", "keys": "jo"} +{"name": "rs-O", "path": "/x.rs", "text": "fn f() {\n a();\n}\n", "keys": "jjO"} +{"name": "txt-ret-copies-indent", "path": "/x.txt", "text": "a\n b\n", "keys": "jA<ret>"} +{"name": "txt-ret-between-braces", "path": "/x.txt", "text": "a\n x {}\n", "keys": "jgli<ret>"} +{"name": "txt-o", "path": "/x.txt", "text": "a\n b\n", "keys": "jo"} |
