From 6fd397627e6a33b7ee4fe227bc38bc4bacd92c49 Mon Sep 17 00:00:00 2001 From: Andrii Rodionov Date: Wed, 13 Nov 2024 12:41:43 +0100 Subject: [PATCH] added additional tests --- .../parser/expressionStatement.test.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/openrewrite/test/javascript/parser/expressionStatement.test.ts b/openrewrite/test/javascript/parser/expressionStatement.test.ts index 6618ded1..814e8be2 100644 --- a/openrewrite/test/javascript/parser/expressionStatement.test.ts +++ b/openrewrite/test/javascript/parser/expressionStatement.test.ts @@ -33,6 +33,15 @@ describe('expression statement mapping', () => { ); }); + test('simple non-null expression with comments', () => { + rewriteRun( + //language=typescript + typeScript(` + const length = /*0*/user/*a*/!/*b*/./*c*/ profile /*d*/!/*e*/ ./*f*/ username /*g*/!/*h*/ ./*j*/ length/*l*/ ; + `) + ); + }); + test('simple question-dot expression', () => { rewriteRun( //language=typescript @@ -42,6 +51,15 @@ describe('expression statement mapping', () => { ); }); + test('simple question-dot expression with comments', () => { + rewriteRun( + //language=typescript + typeScript(` + const length = /*0*/user/*a*/ ?./*b*/ profile/*c*/ ?./*d*/ username /*e*/?./*f*/ length /*g*/; + `) + ); + }); + test('simple default expression', () => { rewriteRun( //language=typescript @@ -51,6 +69,15 @@ describe('expression statement mapping', () => { ); }); + test('simple default expression with comments', () => { + rewriteRun( + //language=typescript + typeScript(` + const length = user /*a*/??/*b*/ 'default' /*c*/; + `) + ); + }); + test('mixed expression with special tokens', () => { rewriteRun( //language=typescript @@ -71,8 +98,8 @@ describe('expression statement mapping', () => { } const user = getUser(1); - const length = user ! . profile ?. username !. length /*test*/ ; - const username2 = getUser(1) ! . profile ?. username ; // test; + const length = user ! . profile ?. username !. length /*test*/ ; + const username2 = getUser(1) ! . profile ?. username ; // test; const username = user!.profile?.username ?? 'Guest' ; `) );