-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# tests/test-langauges | ||
|
||
This folder aims to test that the mappings work the for the languages that have mappings |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from typing import Any | ||
|
||
from xyz import abc as efg | ||
|
||
# Example comment | ||
|
||
u = {"x": "y\f"} | ||
v = 5.5 | ||
w = [] | ||
x = 5 | ||
y = int("5") | ||
z = lambda: print | ||
|
||
if x == 5: | ||
x += 5 + x | ||
x -= 5 - x | ||
x *= 2 * x | ||
x /= 2 / x | ||
x **= 2**x | ||
if x is not None: | ||
pass | ||
elif x is None: | ||
pass | ||
else: | ||
pass | ||
|
||
match x: | ||
case 5: | ||
print("Nice") | ||
case _: | ||
print("Woah") | ||
|
||
while 2 in w: | ||
break | ||
if 2 not in w: | ||
pass | ||
|
||
|
||
def decorator(arg) -> Any: | ||
def wrapper(): | ||
return arg() | ||
|
||
return arg | ||
|
||
|
||
@decorator | ||
def example(): | ||
if x > y: | ||
pass | ||
if x >= y: | ||
pass | ||
if x < y: | ||
pass | ||
if x <= y: | ||
pass | ||
... | ||
if x or y: | ||
pass | ||
with open("xyz.foo") as l: | ||
assert False == False | ||
assert True == True | ||
pass | ||
|
||
|
||
class foo: | ||
def break_func(self): | ||
raise Exception("NO") | ||
|
||
|
||
for i in range(x): | ||
continue | ||
|
||
q = {} | {} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
from sys import platform | ||
|
||
from tree_sitter import Language | ||
|
||
from albero import Token, TreeSitterHighlighter, get_lang, get_mapping | ||
|
||
|
||
def test_basic_usage(): | ||
py_lang: Language = get_lang("python") | ||
mapping: dict[str, str] = get_mapping("python") | ||
|
||
highlighter = TreeSitterHighlighter() | ||
|
||
highlighter.add_language("python", py_lang, mapping) | ||
|
||
highlighter.add_file( | ||
"test", "python" | ||
) # Trying to add a file with a language not in the system gives an AlberoException | ||
|
||
highlighter.update_file( | ||
"test", open("tests/test-languages/python_test_file.py").read() | ||
) # Trying to update a file not in the system gives an AlberoException | ||
|
||
tokens: list[Token] = highlighter.get_highlights( | ||
"test" | ||
) # Trying to use a file not in the system gives an AlberoException | ||
|
||
print(tokens) | ||
assert tokens == [ | ||
((1, 0), 4, "Keyword"), | ||
((1, 5), 6, "Name"), | ||
((1, 12), 6, "Keyword"), | ||
((1, 19), 3, "Name"), | ||
((3, 0), 4, "Keyword"), | ||
((3, 5), 3, "Name"), | ||
((3, 9), 6, "Keyword"), | ||
((3, 16), 3, "Name"), | ||
((3, 20), 2, "Keyword"), | ||
((3, 23), 3, "Name"), | ||
((5, 0), 17, "Comment"), | ||
((7, 0), 1, "Name"), | ||
((7, 2), 1, "Operator"), | ||
((7, 4), 1, "Punctuation"), | ||
((7, 5), 3, "String"), | ||
((7, 8), 1, "Punctuation"), | ||
((7, 10), 1, "String"), | ||
((7, 12), 3, "String"), | ||
((7, 15), 1, "Punctuation"), | ||
((8, 0), 1, "Name"), | ||
((8, 2), 1, "Operator"), | ||
((8, 4), 3, "Number"), | ||
((9, 0), 1, "Name"), | ||
((9, 2), 1, "Operator"), | ||
((9, 4), 2, "Punctuation"), | ||
((10, 0), 1, "Name"), | ||
((10, 2), 1, "Operator"), | ||
((10, 4), 1, "Number"), | ||
((11, 0), 1, "Name"), | ||
((11, 2), 1, "Operator"), | ||
((11, 4), 3, "Name"), | ||
((11, 7), 1, "Punctuation"), | ||
((11, 8), 3, "String"), | ||
((11, 11), 1, "Punctuation"), | ||
((12, 0), 1, "Name"), | ||
((12, 2), 1, "Operator"), | ||
((12, 4), 6, "Keyword"), | ||
((12, 10), 1, "Punctuation"), | ||
((12, 12), 5, "Name"), | ||
((14, 0), 2, "Keyword"), | ||
((14, 3), 1, "Name"), | ||
((14, 5), 2, "Operator"), | ||
((14, 8), 1, "Number"), | ||
((14, 9), 1, "Punctuation"), | ||
((15, 4), 1, "Name"), | ||
((15, 6), 2, "Operator"), | ||
((15, 9), 1, "Number"), | ||
((15, 11), 1, "Operator"), | ||
((15, 13), 1, "Name"), | ||
((16, 4), 1, "Name"), | ||
((16, 6), 2, "Operator"), | ||
((16, 9), 1, "Number"), | ||
((16, 11), 1, "Operator"), | ||
((16, 13), 1, "Name"), | ||
((17, 4), 1, "Name"), | ||
((17, 6), 2, "Operator"), | ||
((17, 9), 1, "Number"), | ||
((17, 11), 1, "Operator"), | ||
((17, 13), 1, "Name"), | ||
((18, 4), 1, "Name"), | ||
((18, 6), 2, "Operator"), | ||
((18, 9), 1, "Number"), | ||
((18, 11), 1, "Operator"), | ||
((18, 13), 1, "Name"), | ||
((19, 4), 1, "Name"), | ||
((19, 6), 3, "Operator"), | ||
((19, 10), 1, "Number"), | ||
((19, 11), 2, "Operator"), | ||
((19, 13), 1, "Name"), | ||
((20, 4), 2, "Keyword"), | ||
((20, 7), 1, "Name"), | ||
((20, 9), 2, "Keyword"), | ||
((20, 12), 3, "Keyword"), | ||
((20, 16), 4, "Keyword"), | ||
((20, 20), 1, "Punctuation"), | ||
((21, 8), 4, "Keyword"), | ||
((22, 4), 4, "Keyword"), | ||
((22, 9), 1, "Name"), | ||
((22, 11), 2, "Keyword"), | ||
((22, 14), 4, "Keyword"), | ||
((22, 18), 1, "Punctuation"), | ||
((23, 8), 4, "Keyword"), | ||
((24, 4), 4, "Keyword"), | ||
((24, 8), 1, "Punctuation"), | ||
((25, 8), 4, "Keyword"), | ||
((27, 0), 5, "Keyword"), | ||
((27, 6), 1, "Name"), | ||
((27, 7), 1, "Punctuation"), | ||
((28, 4), 4, "Keyword"), | ||
((28, 9), 1, "Number"), | ||
((28, 10), 1, "Punctuation"), | ||
((29, 8), 5, "Name"), | ||
((29, 13), 1, "Punctuation"), | ||
((29, 14), 6, "String"), | ||
((29, 20), 1, "Punctuation"), | ||
((30, 4), 4, "Keyword"), | ||
((30, 9), 1, "Keyword"), | ||
((30, 10), 1, "Punctuation"), | ||
((31, 8), 5, "Name"), | ||
((31, 13), 1, "Punctuation"), | ||
((31, 14), 6, "String"), | ||
((31, 20), 1, "Punctuation"), | ||
((33, 0), 5, "Keyword"), | ||
((33, 6), 1, "Number"), | ||
((33, 8), 2, "Keyword"), | ||
((33, 11), 1, "Name"), | ||
((33, 12), 1, "Punctuation"), | ||
((34, 4), 5, "Keyword"), | ||
((35, 0), 2, "Keyword"), | ||
((35, 3), 1, "Number"), | ||
((35, 5), 3, "Keyword"), | ||
((35, 9), 2, "Keyword"), | ||
((35, 12), 1, "Name"), | ||
((35, 13), 1, "Punctuation"), | ||
((36, 4), 4, "Keyword"), | ||
((39, 0), 3, "Keyword"), | ||
((39, 4), 9, "Name"), | ||
((39, 13), 1, "Punctuation"), | ||
((39, 14), 3, "Name"), | ||
((39, 17), 1, "Punctuation"), | ||
((39, 19), 2, "Operator"), | ||
((39, 22), 3, "Name"), | ||
((39, 25), 1, "Punctuation"), | ||
((40, 4), 3, "Keyword"), | ||
((40, 8), 7, "Name"), | ||
((40, 15), 3, "Punctuation"), | ||
((41, 8), 6, "Keyword"), | ||
((41, 15), 3, "Name"), | ||
((41, 18), 2, "Punctuation"), | ||
((43, 4), 6, "Keyword"), | ||
((43, 11), 3, "Name"), | ||
((46, 0), 10, "Name"), | ||
((47, 0), 3, "Keyword"), | ||
((47, 4), 7, "Name"), | ||
((47, 11), 3, "Punctuation"), | ||
((48, 4), 2, "Keyword"), | ||
((48, 7), 1, "Name"), | ||
((48, 9), 1, "Operator"), | ||
((48, 11), 1, "Name"), | ||
((48, 12), 1, "Punctuation"), | ||
((49, 8), 4, "Keyword"), | ||
((50, 4), 2, "Keyword"), | ||
((50, 7), 1, "Name"), | ||
((50, 9), 2, "Operator"), | ||
((50, 12), 1, "Name"), | ||
((50, 13), 1, "Punctuation"), | ||
((51, 8), 4, "Keyword"), | ||
((52, 4), 2, "Keyword"), | ||
((52, 7), 1, "Name"), | ||
((52, 9), 1, "Operator"), | ||
((52, 11), 1, "Name"), | ||
((52, 12), 1, "Punctuation"), | ||
((53, 8), 4, "Keyword"), | ||
((54, 4), 2, "Keyword"), | ||
((54, 7), 1, "Name"), | ||
((54, 9), 2, "Operator"), | ||
((54, 12), 1, "Name"), | ||
((54, 13), 1, "Punctuation"), | ||
((55, 8), 4, "Keyword"), | ||
((56, 4), 3, "Operator"), | ||
((57, 4), 2, "Keyword"), | ||
((57, 7), 1, "Name"), | ||
((57, 9), 2, "Operator"), | ||
((57, 12), 1, "Name"), | ||
((57, 13), 1, "Punctuation"), | ||
((58, 8), 4, "Keyword"), | ||
((59, 9), 4, "Name"), | ||
((59, 13), 1, "Punctuation"), | ||
((59, 14), 9, "String"), | ||
((59, 23), 1, "Punctuation"), | ||
((59, 25), 2, "Keyword"), | ||
((59, 28), 1, "Name"), | ||
((59, 29), 1, "Punctuation"), | ||
((60, 15), 5, "Keyword"), | ||
((60, 21), 2, "Operator"), | ||
((60, 24), 5, "Keyword"), | ||
((61, 15), 4, "Keyword"), | ||
((61, 20), 2, "Operator"), | ||
((61, 23), 4, "Keyword"), | ||
((62, 8), 4, "Keyword"), | ||
((65, 0), 5, "Keyword"), | ||
((65, 6), 3, "Name"), | ||
((65, 9), 1, "Punctuation"), | ||
((66, 4), 3, "Keyword"), | ||
((66, 8), 10, "Name"), | ||
((66, 18), 1, "Punctuation"), | ||
((66, 19), 4, "Name"), | ||
((66, 23), 2, "Punctuation"), | ||
((67, 8), 5, "Keyword"), | ||
((67, 14), 9, "Name"), | ||
((67, 23), 1, "Punctuation"), | ||
((67, 24), 4, "String"), | ||
((67, 28), 1, "Punctuation"), | ||
((70, 0), 3, "Keyword"), | ||
((70, 4), 1, "Name"), | ||
((70, 6), 2, "Keyword"), | ||
((70, 9), 5, "Name"), | ||
((70, 14), 1, "Punctuation"), | ||
((70, 15), 1, "Name"), | ||
((70, 16), 2, "Punctuation"), | ||
((71, 4), 8, "Keyword"), | ||
((73, 0), 1, "Name"), | ||
((73, 2), 1, "Operator"), | ||
((73, 4), 2, "Punctuation"), | ||
((73, 7), 1, "Operator"), | ||
((73, 9), 2, "Punctuation"), | ||
] |