diff --git a/tests/test_cli.py b/tests/test_cli.py index e98e56f..8db6065 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,20 +1,22 @@ """Tests for the CLI module.""" -import json -import pytest 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 @@ -22,44 +24,62 @@ class TestCLIMain: 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 @@ -67,28 +87,47 @@ class TestGenerateCommand: 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