-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_structure.py
More file actions
84 lines (67 loc) · 2.49 KB
/
test_structure.py
File metadata and controls
84 lines (67 loc) · 2.49 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
#!/usr/bin/env python3
"""Simple test to verify the project structure works."""
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
def test_imports():
"""Test that basic imports work."""
try:
# Test basic package import
import regexgen
print(f"✓ Package import works: regexgen v{regexgen.__version__}")
# Test AST module
from regexgen.patterns.ast import PatternAST, LiteralNode
print("✓ PatternAST import works")
# Test basic AST functionality
literal = LiteralNode("test")
ast = PatternAST(literal)
regex_str = ast.to_regex()
print(f"✓ AST functionality works: '{regex_str}'")
# Test complexity calculation
complexity = ast.complexity()
print(f"✓ Complexity calculation works: {complexity}")
return True
except Exception as e:
print(f"✗ Import test failed: {e}")
return False
def test_ast_nodes():
"""Test various AST node types."""
try:
from regexgen.patterns.ast import (
LiteralNode, CharacterClassNode, QuantifierNode,
GroupNode, AlternationNode, WildcardNode
)
# Test literal
lit = LiteralNode("hello")
assert lit.to_regex() == "hello"
print("✓ LiteralNode works")
# Test character class
char_class = CharacterClassNode(characters={'a', 'b', 'c'})
result = char_class.to_regex()
assert '[' in result and ']' in result
print(f"✓ CharacterClassNode works: {result}")
# Test quantifier
quant = QuantifierNode(child=lit, min_count=1, max_count=3)
result = quant.to_regex()
assert '{1,3}' in result
print(f"✓ QuantifierNode works: {result}")
# Test wildcard
wild = WildcardNode()
assert wild.to_regex() == "."
print("✓ WildcardNode works")
return True
except Exception as e:
print(f"✗ AST node test failed: {e}")
return False
if __name__ == "__main__":
print("Testing RegexGenerator project structure...")
print()
success = True
success &= test_imports()
success &= test_ast_nodes()
print()
if success:
print("🎉 All tests passed! Project structure is working correctly.")
else:
print("❌ Some tests failed. Check the errors above.")
sys.exit(1)