mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
chore: Update tests
This commit is contained in:
parent
f715863540
commit
442da6c4a2
@ -1,31 +1,27 @@
|
|||||||
import { parser } from './infoParser.js';
|
import { parser } from './infoParser.js';
|
||||||
|
|
||||||
describe('info', () => {
|
describe('info', () => {
|
||||||
it('should handle an info definition', () => {
|
it('should handle an info definition', async () => {
|
||||||
const str = `info`;
|
const str = `info`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).resolves.not.toThrow();
|
||||||
parser.parse(str);
|
|
||||||
}).not.toThrow();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle an info definition with showInfo', () => {
|
it('should handle an info definition with showInfo', async () => {
|
||||||
const str = `info showInfo`;
|
const str = `info showInfo`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).resolves.not.toThrow();
|
||||||
parser.parse(str);
|
|
||||||
}).not.toThrow();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw because of unsupported info grammar', () => {
|
it('should throw because of unsupported info grammar', async () => {
|
||||||
const str = `info unsupported`;
|
const str = `info unsupported`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).rejects.toThrow(
|
||||||
parser.parse(str);
|
'Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.'
|
||||||
}).toThrow('Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.');
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw because of unsupported info grammar', () => {
|
it('should throw because of unsupported info grammar', async () => {
|
||||||
const str = `info unsupported`;
|
const str = `info unsupported`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).rejects.toThrow(
|
||||||
parser.parse(str);
|
'Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.'
|
||||||
}).toThrow('Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.');
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { it, describe, expect } from 'vitest';
|
||||||
import { db } from './db.js';
|
import { db } from './db.js';
|
||||||
import { parser } from './parser.js';
|
import { parser } from './parser.js';
|
||||||
|
|
||||||
@ -8,24 +9,20 @@ describe('packet diagrams', () => {
|
|||||||
clear();
|
clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle a packet-beta definition', () => {
|
it('should handle a packet-beta definition', async () => {
|
||||||
const str = `packet-beta`;
|
const str = `packet-beta`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).resolves.not.toThrow();
|
||||||
parser.parse(str);
|
|
||||||
}).not.toThrow();
|
|
||||||
expect(getPacket()).toMatchInlineSnapshot('[]');
|
expect(getPacket()).toMatchInlineSnapshot('[]');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle diagram with data and title', () => {
|
it('should handle diagram with data and title', async () => {
|
||||||
const str = `packet-beta
|
const str = `packet-beta
|
||||||
title Packet diagram
|
title Packet diagram
|
||||||
accTitle: Packet accTitle
|
accTitle: Packet accTitle
|
||||||
accDescr: Packet accDescription
|
accDescr: Packet accDescription
|
||||||
0-10: "test"
|
0-10: "test"
|
||||||
`;
|
`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).resolves.not.toThrow();
|
||||||
parser.parse(str);
|
|
||||||
}).not.toThrow();
|
|
||||||
expect(getDiagramTitle()).toMatchInlineSnapshot('"Packet diagram"');
|
expect(getDiagramTitle()).toMatchInlineSnapshot('"Packet diagram"');
|
||||||
expect(getAccTitle()).toMatchInlineSnapshot('"Packet accTitle"');
|
expect(getAccTitle()).toMatchInlineSnapshot('"Packet accTitle"');
|
||||||
expect(getAccDescription()).toMatchInlineSnapshot('"Packet accDescription"');
|
expect(getAccDescription()).toMatchInlineSnapshot('"Packet accDescription"');
|
||||||
@ -42,14 +39,12 @@ describe('packet diagrams', () => {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle single bits', () => {
|
it('should handle single bits', async () => {
|
||||||
const str = `packet-beta
|
const str = `packet-beta
|
||||||
0-10: "test"
|
0-10: "test"
|
||||||
11: "single"
|
11: "single"
|
||||||
`;
|
`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).resolves.not.toThrow();
|
||||||
parser.parse(str);
|
|
||||||
}).not.toThrow();
|
|
||||||
expect(getPacket()).toMatchInlineSnapshot(`
|
expect(getPacket()).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
@ -68,14 +63,12 @@ describe('packet diagrams', () => {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should split into multiple rows', () => {
|
it('should split into multiple rows', async () => {
|
||||||
const str = `packet-beta
|
const str = `packet-beta
|
||||||
0-10: "test"
|
0-10: "test"
|
||||||
11-90: "multiple"
|
11-90: "multiple"
|
||||||
`;
|
`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).resolves.not.toThrow();
|
||||||
parser.parse(str);
|
|
||||||
}).not.toThrow();
|
|
||||||
expect(getPacket()).toMatchInlineSnapshot(`
|
expect(getPacket()).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
@ -108,14 +101,12 @@ describe('packet diagrams', () => {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should split into multiple rows when cut at exact length', () => {
|
it('should split into multiple rows when cut at exact length', async () => {
|
||||||
const str = `packet-beta
|
const str = `packet-beta
|
||||||
0-16: "test"
|
0-16: "test"
|
||||||
17-63: "multiple"
|
17-63: "multiple"
|
||||||
`;
|
`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).resolves.not.toThrow();
|
||||||
parser.parse(str);
|
|
||||||
}).not.toThrow();
|
|
||||||
expect(getPacket()).toMatchInlineSnapshot(`
|
expect(getPacket()).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
@ -141,51 +132,43 @@ describe('packet diagrams', () => {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw error if numbers are not continuous', () => {
|
it('should throw error if numbers are not continuous', async () => {
|
||||||
const str = `packet-beta
|
const str = `packet-beta
|
||||||
0-16: "test"
|
0-16: "test"
|
||||||
18-20: "error"
|
18-20: "error"
|
||||||
`;
|
`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||||
parser.parse(str);
|
|
||||||
}).toThrowErrorMatchingInlineSnapshot(
|
|
||||||
'"Packet block 18 - 20 is not contiguous. It should start from 17."'
|
'"Packet block 18 - 20 is not contiguous. It should start from 17."'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw error if numbers are not continuous for single packets', () => {
|
it('should throw error if numbers are not continuous for single packets', async () => {
|
||||||
const str = `packet-beta
|
const str = `packet-beta
|
||||||
0-16: "test"
|
0-16: "test"
|
||||||
18: "error"
|
18: "error"
|
||||||
`;
|
`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||||
parser.parse(str);
|
|
||||||
}).toThrowErrorMatchingInlineSnapshot(
|
|
||||||
'"Packet block 18 - 18 is not contiguous. It should start from 17."'
|
'"Packet block 18 - 18 is not contiguous. It should start from 17."'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw error if numbers are not continuous for single packets - 2', () => {
|
it('should throw error if numbers are not continuous for single packets - 2', async () => {
|
||||||
const str = `packet-beta
|
const str = `packet-beta
|
||||||
0-16: "test"
|
0-16: "test"
|
||||||
17: "good"
|
17: "good"
|
||||||
19: "error"
|
19: "error"
|
||||||
`;
|
`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||||
parser.parse(str);
|
|
||||||
}).toThrowErrorMatchingInlineSnapshot(
|
|
||||||
'"Packet block 19 - 19 is not contiguous. It should start from 18."'
|
'"Packet block 19 - 19 is not contiguous. It should start from 18."'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw error if end is less than start', () => {
|
it('should throw error if end is less than start', async () => {
|
||||||
const str = `packet-beta
|
const str = `packet-beta
|
||||||
0-16: "test"
|
0-16: "test"
|
||||||
25-20: "error"
|
25-20: "error"
|
||||||
`;
|
`;
|
||||||
expect(() => {
|
await expect(parser.parse(str)).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||||
parser.parse(str);
|
|
||||||
}).toThrowErrorMatchingInlineSnapshot(
|
|
||||||
'"Packet block 25 - 20 is invalid. End must be greater than start."'
|
'"Packet block 25 - 20 is invalid. End must be greater than start."'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user