Skip to content

Commit

Permalink
test(pie): update pie tests cases (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Yokozuna59 <u.yokozuna@gmail.com>
  • Loading branch information
Yokozuna59 authored May 21, 2023
1 parent d542449 commit ef714c0
Showing 1 changed file with 126 additions and 6 deletions.
132 changes: 126 additions & 6 deletions packages/mermaid-parser/tests/pie/syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
PieChart,
} from '../../src/language';

describe('valid pie chart codes', () => {
describe('when parsing pie chart', () => {
let parser: (input: string) => Promise<LangiumDocument<Mermaid>>;

beforeAll(async () => {
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('valid pie chart codes', () => {
\tpie
`,
])('should handle valid pie definitions', async (str: string) => {
])('should handle valid pie', async (str: string) => {
const result = (await parser(str)).parseResult;
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);
Expand Down Expand Up @@ -69,18 +69,138 @@ describe('valid pie chart codes', () => {
pie\tshowData
`,
])('should handle valid pie + showData', async (str: string) => {
const result = (await parser(str)).parseResult;
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.$type).toBe(PieChart);
expect(value.showData).toBeTruthy();
expect(value.title).toBeUndefined();
expect(value.sections).toHaveLength(0);
});

// pie + title
it.each([
// without whitespaces
`pie title sample title`,

// with spaces
` pie title sample title `,

// with tabs
`\tpie\ttitle sample title\t`,

// with extra whitespaces
`pie
\ttitle sample title
`,
])('should handle valid pie + title in same line', async (str: string) => {
const result = (await parser(str)).parseResult;
// expect(result.parserErrors).toHaveLength(0);
// expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.$type).toBe(PieChart);
expect(value.showData).toBeFalsy();
expect(value.title).toBe('sample title');
expect(value.sections).toHaveLength(0);
});

// pie + \n + title
it.each([
// without newlines
`pie
title sample title`,

// extra newline after
`pie
title sample title
`,

// extra newline before
`pie
title sample title`,

// extra newlines
`pie
title sample title
`,
])(
'should handle valid pie + title in different line',
async (str: string) => {
const result = (await parser(str)).parseResult;
// expect(result.parserErrors).toHaveLength(0);
// expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.$type).toBe(PieChart);
expect(value.showData).toBeFalsy();
expect(value.title).toBe('sample title');
expect(value.sections).toHaveLength(0);
},
);

// pie + showData + title
it.each([
// without newlines
`pie showData title sample title`,

// extra newline after
`pie showData title sample title
`,
])('should handle valid pie + showData + title', async (str: string) => {
const result = (await parser(str)).parseResult;
// expect(result.parserErrors).toHaveLength(0);
// expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.$type).toBe(PieChart);
expect(value.showData).toBeTruthy();
expect(value.title).toBe('sample title');
expect(value.sections).toHaveLength(0);
});

// pie + showData + \n + title
it.each([
// without newlines
`pie showData
title sample title`,

// extra newline after
`pie showData
title sample title
`,

// extra newline before
`pie showData
title sample title`,

// extra newlines
`pie showData
title sample title
`,
])(
'should handle valid pie + showData definitions',
'should handle valid pie + showData + title in different line',
async (str: string) => {
const result = (await parser(str)).parseResult;
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);
// expect(result.parserErrors).toHaveLength(0);
// expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.$type).toBe(PieChart);
expect(value.showData).toBeTruthy();
expect(value.title).toBeUndefined();
expect(value.title).toBe('sample title');
expect(value.sections).toHaveLength(0);
},
);
Expand Down

0 comments on commit ef714c0

Please sign in to comment.