Ignore comments in Tree-sitter logic graphs
This commit is contained in:
parent
9161889492
commit
6d659ba381
2 changed files with 46 additions and 0 deletions
|
|
@ -11,6 +11,27 @@ from docforge.treesitter_logic import (
|
|||
|
||||
|
||||
class JavaScriptLogicTests(unittest.TestCase):
|
||||
def test_comments_do_not_become_logic_actions(self) -> None:
|
||||
source = """
|
||||
function choose(enabled) {
|
||||
// Explain the condition.
|
||||
// Continue the explanation.
|
||||
/* A block comment is trivia too. */
|
||||
if (enabled) {
|
||||
accept();
|
||||
}
|
||||
}
|
||||
""".strip()
|
||||
projection = analyze_javascript_source(
|
||||
source,
|
||||
source_id="source.javascript",
|
||||
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)
|
||||
|
||||
def test_branches_short_circuit_and_converge(self) -> None:
|
||||
source = """
|
||||
function choose(enabled, ready) {
|
||||
|
|
@ -90,6 +111,27 @@ function process(items, mode) {
|
|||
|
||||
|
||||
class CppLogicTests(unittest.TestCase):
|
||||
def test_comments_do_not_become_logic_actions(self) -> None:
|
||||
source = """
|
||||
int choose(bool enabled) {
|
||||
// Explain the condition.
|
||||
/* A block comment is trivia too. */
|
||||
if (enabled) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
""".strip()
|
||||
projection = analyze_cpp_source(
|
||||
source,
|
||||
source_id="source.cpp",
|
||||
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)
|
||||
|
||||
def test_cpp_function_branches_and_throws(self) -> None:
|
||||
source = """
|
||||
int choose(bool enabled) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue