Skip to content

Commit

Permalink
Merge pull request #324 from weirdan/make-link-params-always-present
Browse files Browse the repository at this point in the history
Make LinkEntry.params to be string, always
  • Loading branch information
weirdan authored Jan 15, 2021
2 parents 246b204 + b6a65e7 commit c66868a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/CommentParser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class CommentParser {
snippets.push({
link: 'https://' + matches[0],
snippet: matches[1],
params: matches[3]
params: matches[3] || ''
});

seen.add(matches[0]);
Expand Down
23 changes: 14 additions & 9 deletions test/CommentParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ describe('CommentParser', () => {
test('returns a link when there is one', () => {
expect(
parser.parseComment('One link: https://psalm.dev/r/0f9f06ebd6')
)
.toEqual([
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6' }
])
).toEqual([
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6', params: '' }
])
})

test('returns all links when there are many', () => {
expect(
parser.parseComment('psalm.dev/r/0f9f06ebd6 and psalm.dev/r/whatever are not the same')
).toEqual([
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6' },
{ link: 'https://psalm.dev/r/whatever', snippet: 'whatever' }
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6', params: '' },
{ link: 'https://psalm.dev/r/whatever', snippet: 'whatever', params: '' }
])
})

Expand All @@ -37,16 +36,16 @@ describe('CommentParser', () => {
expect(
parser.parseComment(comment)
).toEqual([
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6' },
{ link: 'https://psalm.dev/r/whatever', snippet: 'whatever' }
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6', params: '' },
{ link: 'https://psalm.dev/r/whatever', snippet: 'whatever', params: '' }
])
})

test('returns unique links', () => {
expect(
parser.parseComment('https://psalm.dev/r/0f9f06ebd6 and https://psalm.dev/r/0f9f06ebd6 are the same link')
).toEqual([
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6' }
{ link: 'https://psalm.dev/r/0f9f06ebd6', snippet: '0f9f06ebd6', params: '' }
])
})

Expand All @@ -61,4 +60,10 @@ describe('CommentParser', () => {
}
])
})

test('returns empty string as params for links without params', () => {
expect(
parser.parseComment('One link: https://psalm.dev/r/0f9f06ebd6')[0].params
).toEqual('')
})
})

0 comments on commit c66868a

Please sign in to comment.