Skip to content

Commit fb307c2

Browse files
committed
Adds more test cases for commentsAbove in analyzer
1 parent dae023f commit fb307c2

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,28 @@ describe('commentsAbove', () => {
196196
it('returns a string of a comment block above a line', () => {
197197
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
198198
expect(analyzer.commentsAbove(CURRENT_URI, 22)).toEqual('doc for func_one')
199+
})
199200

201+
it('handles line breaks in comments', () => {
202+
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
200203
expect(analyzer.commentsAbove(CURRENT_URI, 28)).toEqual(
201-
'doc for func_two\nhas two lines',
204+
'doc for func_two\nhas two lines',
202205
)
206+
})
207+
208+
it('only returns connected comments', () => {
209+
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
210+
expect(analyzer.commentsAbove(CURRENT_URI, 36)).toEqual('doc for func_three')
211+
})
203212

204-
// if there is a line break in the comments
205-
// it should not include the above comment
206-
expect(analyzer.commentsAbove(CURRENT_URI, 36)).not.toMatch('this is not included')
213+
it('returns null if no comment found', () => {
214+
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
215+
expect(analyzer.commentsAbove(CURRENT_URI, 45)).toEqual(null)
216+
})
217+
218+
it('works for variables', () => {
219+
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
220+
expect(analyzer.commentsAbove(CURRENT_URI, 42)).toEqual('works for variables')
207221
})
208222
})
209223

testing/fixtures/comment-doc-on-hover.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ func_two() {
3737
func_three() {
3838
echo "func_three"
3939
}
40+
41+
42+
# works for variables
43+
my_var="pizza"
44+
45+
46+
my_other_var="no comments above me :("
47+

0 commit comments

Comments
 (0)