|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import sys |
| 4 | +import os |
| 5 | +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) |
| 6 | + |
| 7 | +from parse_sdk_branch import parse_sdk_branch |
| 8 | + |
| 9 | + |
| 10 | +def test_parse_sdk_branch(): |
| 11 | + test_cases = [ |
| 12 | + # Basic cases |
| 13 | + ("TESTING_SDK_BRANCH = feature/test", "feature/test"), |
| 14 | + ("TESTING_SDK_BRANCH: feature/test", "feature/test"), |
| 15 | + ("TESTING_SDK_BRANCH=feature/test", "feature/test"), |
| 16 | + ("testing_sdk_branch: feature/test", "feature/test"), |
| 17 | + |
| 18 | + # Complex PR body with backticks and contractions |
| 19 | + ("""Updated the script to safely parse the testing SDK branch from the PR body, handling case insensitivity and whitespace. |
| 20 | +
|
| 21 | +The goal here is to fix the usage of backticks such as in `foo`, and contractions that we've been using such as `we've` |
| 22 | +
|
| 23 | +``` |
| 24 | +plus of course the usage of multiple backticks to include code |
| 25 | +``` |
| 26 | +
|
| 27 | +TESTING_SDK_BRANCH = main |
| 28 | +
|
| 29 | +By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.""", "main"), |
| 30 | + |
| 31 | + # Edge cases with markdown and special characters |
| 32 | + ("""# PR Title |
| 33 | + |
| 34 | +Some `code` and we've got contractions here. |
| 35 | +
|
| 36 | +```python |
| 37 | +def test(): |
| 38 | + return "test" |
| 39 | +``` |
| 40 | +
|
| 41 | +TESTING_SDK_BRANCH: feature/fix-backticks |
| 42 | +
|
| 43 | +More text with `inline code` and don't forget contractions.""", "feature/fix-backticks"), |
| 44 | + |
| 45 | + # Multiple occurrences (should take first) |
| 46 | + ("""TESTING_SDK_BRANCH = first-branch |
| 47 | + |
| 48 | +Some text here. |
| 49 | +
|
| 50 | +TESTING_SDK_BRANCH = second-branch""", "first-branch"), |
| 51 | + |
| 52 | + # Whitespace variations |
| 53 | + (" TESTING_SDK_BRANCH = feature/spaces ", "feature/spaces"), |
| 54 | + ("TESTING_SDK_BRANCH:feature/no-space", "feature/no-space"), |
| 55 | + |
| 56 | + # Default cases |
| 57 | + ("No branch specified", "main"), |
| 58 | + ("", "main"), |
| 59 | + ("Just some random text", "main"), |
| 60 | + |
| 61 | + # Case with backticks in branch name |
| 62 | + ("TESTING_SDK_BRANCH = feature/fix-`backticks`", "feature/fix-`backticks`"), |
| 63 | + |
| 64 | + # Case with contractions in surrounding text |
| 65 | + ("We've updated this and TESTING_SDK_BRANCH = feature/test and we're done", "feature/test"), |
| 66 | + ] |
| 67 | + |
| 68 | + for i, (input_text, expected) in enumerate(test_cases): |
| 69 | + result = parse_sdk_branch(input_text) |
| 70 | + if result != expected: |
| 71 | + print(f"FAIL Test {i+1}: Expected '{expected}', got '{result}'") |
| 72 | + print(f"Input: {repr(input_text[:100])}...") |
| 73 | + return False |
| 74 | + else: |
| 75 | + print(f"PASS Test {i+1}: {expected}") |
| 76 | + |
| 77 | + print(f"\nAll {len(test_cases)} tests passed!") |
| 78 | + return True |
| 79 | + |
| 80 | + |
| 81 | +if __name__ == "__main__": |
| 82 | + success = test_parse_sdk_branch() |
| 83 | + sys.exit(0 if success else 1) |
0 commit comments