chore: Move packet diagram out of beta

This commit is contained in:
Sidharth Vinod
2025-04-20 14:09:27 +05:30
parent 1c1d7d0300
commit 19884294bc
11 changed files with 56 additions and 33 deletions

View File

@@ -1,7 +1,7 @@
import { imgSnapshotTest } from '../../helpers/util';
describe('packet structure', () => {
it('should render a simple packet diagram', () => {
it('should render a simple packet-beta diagram', () => {
imgSnapshotTest(
`packet-beta
title Hello world
@@ -10,9 +10,18 @@ describe('packet structure', () => {
);
});
it('should render a simple packet diagram', () => {
imgSnapshotTest(
`packet
title Hello world
0-10: "hello"
`
);
});
it('should render a simple packet diagram without ranges', () => {
imgSnapshotTest(
`packet-beta
`packet
0: "h"
1: "i"
`
@@ -21,7 +30,7 @@ describe('packet structure', () => {
it('should render a complex packet diagram', () => {
imgSnapshotTest(
`packet-beta
`packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"
@@ -52,7 +61,7 @@ describe('packet structure', () => {
packet:
showBits: false
---
packet-beta
packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"

View File

@@ -17,7 +17,7 @@
<div class="diagrams">
<pre class="mermaid">
packet-beta
packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"
@@ -44,7 +44,7 @@
packet:
showBits: false
---
packet-beta
packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"
@@ -70,7 +70,7 @@
config:
theme: forest
---
packet-beta
packet
title Forest theme
0-15: "Source Port"
16-31: "Destination Port"
@@ -97,7 +97,7 @@
config:
theme: dark
---
packet-beta
packet
title Dark theme
0-15: "Source Port"
16-31: "Destination Port"

View File

@@ -17,7 +17,7 @@ This diagram type is particularly useful for developers, network engineers, educ
## Syntax
```md
packet-beta
packet
start: "Block name" %% Single-bit block
start-end: "Block name" %% Multi-bit blocks
... More Fields ...
@@ -29,7 +29,7 @@ start-end: "Block name" %% Multi-bit blocks
---
title: "TCP Packet"
---
packet-beta
packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"
@@ -53,7 +53,7 @@ packet-beta
---
title: "TCP Packet"
---
packet-beta
packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"
@@ -74,7 +74,7 @@ packet-beta
```
```mermaid-example
packet-beta
packet
title UDP Packet
0-15: "Source Port"
16-31: "Destination Port"
@@ -84,7 +84,7 @@ title UDP Packet
```
```mermaid
packet-beta
packet
title UDP Packet
0-15: "Source Port"
16-31: "Destination Port"
@@ -132,7 +132,7 @@ config:
packet:
startByteColor: red
---
packet-beta
packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"

View File

@@ -7,7 +7,7 @@ import type {
const id = 'packet';
const detector: DiagramDetector = (txt) => {
return /^\s*packet-beta/.test(txt);
return /^\s*packet(-beta)?/.test(txt);
};
const loader: DiagramLoader = async () => {

View File

@@ -15,8 +15,14 @@ describe('packet diagrams', () => {
expect(getPacket()).toMatchInlineSnapshot('[]');
});
it('should handle a packet definition', async () => {
const str = `packet`;
await expect(parser.parse(str)).resolves.not.toThrow();
expect(getPacket()).toMatchInlineSnapshot('[]');
});
it('should handle diagram with data and title', async () => {
const str = `packet-beta
const str = `packet
title Packet diagram
accTitle: Packet accTitle
accDescr: Packet accDescription
@@ -40,7 +46,7 @@ describe('packet diagrams', () => {
});
it('should handle single bits', async () => {
const str = `packet-beta
const str = `packet
0-10: "test"
11: "single"
`;
@@ -64,7 +70,7 @@ describe('packet diagrams', () => {
});
it('should split into multiple rows', async () => {
const str = `packet-beta
const str = `packet
0-10: "test"
11-90: "multiple"
`;
@@ -102,7 +108,7 @@ describe('packet diagrams', () => {
});
it('should split into multiple rows when cut at exact length', async () => {
const str = `packet-beta
const str = `packet
0-16: "test"
17-63: "multiple"
`;
@@ -133,7 +139,7 @@ describe('packet diagrams', () => {
});
it('should throw error if numbers are not continuous', async () => {
const str = `packet-beta
const str = `packet
0-16: "test"
18-20: "error"
`;
@@ -143,7 +149,7 @@ describe('packet diagrams', () => {
});
it('should throw error if numbers are not continuous for single packets', async () => {
const str = `packet-beta
const str = `packet
0-16: "test"
18: "error"
`;
@@ -153,7 +159,7 @@ describe('packet diagrams', () => {
});
it('should throw error if numbers are not continuous for single packets - 2', async () => {
const str = `packet-beta
const str = `packet
0-16: "test"
17: "good"
19: "error"
@@ -164,7 +170,7 @@ describe('packet diagrams', () => {
});
it('should throw error if end is less than start', async () => {
const str = `packet-beta
const str = `packet
0-16: "test"
25-20: "error"
`;

View File

@@ -11,7 +11,7 @@ This diagram type is particularly useful for developers, network engineers, educ
## Syntax
```md
packet-beta
packet
start: "Block name" %% Single-bit block
start-end: "Block name" %% Multi-bit blocks
... More Fields ...
@@ -23,7 +23,7 @@ start-end: "Block name" %% Multi-bit blocks
---
title: "TCP Packet"
---
packet-beta
packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"
@@ -44,7 +44,7 @@ packet-beta
```
```mermaid-example
packet-beta
packet
title UDP Packet
0-15: "Source Port"
16-31: "Destination Port"
@@ -92,7 +92,7 @@ config:
packet:
startByteColor: red
---
packet-beta
packet
0-15: "Source Port"
16-31: "Destination Port"
32-63: "Sequence Number"

View File

@@ -795,6 +795,7 @@ graph TD;A--x|text including URL space|B;`)
{ textDiagramType: 'journey', expectedType: 'journey' },
{ textDiagramType: 'pie', expectedType: 'pie' },
{ textDiagramType: 'packet-beta', expectedType: 'packet' },
{ textDiagramType: 'packet', expectedType: 'packet' },
{ textDiagramType: 'xychart-beta', expectedType: 'xychart' },
{ textDiagramType: 'requirementDiagram', expectedType: 'requirement' },
{ textDiagramType: 'sequenceDiagram', expectedType: 'sequence' },

View File

@@ -3,7 +3,7 @@ import "../common/common";
entry Packet:
NEWLINE*
"packet-beta"
("packet"| "packet-beta")
(
TitleAndAccessibilities
| blocks+=PacketBlock

View File

@@ -2,6 +2,6 @@ import { AbstractMermaidTokenBuilder } from '../common/index.js';
export class PacketTokenBuilder extends AbstractMermaidTokenBuilder {
public constructor() {
super(['packet-beta']);
super(['packet']);
}
}

View File

@@ -11,6 +11,12 @@ describe('packet', () => {
`
\tpacket-beta
`,
`packet`,
` packet `,
`\tpacket\t`,
`
\tpacket
`,
])('should handle regular packet', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);

View File

@@ -32,9 +32,10 @@ const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined)
* @param result - the result `parse` function.
*/
export function expectNoErrorsOrAlternatives(result: ParseResult) {
expect(result.lexerErrors).toHaveLength(0);
expect(result.parserErrors).toHaveLength(0);
expect.soft(result.lexerErrors).toHaveLength(0);
expect.soft(result.parserErrors).toHaveLength(0);
// To see what the error is, in the logs.
expect(result.lexerErrors[0]).toBeUndefined();
expect(consoleMock).not.toHaveBeenCalled();
consoleMock.mockReset();
}