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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,7 +3,7 @@ import "../common/common";
entry Packet: entry Packet:
NEWLINE* NEWLINE*
"packet-beta" ("packet"| "packet-beta")
( (
TitleAndAccessibilities TitleAndAccessibilities
| blocks+=PacketBlock | blocks+=PacketBlock
@@ -13,4 +13,4 @@ entry Packet:
PacketBlock: PacketBlock:
start=INT('-' end=INT)? ':' label=STRING EOL start=INT('-' end=INT)? ':' label=STRING EOL
; ;

View File

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

View File

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

View File

@@ -32,9 +32,10 @@ const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined)
* @param result - the result `parse` function. * @param result - the result `parse` function.
*/ */
export function expectNoErrorsOrAlternatives(result: ParseResult) { export function expectNoErrorsOrAlternatives(result: ParseResult) {
expect(result.lexerErrors).toHaveLength(0); expect.soft(result.lexerErrors).toHaveLength(0);
expect(result.parserErrors).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(); expect(consoleMock).not.toHaveBeenCalled();
consoleMock.mockReset(); consoleMock.mockReset();
} }