diff --git a/cypress/integration/rendering/packet.spec.ts b/cypress/integration/rendering/packet.spec.ts index c64538875..2a32b9d07 100644 --- a/cypress/integration/rendering/packet.spec.ts +++ b/cypress/integration/rendering/packet.spec.ts @@ -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" diff --git a/demos/packet.html b/demos/packet.html index b66880f39..c83513dd9 100644 --- a/demos/packet.html +++ b/demos/packet.html @@ -17,7 +17,7 @@
- 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" diff --git a/docs/syntax/packet.md b/docs/syntax/packet.md index 5eab81910..77a718747 100644 --- a/docs/syntax/packet.md +++ b/docs/syntax/packet.md @@ -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" diff --git a/packages/mermaid/src/diagrams/packet/detector.ts b/packages/mermaid/src/diagrams/packet/detector.ts index 5aca92e6c..ed3c61054 100644 --- a/packages/mermaid/src/diagrams/packet/detector.ts +++ b/packages/mermaid/src/diagrams/packet/detector.ts @@ -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 () => { diff --git a/packages/mermaid/src/diagrams/packet/packet.spec.ts b/packages/mermaid/src/diagrams/packet/packet.spec.ts index 2d7b278cd..d328bc4ba 100644 --- a/packages/mermaid/src/diagrams/packet/packet.spec.ts +++ b/packages/mermaid/src/diagrams/packet/packet.spec.ts @@ -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" `; diff --git a/packages/mermaid/src/docs/syntax/packet.md b/packages/mermaid/src/docs/syntax/packet.md index c7b6cb71b..d73adf5d7 100644 --- a/packages/mermaid/src/docs/syntax/packet.md +++ b/packages/mermaid/src/docs/syntax/packet.md @@ -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" diff --git a/packages/mermaid/src/mermaidAPI.spec.ts b/packages/mermaid/src/mermaidAPI.spec.ts index 3e28dbfd4..e1ba8d9da 100644 --- a/packages/mermaid/src/mermaidAPI.spec.ts +++ b/packages/mermaid/src/mermaidAPI.spec.ts @@ -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' }, diff --git a/packages/parser/src/language/packet/packet.langium b/packages/parser/src/language/packet/packet.langium index 91d6501ed..434817dff 100644 --- a/packages/parser/src/language/packet/packet.langium +++ b/packages/parser/src/language/packet/packet.langium @@ -3,7 +3,7 @@ import "../common/common"; entry Packet: NEWLINE* - "packet-beta" + ("packet"| "packet-beta") ( TitleAndAccessibilities | blocks+=PacketBlock @@ -13,4 +13,4 @@ entry Packet: PacketBlock: start=INT('-' end=INT)? ':' label=STRING EOL -; \ No newline at end of file +; diff --git a/packages/parser/src/language/packet/tokenBuilder.ts b/packages/parser/src/language/packet/tokenBuilder.ts index accba5675..c0bbdf3ed 100644 --- a/packages/parser/src/language/packet/tokenBuilder.ts +++ b/packages/parser/src/language/packet/tokenBuilder.ts @@ -2,6 +2,6 @@ import { AbstractMermaidTokenBuilder } from '../common/index.js'; export class PacketTokenBuilder extends AbstractMermaidTokenBuilder { public constructor() { - super(['packet-beta']); + super(['packet']); } } diff --git a/packages/parser/tests/packet.test.ts b/packages/parser/tests/packet.test.ts index eb2ea303d..1b2e1a496 100644 --- a/packages/parser/tests/packet.test.ts +++ b/packages/parser/tests/packet.test.ts @@ -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); diff --git a/packages/parser/tests/test-util.ts b/packages/parser/tests/test-util.ts index 7a6050016..ee7627109 100644 --- a/packages/parser/tests/test-util.ts +++ b/packages/parser/tests/test-util.ts @@ -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(); }