diff --git a/tests/analyze/test_analyze_json_go.py b/tests/analyze/test_analyze_json_go.py new file mode 100644 index 0000000..bf78a59 --- /dev/null +++ b/tests/analyze/test_analyze_json_go.py @@ -0,0 +1,60 @@ +import json +import os +from typer.testing import CliRunner +from cli.main import app + +# Setup test runner +runner = CliRunner() + +# Get the absolute path to the sample file +SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.go") + +def test_analyze_command_with_json_flag(): + """Test the analyze command with the --json flag for Go""" + # Run the command with --json flag + result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"]) + + # Check if the command executed successfully + assert result.exit_code == 0 + + # Parse the JSON output + output = json.loads(result.stdout) + + # Check if all expected stats are in the output + assert "file_name" in output + assert "line_count" in output + assert "comment_line_count" in output + assert "function_count" in output + + # Verify the values match expected results + assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH) + assert output["line_count"] == 194 + assert output["comment_line_count"] == 34 + assert output["function_count"] == 15 + +def test_analyze_command_with_all_and_json_flags(): + """Test the analyze command with both --all and --json flags for Go""" + # Run the command with both flags + result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"]) + + # Check if the command executed successfully + assert result.exit_code == 0 + + # Parse the JSON output + output = json.loads(result.stdout) + + # Verify the values match expected results + assert output["line_count"] == 194 + assert output["comment_line_count"] == 34 + assert output["function_count"] == 15 + +def test_analyze_command_with_nonexistent_file(): + """Test the analyze command with a nonexistent file""" + # Run the command with a file that doesn't exist + result = runner.invoke(app, ["analyze", "nonexistent_file.go", "--json"]) + + # Parse the JSON output (should contain an error) + output = json.loads(result.stdout) + + # Check if the output contains an error message + assert "error" in output diff --git a/tests/analyze/test_analyze_json_javascript.py b/tests/analyze/test_analyze_json_javascript.py new file mode 100644 index 0000000..f67eb8a --- /dev/null +++ b/tests/analyze/test_analyze_json_javascript.py @@ -0,0 +1,60 @@ +import json +import os +from typer.testing import CliRunner +from cli.main import app + +# Setup test runner +runner = CliRunner() + +# Get the absolute path to the sample file +SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.js") + +def test_analyze_command_with_json_flag(): + """Test the analyze command with the --json flag for JavaScript""" + # Run the command with --json flag + result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"]) + + # Check if the command executed successfully + assert result.exit_code == 0 + + # Parse the JSON output + output = json.loads(result.stdout) + + # Check if all expected stats are in the output + assert "file_name" in output + assert "line_count" in output + assert "comment_line_count" in output + assert "function_count" in output + + # Verify the values match expected results + assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH) + assert output["line_count"] == 152 + assert output["comment_line_count"] == 23 + assert output["function_count"] == 15 + +def test_analyze_command_with_all_and_json_flags(): + """Test the analyze command with both --all and --json flags for JavaScript""" + # Run the command with both flags + result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"]) + + # Check if the command executed successfully + assert result.exit_code == 0 + + # Parse the JSON output + output = json.loads(result.stdout) + + # Verify the values match expected results + assert output["line_count"] == 152 + assert output["comment_line_count"] == 23 + assert output["function_count"] == 15 + +def test_analyze_command_with_nonexistent_file(): + """Test the analyze command with a nonexistent file""" + # Run the command with a file that doesn't exist + result = runner.invoke(app, ["analyze", "nonexistent_file.js", "--json"]) + + # Parse the JSON output (should contain an error) + output = json.loads(result.stdout) + + # Check if the output contains an error message + assert "error" in output diff --git a/tests/analyze/test_analyze_json_python-example.py b/tests/analyze/test_analyze_json_python.py similarity index 94% rename from tests/analyze/test_analyze_json_python-example.py rename to tests/analyze/test_analyze_json_python.py index 01a72a7..0eb0eae 100644 --- a/tests/analyze/test_analyze_json_python-example.py +++ b/tests/analyze/test_analyze_json_python.py @@ -10,7 +10,7 @@ SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.py") def test_analyze_command_with_json_flag(): - """Test the analyze command with the --json flag""" + """Test the analyze command with the --json flag for Python""" # Run the command with --json flag result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"]) @@ -33,7 +33,7 @@ def test_analyze_command_with_json_flag(): assert output["function_count"] == 17 def test_analyze_command_with_all_and_json_flags(): - """Test the analyze command with both --all and --json flags""" + """Test the analyze command with both --all and --json flags for Python""" # Run the command with both flags result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"]) @@ -57,4 +57,4 @@ def test_analyze_command_with_nonexistent_file(): output = json.loads(result.stdout) # Check if the output contains an error message - assert "error" in output \ No newline at end of file + assert "error" in output diff --git a/tests/analyze/test_analyze_json_ruby.py b/tests/analyze/test_analyze_json_ruby.py new file mode 100644 index 0000000..12319f7 --- /dev/null +++ b/tests/analyze/test_analyze_json_ruby.py @@ -0,0 +1,60 @@ +import json +import os +from typer.testing import CliRunner +from cli.main import app + +# Setup test runner +runner = CliRunner() + +# Get the absolute path to the sample file +SAMPLE_FILE_PATH = os.path.join(os.path.dirname(__file__), "..", "sample-code", "example.rb") + +def test_analyze_command_with_json_flag(): + """Test the analyze command with the --json flag for Ruby""" + # Run the command with --json flag + result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--json"]) + + # Check if the command executed successfully + assert result.exit_code == 0 + + # Parse the JSON output + output = json.loads(result.stdout) + + # Check if all expected stats are in the output + assert "file_name" in output + assert "line_count" in output + assert "comment_line_count" in output + assert "function_count" in output + + # Verify the values match expected results + assert output["file_name"] == os.path.basename(SAMPLE_FILE_PATH) + assert output["line_count"] == 225 + assert output["comment_line_count"] == 50 + assert output["function_count"] == 17 + +def test_analyze_command_with_all_and_json_flags(): + """Test the analyze command with both --all and --json flags for Ruby""" + # Run the command with both flags + result = runner.invoke(app, ["analyze", SAMPLE_FILE_PATH, "--all", "--json"]) + + # Check if the command executed successfully + assert result.exit_code == 0 + + # Parse the JSON output + output = json.loads(result.stdout) + + # Verify the values match expected results + assert output["line_count"] == 225 + assert output["comment_line_count"] == 50 + assert output["function_count"] == 17 + +def test_analyze_command_with_nonexistent_file(): + """Test the analyze command with a nonexistent file""" + # Run the command with a file that doesn't exist + result = runner.invoke(app, ["analyze", "nonexistent_file.rb", "--json"]) + + # Parse the JSON output (should contain an error) + output = json.loads(result.stdout) + + # Check if the output contains an error message + assert "error" in output