Skip to content

Commit

Permalink
make pie parser async
Browse files Browse the repository at this point in the history
  • Loading branch information
Yokozuna59 committed Jan 27, 2024
1 parent 72a6fad commit c291e0b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions packages/mermaid/src/diagrams/pie/pie.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ describe('pie', () => {
beforeEach(() => db.clear());

describe('parse', () => {
it('should handle very simple pie', () => {
parser.parse(`pie
it('should handle very simple pie', async () => {
await parser.parse(`pie
"ash": 100
`);

const sections = db.getSections();
expect(sections['ash']).toBe(100);
});

it('should handle simple pie', () => {
parser.parse(`pie
it('should handle simple pie', async () => {
await parser.parse(`pie
"ash" : 60
"bat" : 40
`);
Expand All @@ -30,8 +30,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with showData', () => {
parser.parse(`pie showData
it('should handle simple pie with showData', async () => {
await parser.parse(`pie showData
"ash" : 60
"bat" : 40
`);
Expand All @@ -43,8 +43,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with comments', () => {
parser.parse(`pie
it('should handle simple pie with comments', async () => {
await parser.parse(`pie
%% comments
"ash" : 60
"bat" : 40
Expand All @@ -55,8 +55,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with a title', () => {
parser.parse(`pie title a 60/40 pie
it('should handle simple pie with a title', async () => {
await parser.parse(`pie title a 60/40 pie
"ash" : 60
"bat" : 40
`);
Expand All @@ -68,8 +68,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with an acc title (accTitle)', () => {
parser.parse(`pie title a neat chart
it('should handle simple pie with an acc title (accTitle)', async () => {
await parser.parse(`pie title a neat chart
accTitle: a neat acc title
"ash" : 60
"bat" : 40
Expand All @@ -84,8 +84,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with an acc description (accDescr)', () => {
parser.parse(`pie title a neat chart
it('should handle simple pie with an acc description (accDescr)', async () => {
await parser.parse(`pie title a neat chart
accDescr: a neat description
"ash" : 60
"bat" : 40
Expand All @@ -100,8 +100,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with a multiline acc description (accDescr)', () => {
parser.parse(`pie title a neat chart
it('should handle simple pie with a multiline acc description (accDescr)', async () => {
await parser.parse(`pie title a neat chart
accDescr {
a neat description
on multiple lines
Expand All @@ -119,8 +119,8 @@ describe('pie', () => {
expect(sections['bat']).toBe(40);
});

it('should handle simple pie with positive decimal', () => {
parser.parse(`pie
it('should handle simple pie with positive decimal', async () => {
await parser.parse(`pie
"ash" : 60.67
"bat" : 40
`);
Expand All @@ -131,8 +131,8 @@ describe('pie', () => {
});

it('should handle simple pie with negative decimal', () => {
expect(() => {
parser.parse(`pie
expect(async () => {
await parser.parse(`pie
"ash" : -60.67
"bat" : 40.12
`);
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/pie/pieParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const populateDb = (ast: Pie, db: PieDB) => {
};

export const parser: ParserDefinition = {
parse: (input: string): void => {
const ast: Pie = parse('pie', input);
parse: async (input: string): Promise<void> => {
const ast: Pie = await parse('pie', input);
log.debug(ast);
populateDb(ast, db);
},
Expand Down

0 comments on commit c291e0b

Please sign in to comment.