Skip to content

Commit c66868a

Browse files
authored
Merge pull request #324 from weirdan/make-link-params-always-present
Make LinkEntry.params to be string, always
2 parents 246b204 + b6a65e7 commit c66868a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/CommentParser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class CommentParser {
1414
snippets.push({
1515
link: 'https://' + matches[0],
1616
snippet: matches[1],
17-
params: matches[3]
17+
params: matches[3] || ''
1818
});
1919

2020
seen.add(matches[0]);

test/CommentParser.test.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ describe('CommentParser', () => {
1414
test('returns a link when there is one', () => {
1515
expect(
1616
parser.parseComment('One link: https://psalm.dev/r/0f9f06ebd6')
17-
)
18-
.toEqual([
19-
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6' }
20-
])
17+
).toEqual([
18+
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6', params: '' }
19+
])
2120
})
2221

2322
test('returns all links when there are many', () => {
2423
expect(
2524
parser.parseComment('psalm.dev/r/0f9f06ebd6 and psalm.dev/r/whatever are not the same')
2625
).toEqual([
27-
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6' },
28-
{ link: 'https://psalm.dev/r/whatever', snippet: 'whatever' }
26+
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6', params: '' },
27+
{ link: 'https://psalm.dev/r/whatever', snippet: 'whatever', params: '' }
2928
])
3029
})
3130

@@ -37,16 +36,16 @@ describe('CommentParser', () => {
3736
expect(
3837
parser.parseComment(comment)
3938
).toEqual([
40-
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6' },
41-
{ link: 'https://psalm.dev/r/whatever', snippet: 'whatever' }
39+
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6', params: '' },
40+
{ link: 'https://psalm.dev/r/whatever', snippet: 'whatever', params: '' }
4241
])
4342
})
4443

4544
test('returns unique links', () => {
4645
expect(
4746
parser.parseComment('https://psalm.dev/r/0f9f06ebd6 and https://psalm.dev/r/0f9f06ebd6 are the same link')
4847
).toEqual([
49-
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6' }
48+
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6', params: '' }
5049
])
5150
})
5251

@@ -61,4 +60,10 @@ describe('CommentParser', () => {
6160
}
6261
])
6362
})
63+
64+
test('returns empty string as params for links without params', () => {
65+
expect(
66+
parser.parseComment('One link: https://psalm.dev/r/0f9f06ebd6')[0].params
67+
).toEqual('')
68+
})
6469
})

0 commit comments

Comments
 (0)