1
0
Fork 0
Code Issues Pull requests Projects Releases 2 Packages Wiki Activity Actions Pages

Group source comments in logic views

This commit is contained in:
Andraxion 2026-07-25 22:51:56 -04:00
parent 6d659ba381
commit a30f021a52
4 changed files with 67 additions and 13 deletions

View file

@ -11,7 +11,7 @@ from docforge.treesitter_logic import (
class JavaScriptLogicTests(unittest.TestCase):
def test_comments_do_not_become_logic_actions(self) -> None:
def test_consecutive_comments_become_one_logic_comment_block(self) -> None:
source = """
function choose(enabled) {
// Explain the condition.
@ -28,9 +28,13 @@ function choose(enabled) {
owners=(TreeSitterLogicOwner("js.symbol.choose", "choose", 1),),
)[0]
labels = {node.label for node in projection.nodes}
self.assertFalse(any(label.startswith(("//", "/*")) for label in labels))
self.assertIn("accept();", labels)
comments = [node for node in projection.nodes if node.kind == "comment"]
self.assertEqual(len(comments), 1)
self.assertEqual(
comments[0].label,
"Explain the condition. Continue the explanation. A block comment is trivia too.",
)
self.assertIn("accept();", {node.label for node in projection.nodes})
def test_branches_short_circuit_and_converge(self) -> None:
source = """
@ -111,7 +115,7 @@ function process(items, mode) {
class CppLogicTests(unittest.TestCase):
def test_comments_do_not_become_logic_actions(self) -> None:
def test_consecutive_comments_become_one_logic_comment_block(self) -> None:
source = """
int choose(bool enabled) {
// Explain the condition.
@ -128,9 +132,13 @@ int choose(bool enabled) {
owners=(TreeSitterLogicOwner("cpp.symbol.choose", "choose", 1),),
)[0]
labels = {node.label for node in projection.nodes}
self.assertFalse(any(label.startswith(("//", "/*")) for label in labels))
self.assertIn("return 1", labels)
comments = [node for node in projection.nodes if node.kind == "comment"]
self.assertEqual(len(comments), 1)
self.assertEqual(
comments[0].label,
"Explain the condition. A block comment is trivia too.",
)
self.assertIn("return 1", {node.label for node in projection.nodes})
def test_cpp_function_branches_and_throws(self) -> None:
source = """