Skip to content

Commit

Permalink
chore: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Jan 24, 2024
1 parent f715863 commit 442da6c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 52 deletions.
28 changes: 12 additions & 16 deletions packages/mermaid/src/diagrams/info/info.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import { parser } from './infoParser.js';

describe('info', () => {
it('should handle an info definition', () => {
it('should handle an info definition', async () => {
const str = `info`;
expect(() => {
parser.parse(str);
}).not.toThrow();
await expect(parser.parse(str)).resolves.not.toThrow();
});

it('should handle an info definition with showInfo', () => {
it('should handle an info definition with showInfo', async () => {
const str = `info showInfo`;
expect(() => {
parser.parse(str);
}).not.toThrow();
await expect(parser.parse(str)).resolves.not.toThrow();
});

it('should throw because of unsupported info grammar', () => {
it('should throw because of unsupported info grammar', async () => {
const str = `info unsupported`;
expect(() => {
parser.parse(str);
}).toThrow('Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.');
await expect(parser.parse(str)).rejects.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`;
expect(() => {
parser.parse(str);
}).toThrow('Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.');
await expect(parser.parse(str)).rejects.toThrow(
'Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.'
);
});
});
55 changes: 19 additions & 36 deletions packages/mermaid/src/diagrams/packet/packet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { it, describe, expect } from 'vitest';
import { db } from './db.js';
import { parser } from './parser.js';

Expand All @@ -8,24 +9,20 @@ describe('packet diagrams', () => {
clear();
});

it('should handle a packet-beta definition', () => {
it('should handle a packet-beta definition', async () => {
const str = `packet-beta`;
expect(() => {
parser.parse(str);
}).not.toThrow();
await expect(parser.parse(str)).resolves.not.toThrow();
expect(getPacket()).toMatchInlineSnapshot('[]');
});

it('should handle diagram with data and title', () => {
it('should handle diagram with data and title', async () => {
const str = `packet-beta
title Packet diagram
accTitle: Packet accTitle
accDescr: Packet accDescription
0-10: "test"
`;
expect(() => {
parser.parse(str);
}).not.toThrow();
await expect(parser.parse(str)).resolves.not.toThrow();
expect(getDiagramTitle()).toMatchInlineSnapshot('"Packet diagram"');
expect(getAccTitle()).toMatchInlineSnapshot('"Packet accTitle"');
expect(getAccDescription()).toMatchInlineSnapshot('"Packet accDescription"');
Expand All @@ -42,14 +39,12 @@ describe('packet diagrams', () => {
`);
});

it('should handle single bits', () => {
it('should handle single bits', async () => {
const str = `packet-beta
0-10: "test"
11: "single"
`;
expect(() => {
parser.parse(str);
}).not.toThrow();
await expect(parser.parse(str)).resolves.not.toThrow();
expect(getPacket()).toMatchInlineSnapshot(`
[
[
Expand All @@ -68,14 +63,12 @@ describe('packet diagrams', () => {
`);
});

it('should split into multiple rows', () => {
it('should split into multiple rows', async () => {
const str = `packet-beta
0-10: "test"
11-90: "multiple"
`;
expect(() => {
parser.parse(str);
}).not.toThrow();
await expect(parser.parse(str)).resolves.not.toThrow();
expect(getPacket()).toMatchInlineSnapshot(`
[
[
Expand Down Expand Up @@ -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
0-16: "test"
17-63: "multiple"
`;
expect(() => {
parser.parse(str);
}).not.toThrow();
await expect(parser.parse(str)).resolves.not.toThrow();
expect(getPacket()).toMatchInlineSnapshot(`
[
[
Expand All @@ -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
0-16: "test"
18-20: "error"
`;
expect(() => {
parser.parse(str);
}).toThrowErrorMatchingInlineSnapshot(
await expect(parser.parse(str)).rejects.toThrowErrorMatchingInlineSnapshot(
'"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
0-16: "test"
18: "error"
`;
expect(() => {
parser.parse(str);
}).toThrowErrorMatchingInlineSnapshot(
await expect(parser.parse(str)).rejects.toThrowErrorMatchingInlineSnapshot(
'"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
0-16: "test"
17: "good"
19: "error"
`;
expect(() => {
parser.parse(str);
}).toThrowErrorMatchingInlineSnapshot(
await expect(parser.parse(str)).rejects.toThrowErrorMatchingInlineSnapshot(
'"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
0-16: "test"
25-20: "error"
`;
expect(() => {
parser.parse(str);
}).toThrowErrorMatchingInlineSnapshot(
await expect(parser.parse(str)).rejects.toThrowErrorMatchingInlineSnapshot(
'"Packet block 25 - 20 is invalid. End must be greater than start."'
);
});
Expand Down

0 comments on commit 442da6c

Please sign in to comment.