Group source comments in logic views
This commit is contained in:
parent
6d659ba381
commit
a30f021a52
4 changed files with 67 additions and 13 deletions
|
|
@ -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 = """
|
||||
|
|
|
|||
|
|
@ -499,6 +499,7 @@ if (pruned.prunedCount !== 2) fail("pruned node count");
|
|||
self.assertIn("Structure & containment", javascript)
|
||||
self.assertIn("Inherited & implemented behavior", javascript)
|
||||
self.assertIn("Required dependencies", javascript)
|
||||
self.assertIn('"logic-comment"', javascript)
|
||||
self.assertNotIn(">Children<", html)
|
||||
self.assertIn("distanceShade", javascript)
|
||||
self.assertIn("nodeDisplayName", javascript)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue