mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-23 17:29:54 +02:00
make pie parser async
This commit is contained in:
@@ -10,8 +10,8 @@ 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
|
||||
`);
|
||||
|
||||
@@ -19,8 +19,8 @@ describe('pie', () => {
|
||||
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
|
||||
`);
|
||||
@@ -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
|
||||
`);
|
||||
@@ -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
|
||||
@@ -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
|
||||
`);
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
`);
|
||||
@@ -131,12 +131,12 @@ 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
|
||||
`);
|
||||
}).toThrowError();
|
||||
}).rejects.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -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);
|
||||
},
|
||||
|
Reference in New Issue
Block a user