Files
regex-humanizer/tests/test_cli.py
7000pctAUTO 74859eb88c
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
fix: resolve CI/CD issues - fixed coverage and ruff paths, removed unused imports
2026-02-02 07:09:39 +00:00

135 lines
4.4 KiB
Python

"""Tests for the CLI module."""
from click.testing import CliRunner
from regex_humanizer.cli import main
class TestCLIMain:
"""Tests for the main CLI command."""
def test_main_help(self):
"""Test that --help works."""
runner = CliRunner()
result = runner.invoke(main, ["--help"])
assert result.exit_code == 0
assert "Regex Humanizer" in result.output
def test_main_version(self):
"""Test that --version works."""
runner = CliRunner()
result = runner.invoke(main, ["--version"])
assert result.exit_code == 0
assert "0.1.0" in result.output
class TestExplainCommand:
"""Tests for the explain command."""
def test_explain_literal(self):
"""Test explaining a literal pattern."""
runner = CliRunner()
result = runner.invoke(main, ["explain", "hello"])
assert result.exit_code == 0
assert "hello" in result.output.lower() or "letter" in result.output.lower()
def test_explain_with_flavor(self):
"""Test explaining with a specific flavor."""
runner = CliRunner()
result = runner.invoke(main, ["explain", "hello", "--flavor", "python"])
assert result.exit_code == 0
assert "hello" in result.output.lower()
def test_explain_verbose(self):
"""Test explaining in verbose mode."""
runner = CliRunner()
result = runner.invoke(main, ["explain", "hello", "--verbose"])
assert result.exit_code == 0
assert "Pattern" in result.output
def test_explain_json(self):
"""Test explaining in JSON format."""
runner = CliRunner()
result = runner.invoke(main, ["explain", "hello", "--json"])
assert result.exit_code == 0
assert "{" in result.output
def test_explain_invalid_pattern(self):
"""Test explaining an invalid pattern."""
runner = CliRunner()
result = runner.invoke(main, ["explain", "[unclosed"])
assert result.exit_code != 0
assert "Error" in result.output
class TestGenerateCommand:
"""Tests for the generate command."""
def test_generate_literal(self):
"""Test generating examples for a literal."""
runner = CliRunner()
result = runner.invoke(main, ["generate", "hello"])
assert result.exit_code == 0
assert "hello" in result.output
def test_generate_with_count(self):
"""Test generating with a specific count."""
runner = CliRunner()
result = runner.invoke(main, ["generate", "a", "--count", "3"])
assert result.exit_code == 0
def test_generate_json(self):
"""Test generating in JSON format."""
runner = CliRunner()
result = runner.invoke(main, ["generate", "hello", "--json"])
assert result.exit_code == 0
assert "{" in result.output
class TestFromEnglishCommand:
"""Tests for the from-english command."""
def test_from_english_basic(self):
"""Test converting basic English to regex."""
runner = CliRunner()
result = runner.invoke(main, ["from-english", "the letter a"])
assert result.exit_code == 0
def test_from_english_with_flavor(self):
"""Test converting with a specific flavor."""
runner = CliRunner()
result = runner.invoke(main, ["from-english", "a digit", "--flavor", "python"])
assert result.exit_code == 0
def test_from_english_json(self):
"""Test converting in JSON format."""
runner = CliRunner()
result = runner.invoke(main, ["from-english", "a digit", "--json"])
assert result.exit_code == 0
assert "{" in result.output
class TestFlavorsCommand:
"""Tests for the flavors command."""
def test_flavors_list(self):
"""Test listing supported flavors."""
runner = CliRunner()
result = runner.invoke(main, ["flavors"])
assert result.exit_code == 0
assert "pcre" in result.output
assert "javascript" in result.output
assert "python" in result.output
assert "go" in result.output
class TestDetectCommand:
"""Tests for the detect command."""
def test_detect_pattern(self):
"""Test detecting pattern flavor."""
runner = CliRunner()
result = runner.invoke(main, ["detect", r"\d+"])
assert result.exit_code == 0
assert "flavor" in result.output.lower()