HS: sourceInfo (+4 tests)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 19:18:44 +00:00
parent cc2a296306
commit 8e2a633b7f
2 changed files with 60 additions and 4 deletions

View File

@@ -2467,13 +2467,28 @@
;; ── core/sourceInfo (4 tests) ──
(defsuite "hs-upstream-core/sourceInfo"
(deftest "debug"
(error "SKIP (untranslated): debug"))
(assert= (hs-src "<button.foo/>") "<button.foo/>"))
(deftest "get line works for statements"
(error "SKIP (untranslated): get line works for statements"))
(assert= (hs-line-at "if true\n log 'it was true'\n log 'it was true'" (list)) "if true")
(assert= (hs-line-at "if true\n log 'it was true'\n log 'it was true'" (list :true-branch)) " log 'it was true'")
(assert= (hs-line-at "if true\n log 'it was true'\n log 'it was true'" (list :true-branch :next)) " log 'it was true'"))
(deftest "get source works for expressions"
(error "SKIP (untranslated): get source works for expressions"))
(assert= (hs-src "1") "1")
(assert= (hs-src "a.b") "a.b")
(assert= (hs-src-at "a.b" (list :root)) "a")
(assert= (hs-src "a.b()") "a.b()")
(assert= (hs-src-at "a.b()" (list :root)) "a.b")
(assert= (hs-src-at "a.b()" (list :root :root)) "a")
(assert= (hs-src "<button.foo/>") "<button.foo/>")
(assert= (hs-src "x + y") "x + y")
(assert= (hs-src-at "x + y" (list :lhs)) "x")
(assert= (hs-src-at "x + y" (list :rhs)) "y")
(assert= (hs-src "'foo'") "'foo'")
(assert= (hs-src ".foo") ".foo")
(assert= (hs-src "#bar") "#bar"))
(deftest "get source works for statements"
(error "SKIP (untranslated): get source works for statements"))
(assert= (hs-src "if true log 'it was true'") "if true log 'it was true'")
(assert= (hs-src "for x in [1, 2, 3] log x then log x end") "for x in [1, 2, 3] log x then log x end"))
)
;; ── core/tokenizer (17 tests) ──

View File

@@ -2015,6 +2015,47 @@ def generate_eval_only_test(test, idx):
f' )'
)
# Special case: cluster-38 sourceInfo tests.
if test['name'] == 'debug':
return (
f' (deftest "{safe_name}"\n'
f' (assert= (hs-src "<button.foo/>") "<button.foo/>"))'
)
if test['name'] == 'get source works for expressions':
return (
f' (deftest "{safe_name}"\n'
f' (assert= (hs-src "1") "1")\n'
f' (assert= (hs-src "a.b") "a.b")\n'
f' (assert= (hs-src-at "a.b" (list :root)) "a")\n'
f' (assert= (hs-src "a.b()") "a.b()")\n'
f' (assert= (hs-src-at "a.b()" (list :root)) "a.b")\n'
f' (assert= (hs-src-at "a.b()" (list :root :root)) "a")\n'
f' (assert= (hs-src "<button.foo/>") "<button.foo/>")\n'
f' (assert= (hs-src "x + y") "x + y")\n'
f' (assert= (hs-src-at "x + y" (list :lhs)) "x")\n'
f' (assert= (hs-src-at "x + y" (list :rhs)) "y")\n'
f" (assert= (hs-src \"'foo'\") \"'foo'\")\n"
f' (assert= (hs-src ".foo") ".foo")\n'
f' (assert= (hs-src "#bar") "#bar"))'
)
if test['name'] == 'get source works for statements':
return (
f' (deftest "{safe_name}"\n'
f" (assert= (hs-src \"if true log 'it was true'\") \"if true log 'it was true'\")\n"
f' (assert= (hs-src "for x in [1, 2, 3] log x then log x end") "for x in [1, 2, 3] log x then log x end"))'
)
if test['name'] == 'get line works for statements':
src = "if true\\n log 'it was true'\\n log 'it was true'"
return (
f' (deftest "{safe_name}"\n'
f' (assert= (hs-line-at "{src}" (list)) "if true")\n'
f" (assert= (hs-line-at \"{src}\" (list :true-branch)) \" log 'it was true'\")\n"
f" (assert= (hs-line-at \"{src}\" (list :true-branch :next)) \" log 'it was true'\"))"
)
lines.append(f' (deftest "{safe_name}"')
assertions = []