Add test files
This commit is contained in:
81
tests/test_flavors.py
Normal file
81
tests/test_flavors.py
Normal file
@@ -0,0 +1,81 @@
|
||||
"""Tests for the flavors module."""
|
||||
|
||||
import pytest
|
||||
|
||||
from regex_humanizer.flavors import (
|
||||
get_flavor,
|
||||
get_supported_flavors,
|
||||
validate_flavor,
|
||||
detect_flavor,
|
||||
check_feature_support,
|
||||
get_compatibility_warnings,
|
||||
)
|
||||
|
||||
|
||||
class TestFlavorRegistry:
|
||||
def test_list_flavors(self):
|
||||
flavors = get_supported_flavors()
|
||||
assert "pcre" in flavors
|
||||
assert "javascript" in flavors
|
||||
assert "python" in flavors
|
||||
assert "go" in flavors
|
||||
|
||||
def test_get_flavor(self):
|
||||
flavor = get_flavor("pcre")
|
||||
assert flavor is not None
|
||||
assert flavor.name == "pcre"
|
||||
|
||||
def test_validate_flavor_valid(self):
|
||||
assert validate_flavor("pcre") is True
|
||||
assert validate_flavor("javascript") is True
|
||||
|
||||
|
||||
class TestDetectFlavor:
|
||||
def test_detect_pcre_features(self):
|
||||
flavor = detect_flavor(r"(?P<name>pattern)\k<name>")
|
||||
assert flavor == "pcre"
|
||||
|
||||
def test_detect_js_lookahead(self):
|
||||
flavor = detect_flavor(r"(?=pattern)")
|
||||
assert flavor in ("javascript", "pcre")
|
||||
|
||||
def test_detect_possessive_quantifiers(self):
|
||||
flavor = detect_flavor(r"a++")
|
||||
assert flavor == "pcre"
|
||||
|
||||
|
||||
class TestFeatureSupport:
|
||||
def test_check_js_lookbehind(self):
|
||||
pattern = r"(?<=pattern)"
|
||||
unsupported = check_feature_support(pattern, "javascript")
|
||||
assert "lookbehind" in unsupported
|
||||
|
||||
def test_check_go_lookbehind(self):
|
||||
pattern = r"(?<=pattern)"
|
||||
unsupported = check_feature_support(pattern, "go")
|
||||
assert "lookbehind" in unsupported
|
||||
|
||||
def test_check_js_possessive(self):
|
||||
pattern = r"a++"
|
||||
unsupported = check_feature_support(pattern, "javascript")
|
||||
assert "possessive_quantifiers" in unsupported
|
||||
|
||||
|
||||
class TestCompatibilityWarnings:
|
||||
def test_js_lookbehind_warning(self):
|
||||
pattern = r"(?<=pattern)"
|
||||
warnings = get_compatibility_warnings(pattern, "javascript")
|
||||
assert len(warnings) > 0
|
||||
warning_types = [w.feature for w in warnings]
|
||||
assert "lookbehind" in warning_types
|
||||
|
||||
def test_go_backreference_warning(self):
|
||||
pattern = r"\k<name>"
|
||||
warnings = get_compatibility_warnings(pattern, "go")
|
||||
warning_types = [w.feature for w in warnings]
|
||||
assert "named_groups" in warning_types or "backreferences_general" in warning_types
|
||||
|
||||
def test_pcre_no_warnings(self):
|
||||
pattern = r"\w+"
|
||||
warnings = get_compatibility_warnings(pattern, "pcre")
|
||||
assert len(warnings) == 0
|
||||
Reference in New Issue
Block a user