Skip to content

Commit

Permalink
Allow architecture diagrams to support any character for titles
Browse files Browse the repository at this point in the history
  • Loading branch information
wizbit committed Oct 4, 2024
1 parent ddf18dd commit 7857686
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import "../common/common";
entry Architecture:
NEWLINE*
"architecture-beta"
(
NEWLINE* TitleAndAccessibilities
| NEWLINE* Statement*
| NEWLINE*
)
NEWLINE* TitleAndAccessibilities? Statement*
;

fragment Statement:
Expand Down Expand Up @@ -50,6 +46,6 @@ terminal ARROW_DIRECTION: 'L' | 'R' | 'T' | 'B';
terminal ARCH_ID: /[\w]+/;
terminal ARCH_TEXT_ICON: /\("[^"]+"\)/;
terminal ARCH_ICON: /\([\w-:]+\)/;
terminal ARCH_TITLE: /\[[\w ]+\]/;
terminal ARCH_TITLE: /\[[^\]]+\]/;
terminal ARROW_GROUP: /\{group\}/;
terminal ARROW_INTO: /<|>/;
68 changes: 68 additions & 0 deletions packages/parser/tests/architecture.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, expect, it } from 'vitest';

import { Architecture } from '../src/index.js';
import { expectNoErrorsOrAlternatives, architectureParse as parse } from './test-util.js';

describe('architecture', () => {
it.each([
`architecture-beta`,
` architecture-beta `,
`\tarchitecture-beta\t`,
`
\tarchitecture-beta
`,
])('should handle regular architecture-beta', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);
});

it.each([
`architecture-beta group api(cloud)[API]`,
` architecture-beta group api(cloud)[API] `,
`\tarchitecture-beta\tgroup api(cloud)[API]\t`,
`
architecture-beta\tgroup api(cloud)[API]
`,
])('should handle architecture-beta & group in same line', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);

const { groups } = result.value;
expect(groups[0]).toBeTruthy();
});

it.each([
`architecture-beta
group api(cloud)[API]`,
`architecture-beta
group api(cloud)[API]
`,
`architecture-beta
group api(cloud)[API]`,
`architecture-beta
group api(cloud)[API]
`,
])('should handle architecture-beta + group in different line', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);

const { groups } = result.value;
expect(groups[0].title).toBe('API');
});

it.each([
`architecture-beta group api(cloud)[a.b-t]`,
`architecture-beta group api(cloud)[user:password@some_domain.com]
`,
])('should handle special character in a title', (context: string) => {
const result = parse(context);
expectNoErrorsOrAlternatives(result);
expect(result.value.$type).toBe(Architecture);

const { groups } = result.value;
expect(groups[0]).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions packages/parser/tests/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import type {
PieServices,
GitGraph,
GitGraphServices,
Architecture,
ArchitectureServices,
} from '../src/language/index.js';
import {
createInfoServices,
createPieServices,
createGitGraphServices,
createArchitectureServices,
} from '../src/language/index.js';

const consoleMock = vi.spyOn(console, 'log').mockImplementation(() => undefined);
Expand Down Expand Up @@ -62,3 +65,14 @@ export function createGitGraphTestServices() {
return { services: gitGraphServices, parse };
}
export const gitGraphParse = createGitGraphTestServices().parse;

const architectureServices: ArchitectureServices = createArchitectureServices().Architecture;
const architectureParser: LangiumParser = architectureServices.parser.LangiumParser;
export function createArchitectureTestServices() {
const parse = (input: string) => {
return architectureParser.parse<Architecture>(input);
};

return { services: architectureServices, parse };
}
export const architectureParse = createArchitectureTestServices().parse;

0 comments on commit 7857686

Please sign in to comment.