Make language frontends optional
This commit is contained in:
parent
fee2bb0080
commit
395d732348
4 changed files with 207 additions and 12 deletions
|
|
@ -7,6 +7,8 @@ from docforge.treesitter_logic import (
|
|||
TreeSitterLogicOwner,
|
||||
analyze_cpp_source,
|
||||
analyze_javascript_source,
|
||||
analyze_typescript_source,
|
||||
discover_typescript_functions,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -200,5 +202,44 @@ public:
|
|||
self.assertEqual(missing.exception.code, "missing_logic_owner")
|
||||
|
||||
|
||||
class TypeScriptLogicTests(unittest.TestCase):
|
||||
def test_typed_function_and_method_use_the_typescript_grammar(self) -> None:
|
||||
source = """
|
||||
interface Choice {
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
function choose(choice: Choice): number {
|
||||
if (choice.enabled) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
class Worker {
|
||||
run(choice: Choice): number {
|
||||
return choose(choice);
|
||||
}
|
||||
}
|
||||
""".strip()
|
||||
|
||||
discovered = discover_typescript_functions(source)
|
||||
self.assertEqual(
|
||||
[("Worker.run", 13), ("choose", 5)],
|
||||
[(item.qualified_name, item.line) for item in discovered],
|
||||
)
|
||||
projection = analyze_typescript_source(
|
||||
source,
|
||||
source_id="source.typescript",
|
||||
owners=(TreeSitterLogicOwner("ts.symbol.choose", "choose", 5),),
|
||||
)[0]
|
||||
|
||||
self.assertIn("choice.enabled", {node.label for node in projection.nodes})
|
||||
self.assertEqual(
|
||||
{"return"},
|
||||
{edge.relation for edge in projection.edges if edge.relation == "return"},
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue