|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Test script to verify the hyphenated folder handling in convert_url_path_to_github_path function. |
| 4 | +Tests the special cases for api-reference, api-routes, custom-components, and wrapping-react folders. |
| 5 | +""" |
| 6 | + |
| 7 | +import sys |
| 8 | +sys.path.append('.') |
| 9 | + |
| 10 | +def test_hyphenated_folders(): |
| 11 | + """Test that hyphenated folder handling works correctly.""" |
| 12 | + try: |
| 13 | + from pcweb.templates.docpage.docpage import convert_url_path_to_github_path |
| 14 | + |
| 15 | + test_cases = [ |
| 16 | + # api-reference: folder keeps hyphens, files use underscores |
| 17 | + ("/docs/api-reference/browser-javascript/", "docs/api-reference/browser_javascript.md"), |
| 18 | + ("/docs/api-reference/event-triggers/", "docs/api-reference/event_triggers.md"), |
| 19 | + ("/docs/api-reference/var-system/", "docs/api-reference/var_system.md"), |
| 20 | + ("/docs/api-reference/cli/", "docs/api-reference/cli.md"), |
| 21 | + |
| 22 | + # api-routes: both folder and files keep hyphens |
| 23 | + ("/docs/api-routes/overview/", "docs/api-routes/overview.md"), |
| 24 | + |
| 25 | + # custom-components: both folder and files keep hyphens |
| 26 | + ("/docs/custom-components/overview/", "docs/custom-components/overview.md"), |
| 27 | + ("/docs/custom-components/command-reference/", "docs/custom-components/command-reference.md"), |
| 28 | + ("/docs/custom-components/prerequisites-for-publishing/", "docs/custom-components/prerequisites-for-publishing.md"), |
| 29 | + |
| 30 | + # wrapping-react: both folder and files keep hyphens |
| 31 | + ("/docs/wrapping-react/overview/", "docs/wrapping-react/overview.md"), |
| 32 | + ("/docs/wrapping-react/custom-code-and-hooks/", "docs/wrapping-react/custom-code-and-hooks.md"), |
| 33 | + ("/docs/wrapping-react/local-packages/", "docs/wrapping-react/local-packages.md"), |
| 34 | + ("/docs/wrapping-react/step-by-step/", "docs/wrapping-react/step-by-step.md"), |
| 35 | + |
| 36 | + # Standard folders: should convert dashes to underscores |
| 37 | + ("/docs/getting-started/introduction/", "docs/getting_started/introduction.md"), |
| 38 | + ("/docs/vars/var-operations/", "docs/vars/var_operations.md"), |
| 39 | + ("/docs/library/forms/button/", "docs/library/forms/button.md"), |
| 40 | + |
| 41 | + # Edge cases with double slashes |
| 42 | + ("//docs/api-reference/browser-javascript/", "docs/api-reference/browser_javascript.md"), |
| 43 | + ("/docs//custom-components/overview/", "docs/custom-components/overview.md"), |
| 44 | + ("/docs/getting-started//introduction/", "docs/getting_started/introduction.md"), |
| 45 | + ] |
| 46 | + |
| 47 | + print("Testing hyphenated folder handling:") |
| 48 | + print("=" * 80) |
| 49 | + |
| 50 | + all_passed = True |
| 51 | + |
| 52 | + for i, (input_path, expected_output) in enumerate(test_cases, 1): |
| 53 | + print(f"\nTest {i:2d}: '{input_path}'") |
| 54 | + |
| 55 | + actual_output = convert_url_path_to_github_path(input_path) |
| 56 | + print(f"Expected: '{expected_output}'") |
| 57 | + print(f"Actual: '{actual_output}'") |
| 58 | + |
| 59 | + full_url = f"https://github.com/reflex-dev/reflex-web/blob/main/{actual_output}" |
| 60 | + print(f"Full URL: '{full_url}'") |
| 61 | + |
| 62 | + has_double_slash = "//" in full_url.replace("https://", "") |
| 63 | + matches_expected = actual_output == expected_output |
| 64 | + |
| 65 | + if matches_expected and not has_double_slash: |
| 66 | + print("✅ PASS") |
| 67 | + else: |
| 68 | + print("❌ FAIL") |
| 69 | + if not matches_expected: |
| 70 | + print(f" Expected '{expected_output}' but got '{actual_output}'") |
| 71 | + if has_double_slash: |
| 72 | + print(f" URL contains double slash: '{full_url}'") |
| 73 | + all_passed = False |
| 74 | + |
| 75 | + print("-" * 60) |
| 76 | + |
| 77 | + print("\n" + "=" * 80) |
| 78 | + if all_passed: |
| 79 | + print("🎉 SUCCESS: All hyphenated folder tests passed!") |
| 80 | + else: |
| 81 | + print("❌ FAILURE: Some hyphenated folder tests failed.") |
| 82 | + |
| 83 | + return all_passed |
| 84 | + |
| 85 | + except Exception as e: |
| 86 | + print(f"❌ Error in hyphenated folder test: {e}") |
| 87 | + import traceback |
| 88 | + traceback.print_exc() |
| 89 | + return False |
| 90 | + |
| 91 | +if __name__ == "__main__": |
| 92 | + success = test_hyphenated_folders() |
| 93 | + exit(0 if success else 1) |
0 commit comments