forked from grantjenks/py-tree-sitter-languages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tree_sitter_languages.py
90 lines (80 loc) · 1.59 KB
/
test_tree_sitter_languages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from tree_sitter_languages import get_language, get_parser
LANGUAGES = [
"bash",
"c",
"c_sharp", # c-sharp
"commonlisp",
"cpp",
"css",
"dockerfile",
"dot",
"elisp",
"elixir",
"elm",
"embedded_template", # embedded-template
"erlang",
"fixed_form_fortran",
"fortran",
"go",
"gomod", # go-mod
"hack",
"haskell",
"hcl",
"html",
"java",
"javascript",
"jsdoc",
"json",
"julia",
"kotlin",
"lua",
"make",
"markdown",
"objc",
"ocaml",
"php",
"python",
"ql",
"r",
"regex",
"rst",
"ruby",
"rust",
"scala",
"sql",
"sqlite",
"toml",
"tsq",
"typescript",
"yaml",
]
PYTHON_CODE = """
def foo():
if bar:
baz()
""".encode()
PYTHON_QUERY = """
(function_definition
name: (identifier) @function.def)
(call
function: (identifier) @function.call)
"""
def test_python():
language = get_language("python")
query = language.query(PYTHON_QUERY)
parser = get_parser("python")
tree = parser.parse(PYTHON_CODE)
captures = query.captures(tree.root_node)
assert len(captures) == 2
assert captures[0][1] == "function.def"
assert captures[0][0].text.decode() == "foo"
assert captures[1][1] == "function.call"
assert captures[1][0].text.decode() == "baz"
def test_get_parser():
for language in LANGUAGES:
parser = get_parser(language)
assert parser
def test_get_language():
for language in LANGUAGES:
language = get_language(language)
assert language