|
5 | 5 |
|
6 | 6 | import { default as assert } from 'assert'; |
7 | 7 | import * as vscode from 'vscode'; |
8 | | -import { fromOpenOrCheckoutPullRequestWebviewUri } from '../../common/uri'; |
| 8 | +import { convertIssuePRReferencesToLinks, fromOpenOrCheckoutPullRequestWebviewUri } from '../../common/uri'; |
9 | 9 |
|
10 | 10 | describe('uri', () => { |
11 | 11 | describe('fromOpenOrCheckoutPullRequestWebviewUri', () => { |
@@ -110,4 +110,75 @@ describe('uri', () => { |
110 | 110 | assert.strictEqual(result2, undefined); |
111 | 111 | }); |
112 | 112 | }); |
| 113 | + |
| 114 | + describe('convertIssuePRReferencesToLinks', () => { |
| 115 | + const owner = 'microsoft'; |
| 116 | + const repo = 'vscode-pull-request-github'; |
| 117 | + |
| 118 | + it('should convert standalone issue numbers with # prefix', () => { |
| 119 | + const text = 'This PR addresses issue #7280.'; |
| 120 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 121 | + assert.strictEqual(result, 'This PR addresses issue [#7280](https://github.com/microsoft/vscode-pull-request-github/issues/7280).'); |
| 122 | + }); |
| 123 | + |
| 124 | + it('should convert issue references without # prefix', () => { |
| 125 | + const text = 'This fixes issue 123.'; |
| 126 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 127 | + assert.strictEqual(result, 'This fixes [issue 123](https://github.com/microsoft/vscode-pull-request-github/issues/123).'); |
| 128 | + }); |
| 129 | + |
| 130 | + it('should convert PR references with # prefix', () => { |
| 131 | + const text = 'See PR #456 for details.'; |
| 132 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 133 | + assert.strictEqual(result, 'See [PR #456](https://github.com/microsoft/vscode-pull-request-github/issues/456) for details.'); |
| 134 | + }); |
| 135 | + |
| 136 | + it('should convert PR references without # prefix', () => { |
| 137 | + const text = 'Related to PR 789.'; |
| 138 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 139 | + assert.strictEqual(result, 'Related to [PR 789](https://github.com/microsoft/vscode-pull-request-github/issues/789).'); |
| 140 | + }); |
| 141 | + |
| 142 | + it('should convert multiple issue/PR references in the same text', () => { |
| 143 | + const text = 'This fixes issue #123 and PR #456.'; |
| 144 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 145 | + assert.strictEqual(result, 'This fixes [issue #123](https://github.com/microsoft/vscode-pull-request-github/issues/123) and [PR #456](https://github.com/microsoft/vscode-pull-request-github/issues/456).'); |
| 146 | + }); |
| 147 | + |
| 148 | + it('should handle case-insensitive issue/PR keywords', () => { |
| 149 | + const text = 'See Issue #100 and pr #200.'; |
| 150 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 151 | + assert.strictEqual(result, 'See [Issue #100](https://github.com/microsoft/vscode-pull-request-github/issues/100) and [pr #200](https://github.com/microsoft/vscode-pull-request-github/issues/200).'); |
| 152 | + }); |
| 153 | + |
| 154 | + it('should not convert issue/PR references in the middle of words', () => { |
| 155 | + const text = 'This is not#123 an issue.'; |
| 156 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 157 | + assert.strictEqual(result, 'This is not#123 an issue.'); |
| 158 | + }); |
| 159 | + |
| 160 | + it('should not convert # followed by non-numeric characters', () => { |
| 161 | + const text = 'This is #notanissue.'; |
| 162 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 163 | + assert.strictEqual(result, 'This is #notanissue.'); |
| 164 | + }); |
| 165 | + |
| 166 | + it('should convert standalone # followed by number', () => { |
| 167 | + const text = 'See #42 for more info.'; |
| 168 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 169 | + assert.strictEqual(result, 'See [#42](https://github.com/microsoft/vscode-pull-request-github/issues/42) for more info.'); |
| 170 | + }); |
| 171 | + |
| 172 | + it('should handle text with no issue/PR references', () => { |
| 173 | + const text = 'This is just regular text.'; |
| 174 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 175 | + assert.strictEqual(result, 'This is just regular text.'); |
| 176 | + }); |
| 177 | + |
| 178 | + it('should handle empty text', () => { |
| 179 | + const text = ''; |
| 180 | + const result = convertIssuePRReferencesToLinks(text, owner, repo); |
| 181 | + assert.strictEqual(result, ''); |
| 182 | + }); |
| 183 | + }); |
113 | 184 | }); |
0 commit comments