-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_python.py
More file actions
100 lines (85 loc) · 2.13 KB
/
test_python.py
File metadata and controls
100 lines (85 loc) · 2.13 KB
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
91
92
93
94
95
96
97
98
99
100
# TreeSitterLexer PoC Test File
# This file tests Python syntax highlighting via tree-sitter
import os
import sys
from collections import defaultdict
# Constants
MAX_RETRIES = 3
PI = 3.14159
DEBUG = True
class DataProcessor:
"""A sample class for testing tree-sitter highlighting."""
def __init__(self, name: str, count: int = 0):
self.name = name
self.count = count
self._cache = {}
def process(self, data: list) -> dict:
"""Process the input data and return results."""
result = {}
for i, item in enumerate(data):
if item is None:
continue
elif isinstance(item, str):
result[item] = len(item)
else:
result[str(item)] = item * 2
return result
@staticmethod
def validate(value):
if not value:
raise ValueError("Value cannot be empty")
return True
async def fetch_data(url: str) -> bytes:
"""Async function for testing coroutine highlighting."""
try:
response = await some_http_lib.get(url)
return response.content
except Exception as e:
print(f"Error fetching {url}: {e}")
return b""
# Builtin function calls
numbers = list(range(10))
total = sum(numbers)
filtered = filter(lambda x: x > 5, numbers)
mapped = map(str, numbers)
# Various literals
name = "hello world"
raw = r"raw\nstring"
multiline = """
This is a
multiline string
"""
byte_str = b"bytes"
fstring = f"Result: {total + 1}"
hex_num = 0xFF
oct_num = 0o77
bin_num = 0b1010
float_num = 1.5e-3
complex_num = 3 + 4j
# Control flow
for x in range(10):
if x % 2 == 0:
print(x)
elif x == 7:
break
else:
continue
while True:
pass
# Pattern matching (Python 3.10+)
match total:
case 0:
print("zero")
case n if n > 0:
print(f"positive: {n}")
# Boolean and None
flag = True
other = False
nothing = None
if flag is not None and flag is True:
print("flag is set")
# Operators
result = (10 + 20) * 3 // 4
bitwise = 0xFF & 0x0F | 0x10 ^ 0x01
shifted = 1 << 4
comparison = 10 >= 5 and 3 <= 7 or not False