Skip to content

Commit

Permalink
added additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Rodionov committed Nov 13, 2024
1 parent a55ccda commit 6fd3976
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions openrewrite/test/javascript/parser/expressionStatement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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' ;
`)
);
Expand Down

0 comments on commit 6fd3976

Please sign in to comment.