Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(pie): update pie tests cases #50

Merged
merged 3 commits into from
May 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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