#!/bin/bash

set -e

echo "Testing Homebrew formula locally..."

if ! brew tap | grep -q "goldziher/tap"; then
	echo "Adding local tap..."
	brew tap goldziher/tap "$(pwd)/homebrew-tap"
else
	echo "Tap already exists, updating..."
	brew untap goldziher/tap
	brew tap goldziher/tap "$(pwd)/homebrew-tap"
fi

echo "Installing uncomment from local tap..."
brew install --verbose goldziher/tap/uncomment

echo "Testing uncomment command..."
uncomment --version

cat >/tmp/test_uncomment.py <<'EOF'
# This is a comment
def hello():
    print("Hello, world!")  # Inline comment
    # Another comment
    return True
EOF

echo "Running uncomment on test file..."
uncomment --dry-run /tmp/test_uncomment.py

echo "✅ Homebrew formula test completed successfully!"

echo "Cleaning up..."
brew uninstall uncomment
brew untap goldziher/tap
