# HG changeset patch # User Thomas De Schampheleire # Date 1518901148 -3600 # Node ID 9a69885497b5b520bab420077a5039fb5277d72b # Parent f534b213bc9b6072d31be453e05e92690d11cd34 issues: add more tests and restructure Add two test cases using the default issue pattern from the ini file template prior to commit 9cef5615da7b, and some more cases, some of which verify the behavior regarding test cases with mandatory/optional leading whitespace. Increase readability by grouping tests with the same issue pattern, server and prefix, and place the urlified result on a separate line from the input, wrapped in case there are multiple issues in the input. For the result, """ string delimiters are used instead of ' as used in the input, to visually distinguish them better. diff -r f534b213bc9b -r 9a69885497b5 kallithea/tests/other/test_libs.py --- a/kallithea/tests/other/test_libs.py Mon Apr 02 02:11:11 2018 +0200 +++ b/kallithea/tests/other/test_libs.py Sat Feb 17 21:59:08 2018 +0100 @@ -408,21 +408,58 @@ @parametrize('issue_pat,issue_server,issue_prefix,sample,expected', [ (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', - 'issue #123', 'issue #123'), - (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', - 'issue#456', 'issue#456'), + 'issue #123 and issue#456', + """issue #123 and """ + """issue#456"""), + (r'(?:\s*#)(\d+)', 'http://foo/{repo}/issue/{id}', '#', + 'issue #123 and issue#456', + """issue #123 and """ + """issue#456"""), + (r'\bPR(\d+)', 'http://foo/{repo}/issue/{id}', '#', + 'issue PR123 and issuePR456', + """issue #123 and """ + """issuePR456"""), + # following test case shows that \b does not work well in combination with '#': the expectations + # are reversed from what is actually happening. + (r'\b#(\d+)', 'http://foo/{repo}/issue/{id}', '#', + 'issue #123 and issue#456', + """issue #123 and """ + """issue#456"""), + (r'[ \t]#(\d+)', 'http://foo/{repo}/issue/{id}', '#', + 'issue #123 and issue#456', + """issue #123 and """ + """issue#456"""), + (r'(?:pullrequest|pull request|PR|pr) ?#?(\d+)', 'http://foo/{repo}/issue/{id}', 'PR#', + 'fixed with pullrequest #1, pull request#2, PR 3, pr4', + """fixed with PR#1, """ + """PR#2, """ + """PR#3, """ + """PR#4"""), (r'#(\d+)', 'http://foo/{repo}/issue/{id}', 'PR', - 'interesting issue #123', 'interesting issue PR123'), + 'interesting issue #123', + """interesting issue PR123"""), (r'BUG\d{5}', 'https://bar/{repo}/{id}', 'BUG', - 'silly me, I did not parenthesize the {id}, BUG12345.', 'silly me, I did not parenthesize the {id}, BUG.'), + 'silly me, I did not parenthesize the {id}, BUG12345.', + """silly me, I did not parenthesize the {id}, BUG."""), (r'BUG(\d{5})', 'https://bar/{repo}/', 'BUG', - 'silly me, the URL does not contain {id}, BUG12345.', 'silly me, the URL does not contain {id}, BUG12345.'), + 'silly me, the URL does not contain {id}, BUG12345.', + """silly me, the URL does not contain {id}, BUG12345."""), (r'(PR-\d+)', 'http://foo/{repo}/issue/{id}', '', - 'interesting issue #123, err PR-56', 'interesting issue #123, err PR-56'), + 'interesting issue #123, err PR-56', + """interesting issue #123, err PR-56"""), + (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', + "some 'standard' text with apostrophes", + """some 'standard' text with apostrophes"""), (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', - "some 'standard' text with apostrophes", 'some 'standard' text with apostrophes'), + "some 'standard' issue #123", + """some 'standard' issue #123"""), (r'#(\d+)', 'http://foo/{repo}/issue/{id}', '#', - "some 'standard' issue #123", 'some 'standard' issue #123'), + 'an issue #123 with extra whitespace', + """an issue #123 with extra whitespace"""), + # Note: whitespace is squashed + (r'(?:\s*#)(\d+)', 'http://foo/{repo}/issue/{id}', '#', + 'an issue #123 with extra whitespace', + """an issue #123 with extra whitespace"""), ]) def test_urlify_issues(self, issue_pat, issue_server, issue_prefix, sample, expected): from kallithea.lib.helpers import urlify_text