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());
|
beforeEach(() => db.clear());
|
||||||
|
|
||||||
describe('parse', () => {
|
describe('parse', () => {
|
||||||
it('should handle very simple pie', () => {
|
it('should handle very simple pie', async () => {
|
||||||
parser.parse(`pie
|
await parser.parse(`pie
|
||||||
"ash": 100
|
"ash": 100
|
||||||
`);
|
`);
|
||||||
|
|
||||||
@@ -19,8 +19,8 @@ describe('pie', () => {
|
|||||||
expect(sections['ash']).toBe(100);
|
expect(sections['ash']).toBe(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie', () => {
|
it('should handle simple pie', async () => {
|
||||||
parser.parse(`pie
|
await parser.parse(`pie
|
||||||
"ash" : 60
|
"ash" : 60
|
||||||
"bat" : 40
|
"bat" : 40
|
||||||
`);
|
`);
|
||||||
@@ -30,8 +30,8 @@ describe('pie', () => {
|
|||||||
expect(sections['bat']).toBe(40);
|
expect(sections['bat']).toBe(40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie with showData', () => {
|
it('should handle simple pie with showData', async () => {
|
||||||
parser.parse(`pie showData
|
await parser.parse(`pie showData
|
||||||
"ash" : 60
|
"ash" : 60
|
||||||
"bat" : 40
|
"bat" : 40
|
||||||
`);
|
`);
|
||||||
@@ -43,8 +43,8 @@ describe('pie', () => {
|
|||||||
expect(sections['bat']).toBe(40);
|
expect(sections['bat']).toBe(40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie with comments', () => {
|
it('should handle simple pie with comments', async () => {
|
||||||
parser.parse(`pie
|
await parser.parse(`pie
|
||||||
%% comments
|
%% comments
|
||||||
"ash" : 60
|
"ash" : 60
|
||||||
"bat" : 40
|
"bat" : 40
|
||||||
@@ -55,8 +55,8 @@ describe('pie', () => {
|
|||||||
expect(sections['bat']).toBe(40);
|
expect(sections['bat']).toBe(40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie with a title', () => {
|
it('should handle simple pie with a title', async () => {
|
||||||
parser.parse(`pie title a 60/40 pie
|
await parser.parse(`pie title a 60/40 pie
|
||||||
"ash" : 60
|
"ash" : 60
|
||||||
"bat" : 40
|
"bat" : 40
|
||||||
`);
|
`);
|
||||||
@@ -68,8 +68,8 @@ describe('pie', () => {
|
|||||||
expect(sections['bat']).toBe(40);
|
expect(sections['bat']).toBe(40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie with an acc title (accTitle)', () => {
|
it('should handle simple pie with an acc title (accTitle)', async () => {
|
||||||
parser.parse(`pie title a neat chart
|
await parser.parse(`pie title a neat chart
|
||||||
accTitle: a neat acc title
|
accTitle: a neat acc title
|
||||||
"ash" : 60
|
"ash" : 60
|
||||||
"bat" : 40
|
"bat" : 40
|
||||||
@@ -84,8 +84,8 @@ describe('pie', () => {
|
|||||||
expect(sections['bat']).toBe(40);
|
expect(sections['bat']).toBe(40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie with an acc description (accDescr)', () => {
|
it('should handle simple pie with an acc description (accDescr)', async () => {
|
||||||
parser.parse(`pie title a neat chart
|
await parser.parse(`pie title a neat chart
|
||||||
accDescr: a neat description
|
accDescr: a neat description
|
||||||
"ash" : 60
|
"ash" : 60
|
||||||
"bat" : 40
|
"bat" : 40
|
||||||
@@ -100,8 +100,8 @@ describe('pie', () => {
|
|||||||
expect(sections['bat']).toBe(40);
|
expect(sections['bat']).toBe(40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie with a multiline acc description (accDescr)', () => {
|
it('should handle simple pie with a multiline acc description (accDescr)', async () => {
|
||||||
parser.parse(`pie title a neat chart
|
await parser.parse(`pie title a neat chart
|
||||||
accDescr {
|
accDescr {
|
||||||
a neat description
|
a neat description
|
||||||
on multiple lines
|
on multiple lines
|
||||||
@@ -119,8 +119,8 @@ describe('pie', () => {
|
|||||||
expect(sections['bat']).toBe(40);
|
expect(sections['bat']).toBe(40);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie with positive decimal', () => {
|
it('should handle simple pie with positive decimal', async () => {
|
||||||
parser.parse(`pie
|
await parser.parse(`pie
|
||||||
"ash" : 60.67
|
"ash" : 60.67
|
||||||
"bat" : 40
|
"bat" : 40
|
||||||
`);
|
`);
|
||||||
@@ -131,12 +131,12 @@ describe('pie', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should handle simple pie with negative decimal', () => {
|
it('should handle simple pie with negative decimal', () => {
|
||||||
expect(() => {
|
expect(async () => {
|
||||||
parser.parse(`pie
|
await parser.parse(`pie
|
||||||
"ash" : -60.67
|
"ash" : -60.67
|
||||||
"bat" : 40.12
|
"bat" : 40.12
|
||||||
`);
|
`);
|
||||||
}).toThrowError();
|
}).rejects.toThrowError();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -13,8 +13,8 @@ const populateDb = (ast: Pie, db: PieDB) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const parser: ParserDefinition = {
|
export const parser: ParserDefinition = {
|
||||||
parse: (input: string): void => {
|
parse: async (input: string): Promise<void> => {
|
||||||
const ast: Pie = parse('pie', input);
|
const ast: Pie = await parse('pie', input);
|
||||||
log.debug(ast);
|
log.debug(ast);
|
||||||
populateDb(ast, db);
|
populateDb(ast, db);
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user