From 87a3ab3ac168a36b0b0f7d7e8bbba0f361c96959 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Wed, 7 Apr 2021 17:03:28 +0500 Subject: [PATCH] test: Added for trimComments --- src/utils/trimComments.spec.ts | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/utils/trimComments.spec.ts diff --git a/src/utils/trimComments.spec.ts b/src/utils/trimComments.spec.ts new file mode 100644 index 0000000..4ede9c3 --- /dev/null +++ b/src/utils/trimComments.spec.ts @@ -0,0 +1,74 @@ +import { trimComments } from './trimComments' + +describe('trimComments', () => { + it('should return statment', () => { + expect( + trimComments(` + /* some comment */ some code; + `) + ).toEqual({ statement: 'some code;', commentStarted: false }) + }) + + it('should return statment, having multi-line comment', () => { + expect( + trimComments(` + /* some + comment */ + some code; + `) + ).toEqual({ statement: 'some code;', commentStarted: false }) + }) + + it('should return statment, having multi-line comment and some code present in comment', () => { + expect( + trimComments(` + /* some + some code; + comment */ + some other code; + `) + ).toEqual({ statement: 'some other code;', commentStarted: false }) + }) + + it('should return empty statment, having only comment', () => { + expect( + trimComments(` + /* some + some code; + comment */ + `) + ).toEqual({ statement: '', commentStarted: false }) + }) + + it('should return empty statment, having continuity in comment', () => { + expect( + trimComments(` + /* some + some code; + `) + ).toEqual({ statement: '', commentStarted: true }) + }) + + it('should return statment, having already started comment and ends', () => { + expect( + trimComments( + ` + comment */ + some code; + `, + true + ) + ).toEqual({ statement: 'some code;', commentStarted: false }) + }) + + it('should return empty statment, having already started comment and continuity in comment', () => { + expect( + trimComments( + ` + some code; + `, + true + ) + ).toEqual({ statement: '', commentStarted: true }) + }) +})