mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 06:49:47 +02:00
Merge branch 'develop' into pr/BryanCrotazGivEnergy/5980
* develop: (492 commits) chore: Ignore timeout domains [autofix.ci] apply automated fixes [autofix.ci] apply automated fixes Create neat-moose-compare.md chore: Add changeset updated tests modified description of showDataLabel in config schema and added it to docs fix(deps): update all major dependencies chore(deps): update peter-evans/create-pull-request digest to a7b20e1 fix(deps): update dependency dompurify to ^3.2.5 [autofix.ci] apply automated fixes Update integrations-community.md [autofix.ci] apply automated fixes Add Mermaid plus for Confluence into integrations-community.md refactor xy-chart tests added new tests added new tests chore(deps): update eslint chore: Update change detection logic chore: Use git to read old timings ...
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# @mermaid-js/parser
|
||||
|
||||
## 0.4.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#6381](https://github.com/mermaid-js/mermaid/pull/6381) [`95d73bc`](https://github.com/mermaid-js/mermaid/commit/95d73bc3f064dbf261a06483f94a7ef4d0bb52eb) Thanks [@thomascizeron](https://github.com/thomascizeron)! - Add Radar Chart
|
||||
|
||||
## 0.3.0
|
||||
|
||||
### Minor Changes
|
||||
|
@@ -25,6 +25,11 @@
|
||||
"id": "gitGraph",
|
||||
"grammar": "src/language/gitGraph/gitGraph.langium",
|
||||
"fileExtensions": [".mmd", ".mermaid"]
|
||||
},
|
||||
{
|
||||
"id": "radar",
|
||||
"grammar": "src/language/radar/radar.langium",
|
||||
"fileExtensions": [".mmd", ".mermaid"]
|
||||
}
|
||||
],
|
||||
"mode": "production",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mermaid-js/parser",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0",
|
||||
"description": "MermaidJS parser",
|
||||
"author": "Yokozuna59",
|
||||
"contributors": [
|
||||
@@ -33,7 +33,7 @@
|
||||
"ast"
|
||||
],
|
||||
"dependencies": {
|
||||
"langium": "3.0.0"
|
||||
"langium": "3.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chevrotain": "^11.0.3"
|
||||
|
2
packages/parser/src/language/architecture/arch.langium
Normal file
2
packages/parser/src/language/architecture/arch.langium
Normal file
@@ -0,0 +1,2 @@
|
||||
terminal ARCH_ICON: /\([\w-:]+\)/;
|
||||
terminal ARCH_TITLE: /\[[\w ]+\]/;
|
@@ -1,14 +1,15 @@
|
||||
grammar Architecture
|
||||
import "../common/common";
|
||||
import "arch";
|
||||
|
||||
entry Architecture:
|
||||
NEWLINE*
|
||||
"architecture-beta"
|
||||
(
|
||||
NEWLINE* TitleAndAccessibilities
|
||||
| NEWLINE* Statement*
|
||||
| NEWLINE*
|
||||
)
|
||||
NEWLINE
|
||||
| TitleAndAccessibilities
|
||||
| Statement
|
||||
)*
|
||||
;
|
||||
|
||||
fragment Statement:
|
||||
@@ -31,25 +32,21 @@ fragment Arrow:
|
||||
;
|
||||
|
||||
Group:
|
||||
'group' id=ARCH_ID icon=ARCH_ICON? title=ARCH_TITLE? ('in' in=ARCH_ID)? EOL
|
||||
'group' id=ID icon=ARCH_ICON? title=ARCH_TITLE? ('in' in=ID)? EOL
|
||||
;
|
||||
|
||||
Service:
|
||||
'service' id=ARCH_ID (iconText=ARCH_TEXT_ICON | icon=ARCH_ICON)? title=ARCH_TITLE? ('in' in=ARCH_ID)? EOL
|
||||
'service' id=ID (iconText=STRING | icon=ARCH_ICON)? title=ARCH_TITLE? ('in' in=ID)? EOL
|
||||
;
|
||||
|
||||
Junction:
|
||||
'junction' id=ARCH_ID ('in' in=ARCH_ID)? EOL
|
||||
'junction' id=ID ('in' in=ID)? EOL
|
||||
;
|
||||
|
||||
Edge:
|
||||
lhsId=ARCH_ID lhsGroup?=ARROW_GROUP? Arrow rhsId=ARCH_ID rhsGroup?=ARROW_GROUP? EOL
|
||||
lhsId=ID lhsGroup?=ARROW_GROUP? Arrow rhsId=ID rhsGroup?=ARROW_GROUP? EOL
|
||||
;
|
||||
|
||||
terminal ARROW_DIRECTION: 'L' | 'R' | 'T' | 'B';
|
||||
terminal ARCH_ID: /[\w]+/;
|
||||
terminal ARCH_TEXT_ICON: /\("[^"]+"\)/;
|
||||
terminal ARCH_ICON: /\([\w-:]+\)/;
|
||||
terminal ARCH_TITLE: /\[[\w ]+\]/;
|
||||
terminal ARROW_GROUP: /\{group\}/;
|
||||
terminal ARROW_INTO: /<|>/;
|
||||
|
@@ -1,22 +1,35 @@
|
||||
interface Common {
|
||||
accDescr?: string;
|
||||
accTitle?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
fragment TitleAndAccessibilities:
|
||||
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
|
||||
;
|
||||
// Base terminals and fragments for common language constructs
|
||||
// Terminal Precedence: Lazy to Greedy
|
||||
// When imported, the terminals are considered after the terminals in the importing grammar
|
||||
// Note: Hence, to add a terminal greedier than the common terminals, import it separately after the common import
|
||||
|
||||
fragment EOL returns string:
|
||||
NEWLINE+ | EOF
|
||||
;
|
||||
|
||||
terminal NEWLINE: /\r?\n/;
|
||||
fragment TitleAndAccessibilities:
|
||||
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
|
||||
;
|
||||
|
||||
terminal BOOLEAN returns boolean: 'true' | 'false';
|
||||
|
||||
terminal ACC_DESCR: /[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/;
|
||||
terminal ACC_TITLE: /[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/;
|
||||
terminal TITLE: /[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/;
|
||||
|
||||
terminal FLOAT returns number: /[0-9]+\.[0-9]+(?!\.)/;
|
||||
terminal INT returns number: /0|[1-9][0-9]*(?!\.)/;
|
||||
terminal NUMBER returns number: FLOAT | INT;
|
||||
|
||||
terminal STRING returns string: /"([^"\\]|\\.)*"|'([^'\\]|\\.)*'/;
|
||||
|
||||
// Alphanumerics with underscores and dashes
|
||||
// Must start with an alphanumeric or an underscore
|
||||
// Cant end with a dash
|
||||
terminal ID returns string: /[\w]([-\w]*\w)?/;
|
||||
|
||||
terminal NEWLINE: /\r?\n/;
|
||||
|
||||
hidden terminal WHITESPACE: /[\t ]+/;
|
||||
hidden terminal YAML: /---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/;
|
||||
hidden terminal DIRECTIVE: /[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/;
|
||||
|
@@ -1,39 +1,15 @@
|
||||
grammar GitGraph
|
||||
|
||||
interface Common {
|
||||
accDescr?: string;
|
||||
accTitle?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
fragment TitleAndAccessibilities:
|
||||
((accDescr=ACC_DESCR | accTitle=ACC_TITLE | title=TITLE) EOL)+
|
||||
;
|
||||
|
||||
fragment EOL returns string:
|
||||
NEWLINE+ | EOF
|
||||
;
|
||||
|
||||
terminal NEWLINE: /\r?\n/;
|
||||
terminal ACC_DESCR: /[\t ]*accDescr(?:[\t ]*:([^\n\r]*?(?=%%)|[^\n\r]*)|\s*{([^}]*)})/;
|
||||
terminal ACC_TITLE: /[\t ]*accTitle[\t ]*:(?:[^\n\r]*?(?=%%)|[^\n\r]*)/;
|
||||
terminal TITLE: /[\t ]*title(?:[\t ][^\n\r]*?(?=%%)|[\t ][^\n\r]*|)/;
|
||||
|
||||
hidden terminal WHITESPACE: /[\t ]+/;
|
||||
hidden terminal YAML: /---[\t ]*\r?\n(?:[\S\s]*?\r?\n)?---(?:\r?\n|(?!\S))/;
|
||||
hidden terminal DIRECTIVE: /[\t ]*%%{[\S\s]*?}%%(?:\r?\n|(?!\S))/;
|
||||
hidden terminal SINGLE_LINE_COMMENT: /[\t ]*%%[^\n\r]*/;
|
||||
import "../common/common";
|
||||
import "reference";
|
||||
|
||||
entry GitGraph:
|
||||
NEWLINE*
|
||||
('gitGraph' | 'gitGraph' ':' | 'gitGraph:' | ('gitGraph' Direction ':'))
|
||||
NEWLINE*
|
||||
(
|
||||
NEWLINE*
|
||||
(TitleAndAccessibilities |
|
||||
statements+=Statement |
|
||||
NEWLINE)*
|
||||
)
|
||||
NEWLINE
|
||||
| TitleAndAccessibilities
|
||||
| statements+=Statement
|
||||
)*
|
||||
;
|
||||
|
||||
Statement
|
||||
@@ -56,12 +32,12 @@ Commit:
|
||||
|'type:' type=('NORMAL' | 'REVERSE' | 'HIGHLIGHT')
|
||||
)* EOL;
|
||||
Branch:
|
||||
'branch' name=(ID|STRING)
|
||||
'branch' name=(REFERENCE|STRING)
|
||||
('order:' order=INT)?
|
||||
EOL;
|
||||
|
||||
Merge:
|
||||
'merge' branch=(ID|STRING)
|
||||
'merge' branch=(REFERENCE|STRING)
|
||||
(
|
||||
'id:' id=STRING
|
||||
|'tag:' tags+=STRING
|
||||
@@ -69,7 +45,7 @@ Merge:
|
||||
)* EOL;
|
||||
|
||||
Checkout:
|
||||
('checkout'|'switch') branch=(ID|STRING) EOL;
|
||||
('checkout'|'switch') branch=(REFERENCE|STRING) EOL;
|
||||
|
||||
CherryPicking:
|
||||
'cherry-pick'
|
||||
@@ -78,10 +54,3 @@ CherryPicking:
|
||||
|'tag:' tags+=STRING
|
||||
|'parent:' parent=STRING
|
||||
)* EOL;
|
||||
|
||||
|
||||
|
||||
terminal INT returns number: /[0-9]+(?=\s)/;
|
||||
terminal ID returns string: /\w([-\./\w]*[-\w])?/;
|
||||
terminal STRING: /"[^"]*"|'[^']*'/;
|
||||
|
||||
|
4
packages/parser/src/language/gitGraph/reference.langium
Normal file
4
packages/parser/src/language/gitGraph/reference.langium
Normal file
@@ -0,0 +1,4 @@
|
||||
// Alphanumerics with underscores, dashes, slashes, and dots
|
||||
// Must start with an alphanumeric or an underscore
|
||||
// Cant end with a dash, slash, or dot
|
||||
terminal REFERENCE returns string: /\w([-\./\w]*[-\w])?/;
|
@@ -7,11 +7,11 @@ export {
|
||||
PieSection,
|
||||
Architecture,
|
||||
GitGraph,
|
||||
Radar,
|
||||
Branch,
|
||||
Commit,
|
||||
Merge,
|
||||
Statement,
|
||||
isCommon,
|
||||
isInfo,
|
||||
isPacket,
|
||||
isPacketBlock,
|
||||
@@ -31,6 +31,7 @@ export {
|
||||
PieGeneratedModule,
|
||||
ArchitectureGeneratedModule,
|
||||
GitGraphGeneratedModule,
|
||||
RadarGeneratedModule,
|
||||
} from './generated/module.js';
|
||||
|
||||
export * from './gitGraph/index.js';
|
||||
@@ -39,3 +40,4 @@ export * from './info/index.js';
|
||||
export * from './packet/index.js';
|
||||
export * from './pie/index.js';
|
||||
export * from './architecture/index.js';
|
||||
export * from './radar/index.js';
|
||||
|
@@ -5,10 +5,10 @@ entry Packet:
|
||||
NEWLINE*
|
||||
"packet-beta"
|
||||
(
|
||||
NEWLINE* TitleAndAccessibilities blocks+=PacketBlock*
|
||||
| NEWLINE+ blocks+=PacketBlock+
|
||||
| NEWLINE*
|
||||
)
|
||||
TitleAndAccessibilities
|
||||
| blocks+=PacketBlock
|
||||
| NEWLINE
|
||||
)*
|
||||
;
|
||||
|
||||
PacketBlock:
|
||||
@@ -19,6 +19,3 @@ PacketBlock:
|
||||
':' label=STRING
|
||||
EOL
|
||||
;
|
||||
|
||||
terminal INT returns number: /0|[1-9][0-9]*/;
|
||||
terminal STRING: /"[^"]*"|'[^']*'/;
|
||||
|
@@ -5,15 +5,12 @@ entry Pie:
|
||||
NEWLINE*
|
||||
"pie" showData?="showData"?
|
||||
(
|
||||
NEWLINE* TitleAndAccessibilities sections+=PieSection*
|
||||
| NEWLINE+ sections+=PieSection+
|
||||
| NEWLINE*
|
||||
)
|
||||
TitleAndAccessibilities
|
||||
| sections+=PieSection
|
||||
| NEWLINE
|
||||
)*
|
||||
;
|
||||
|
||||
PieSection:
|
||||
label=PIE_SECTION_LABEL ":" value=PIE_SECTION_VALUE EOL
|
||||
label=STRING ":" value=NUMBER EOL
|
||||
;
|
||||
|
||||
terminal PIE_SECTION_LABEL: /"[^"]+"/;
|
||||
terminal PIE_SECTION_VALUE returns number: /(0|[1-9][0-9]*)(\.[0-9]+)?/;
|
||||
|
1
packages/parser/src/language/radar/index.ts
Normal file
1
packages/parser/src/language/radar/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './module.js';
|
73
packages/parser/src/language/radar/module.ts
Normal file
73
packages/parser/src/language/radar/module.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import type {
|
||||
DefaultSharedCoreModuleContext,
|
||||
LangiumCoreServices,
|
||||
LangiumSharedCoreServices,
|
||||
Module,
|
||||
PartialLangiumCoreServices,
|
||||
} from 'langium';
|
||||
import {
|
||||
EmptyFileSystem,
|
||||
createDefaultCoreModule,
|
||||
createDefaultSharedCoreModule,
|
||||
inject,
|
||||
} from 'langium';
|
||||
import { CommonValueConverter } from '../common/valueConverter.js';
|
||||
import { MermaidGeneratedSharedModule, RadarGeneratedModule } from '../generated/module.js';
|
||||
import { RadarTokenBuilder } from './tokenBuilder.js';
|
||||
|
||||
/**
|
||||
* Declaration of `Radar` services.
|
||||
*/
|
||||
interface RadarAddedServices {
|
||||
parser: {
|
||||
TokenBuilder: RadarTokenBuilder;
|
||||
ValueConverter: CommonValueConverter;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Union of Langium default services and `Radar` services.
|
||||
*/
|
||||
export type RadarServices = LangiumCoreServices & RadarAddedServices;
|
||||
|
||||
/**
|
||||
* Dependency injection module that overrides Langium default services and
|
||||
* contributes the declared `Radar` services.
|
||||
*/
|
||||
export const RadarModule: Module<RadarServices, PartialLangiumCoreServices & RadarAddedServices> = {
|
||||
parser: {
|
||||
TokenBuilder: () => new RadarTokenBuilder(),
|
||||
ValueConverter: () => new CommonValueConverter(),
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the full set of services required by Langium.
|
||||
*
|
||||
* First inject the shared services by merging two modules:
|
||||
* - Langium default shared services
|
||||
* - Services generated by langium-cli
|
||||
*
|
||||
* Then inject the language-specific services by merging three modules:
|
||||
* - Langium default language-specific services
|
||||
* - Services generated by langium-cli
|
||||
* - Services specified in this file
|
||||
* @param context - Optional module context with the LSP connection
|
||||
* @returns An object wrapping the shared services and the language-specific services
|
||||
*/
|
||||
export function createRadarServices(context: DefaultSharedCoreModuleContext = EmptyFileSystem): {
|
||||
shared: LangiumSharedCoreServices;
|
||||
Radar: RadarServices;
|
||||
} {
|
||||
const shared: LangiumSharedCoreServices = inject(
|
||||
createDefaultSharedCoreModule(context),
|
||||
MermaidGeneratedSharedModule
|
||||
);
|
||||
const Radar: RadarServices = inject(
|
||||
createDefaultCoreModule({ shared }),
|
||||
RadarGeneratedModule,
|
||||
RadarModule
|
||||
);
|
||||
shared.ServiceRegistry.register(Radar);
|
||||
return { shared, Radar };
|
||||
}
|
55
packages/parser/src/language/radar/radar.langium
Normal file
55
packages/parser/src/language/radar/radar.langium
Normal file
@@ -0,0 +1,55 @@
|
||||
grammar Radar
|
||||
import "../common/common";
|
||||
|
||||
entry Radar:
|
||||
NEWLINE*
|
||||
('radar-beta' | 'radar-beta:' | 'radar-beta' ':')
|
||||
NEWLINE*
|
||||
(
|
||||
TitleAndAccessibilities
|
||||
| 'axis' axes+=Axis (',' axes+=Axis)*
|
||||
| 'curve' curves+=Curve (',' curves+=Curve)*
|
||||
| options+=Option (',' options+=Option)*
|
||||
| NEWLINE
|
||||
)*
|
||||
;
|
||||
|
||||
fragment Label:
|
||||
'[' label=STRING ']'
|
||||
;
|
||||
|
||||
Axis:
|
||||
name=ID (Label)?
|
||||
;
|
||||
|
||||
Curve:
|
||||
name=ID (Label)? '{' Entries '}'
|
||||
;
|
||||
|
||||
fragment Entries:
|
||||
NEWLINE* entries+=NumberEntry (',' NEWLINE* entries+=NumberEntry)* NEWLINE* |
|
||||
NEWLINE* entries+=DetailedEntry (',' NEWLINE* entries+=DetailedEntry)* NEWLINE*
|
||||
;
|
||||
|
||||
interface Entry {
|
||||
axis?: @Axis;
|
||||
value: number;
|
||||
}
|
||||
DetailedEntry returns Entry:
|
||||
axis=[Axis:ID] ':'? value=NUMBER
|
||||
;
|
||||
NumberEntry returns Entry:
|
||||
value=NUMBER
|
||||
;
|
||||
|
||||
Option:
|
||||
(
|
||||
name='showLegend' value=BOOLEAN
|
||||
| name='ticks' value=NUMBER
|
||||
| name='max' value=NUMBER
|
||||
| name='min' value=NUMBER
|
||||
| name='graticule' value=GRATICULE
|
||||
)
|
||||
;
|
||||
|
||||
terminal GRATICULE returns string: 'circle' | 'polygon';
|
7
packages/parser/src/language/radar/tokenBuilder.ts
Normal file
7
packages/parser/src/language/radar/tokenBuilder.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { AbstractMermaidTokenBuilder } from '../common/index.js';
|
||||
|
||||
export class RadarTokenBuilder extends AbstractMermaidTokenBuilder {
|
||||
public constructor() {
|
||||
super(['radar-beta']);
|
||||
}
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
import type { LangiumParser, ParseResult } from 'langium';
|
||||
|
||||
import type { Info, Packet, Pie, Architecture, GitGraph } from './index.js';
|
||||
import type { Info, Packet, Pie, Architecture, GitGraph, Radar } from './index.js';
|
||||
|
||||
export type DiagramAST = Info | Packet | Pie | Architecture | GitGraph;
|
||||
export type DiagramAST = Info | Packet | Pie | Architecture | GitGraph | Radar;
|
||||
|
||||
const parsers: Record<string, LangiumParser> = {};
|
||||
const initializers = {
|
||||
@@ -31,6 +31,11 @@ const initializers = {
|
||||
const parser = createGitGraphServices().GitGraph.parser.LangiumParser;
|
||||
parsers.gitGraph = parser;
|
||||
},
|
||||
radar: async () => {
|
||||
const { createRadarServices } = await import('./language/radar/index.js');
|
||||
const parser = createRadarServices().Radar.parser.LangiumParser;
|
||||
parsers.radar = parser;
|
||||
},
|
||||
} as const;
|
||||
|
||||
export async function parse(diagramType: 'info', text: string): Promise<Info>;
|
||||
@@ -38,6 +43,7 @@ export async function parse(diagramType: 'packet', text: string): Promise<Packet
|
||||
export async function parse(diagramType: 'pie', text: string): Promise<Pie>;
|
||||
export async function parse(diagramType: 'architecture', text: string): Promise<Architecture>;
|
||||
export async function parse(diagramType: 'gitGraph', text: string): Promise<GitGraph>;
|
||||
export async function parse(diagramType: 'radar', text: string): Promise<Radar>;
|
||||
|
||||
export async function parse<T extends DiagramAST>(
|
||||
diagramType: keyof typeof initializers,
|
||||
|
88
packages/parser/tests/architecture.test.ts
Normal file
88
packages/parser/tests/architecture.test.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { Architecture } from '../src/language/index.js';
|
||||
import { expectNoErrorsOrAlternatives, architectureParse as parse } from './test-util.js';
|
||||
|
||||
describe('architecture', () => {
|
||||
describe('should handle architecture definition', () => {
|
||||
it.each([
|
||||
`architecture-beta`,
|
||||
` architecture-beta `,
|
||||
`\tarchitecture-beta\t`,
|
||||
`
|
||||
\tarchitecture-beta
|
||||
`,
|
||||
])('should handle regular architecture', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle TitleAndAccessibilities', () => {
|
||||
it.each([
|
||||
`architecture-beta title sample title`,
|
||||
` architecture-beta title sample title `,
|
||||
`\tarchitecture-beta\ttitle sample title\t`,
|
||||
`architecture-beta
|
||||
\ttitle sample title
|
||||
`,
|
||||
])('should handle regular architecture + title in same line', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
|
||||
const { title } = result.value;
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
|
||||
it.each([
|
||||
`architecture-beta
|
||||
title sample title`,
|
||||
`architecture-beta
|
||||
title sample title
|
||||
`,
|
||||
])('should handle regular architecture + title in next line', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
|
||||
const { title } = result.value;
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
|
||||
it('should handle regular architecture + title + accTitle + accDescr', () => {
|
||||
const context = `architecture-beta
|
||||
title sample title
|
||||
accTitle: sample accTitle
|
||||
accDescr: sample accDescr
|
||||
`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
|
||||
const { title, accTitle, accDescr } = result.value;
|
||||
expect(title).toBe('sample title');
|
||||
expect(accTitle).toBe('sample accTitle');
|
||||
expect(accDescr).toBe('sample accDescr');
|
||||
});
|
||||
|
||||
it('should handle regular architecture + title + accTitle + multi-line accDescr', () => {
|
||||
const context = `architecture-beta
|
||||
title sample title
|
||||
accTitle: sample accTitle
|
||||
accDescr {
|
||||
sample accDescr
|
||||
}
|
||||
`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Architecture);
|
||||
|
||||
const { title, accTitle, accDescr } = result.value;
|
||||
expect(title).toBe('sample title');
|
||||
expect(accTitle).toBe('sample accTitle');
|
||||
expect(accDescr).toBe('sample accDescr');
|
||||
});
|
||||
});
|
||||
});
|
@@ -63,6 +63,12 @@ describe('Parsing Branch Statements', () => {
|
||||
expect(branch.name).toBe('master');
|
||||
});
|
||||
|
||||
it('should parse a branch name starting with numbers', () => {
|
||||
const result = parse(`gitGraph\n commit\n branch 1.0.1\n`);
|
||||
const branch = result.value.statements[1] as Branch;
|
||||
expect(branch.name).toBe('1.0.1');
|
||||
});
|
||||
|
||||
it('should parse a branch with an order property', () => {
|
||||
const result = parse(`gitGraph\n commit\n branch feature order:1\n`);
|
||||
const branch = result.value.statements[1] as Branch;
|
||||
|
19
packages/parser/tests/packet.test.ts
Normal file
19
packages/parser/tests/packet.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { Packet } from '../src/language/index.js';
|
||||
import { expectNoErrorsOrAlternatives, packetParse as parse } from './test-util.js';
|
||||
|
||||
describe('packet', () => {
|
||||
it.each([
|
||||
`packet-beta`,
|
||||
` packet-beta `,
|
||||
`\tpacket-beta\t`,
|
||||
`
|
||||
\tpacket-beta
|
||||
`,
|
||||
])('should handle regular packet', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Packet);
|
||||
});
|
||||
});
|
@@ -4,226 +4,247 @@ import { Pie } from '../src/language/index.js';
|
||||
import { expectNoErrorsOrAlternatives, pieParse as parse } from './test-util.js';
|
||||
|
||||
describe('pie', () => {
|
||||
it.each([
|
||||
`pie`,
|
||||
` pie `,
|
||||
`\tpie\t`,
|
||||
`
|
||||
describe('should handle pie definition with or without showData', () => {
|
||||
it.each([
|
||||
`pie`,
|
||||
` pie `,
|
||||
`\tpie\t`,
|
||||
`
|
||||
\tpie
|
||||
`,
|
||||
])('should handle regular pie', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
});
|
||||
])('should handle regular pie', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
});
|
||||
|
||||
it.each([
|
||||
`pie showData`,
|
||||
` pie showData `,
|
||||
`\tpie\tshowData\t`,
|
||||
`
|
||||
it.each([
|
||||
`pie showData`,
|
||||
` pie showData `,
|
||||
`\tpie\tshowData\t`,
|
||||
`
|
||||
pie\tshowData
|
||||
`,
|
||||
])('should handle regular showData', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
])('should handle regular showData', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { showData } = result.value;
|
||||
expect(showData).toBeTruthy();
|
||||
const { showData } = result.value;
|
||||
expect(showData).toBeTruthy();
|
||||
});
|
||||
});
|
||||
describe('should handle TitleAndAccessibilities', () => {
|
||||
describe('should handle TitleAndAccessibilities without showData', () => {
|
||||
it.each([
|
||||
`pie title sample title`,
|
||||
` pie title sample title `,
|
||||
`\tpie\ttitle sample title\t`,
|
||||
`pie
|
||||
\ttitle sample title
|
||||
`,
|
||||
])('should handle regular pie + title in same line', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
it.each([
|
||||
`pie title sample title`,
|
||||
` pie title sample title `,
|
||||
`\tpie\ttitle sample title\t`,
|
||||
`pie
|
||||
\ttitle sample title
|
||||
`,
|
||||
])('should handle regular pie + title in same line', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
const { title } = result.value;
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
|
||||
const { title } = result.value;
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
|
||||
it.each([
|
||||
`pie
|
||||
title sample title`,
|
||||
`pie
|
||||
title sample title
|
||||
`,
|
||||
`pie
|
||||
title sample title`,
|
||||
`pie
|
||||
title sample title
|
||||
`,
|
||||
])('should handle regular pie + title in different line', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { title } = result.value;
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
|
||||
it.each([
|
||||
`pie showData title sample title`,
|
||||
`pie showData title sample title
|
||||
`,
|
||||
])('should handle regular pie + showData + title', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { showData, title } = result.value;
|
||||
expect(showData).toBeTruthy();
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
|
||||
it.each([
|
||||
`pie showData
|
||||
title sample title`,
|
||||
`pie showData
|
||||
title sample title
|
||||
`,
|
||||
`pie showData
|
||||
title sample title`,
|
||||
`pie showData
|
||||
title sample title
|
||||
`,
|
||||
])('should handle regular showData + title in different line', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { showData, title } = result.value;
|
||||
expect(showData).toBeTruthy();
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
|
||||
describe('sections', () => {
|
||||
describe('normal', () => {
|
||||
it.each([
|
||||
`pie
|
||||
title sample title`,
|
||||
`pie
|
||||
title sample title
|
||||
`,
|
||||
`pie
|
||||
title sample title`,
|
||||
`pie
|
||||
title sample title
|
||||
`,
|
||||
])('should handle regular pie + title in different line', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { title } = result.value;
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle TitleAndAccessibilities with showData', () => {
|
||||
it.each([
|
||||
`pie showData title sample title`,
|
||||
`pie showData title sample title
|
||||
`,
|
||||
])('should handle regular pie + showData + title', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { showData, title } = result.value;
|
||||
expect(showData).toBeTruthy();
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
|
||||
it.each([
|
||||
`pie showData
|
||||
title sample title`,
|
||||
`pie showData
|
||||
title sample title
|
||||
`,
|
||||
`pie showData
|
||||
title sample title`,
|
||||
`pie showData
|
||||
title sample title
|
||||
`,
|
||||
])('should handle regular showData + title in different line', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { showData, title } = result.value;
|
||||
expect(showData).toBeTruthy();
|
||||
expect(title).toBe('sample title');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle sections', () => {
|
||||
it.each([
|
||||
`pie
|
||||
"GitHub":100
|
||||
"GitLab":50`,
|
||||
`pie
|
||||
`pie
|
||||
"GitHub" : 100
|
||||
"GitLab" : 50`,
|
||||
`pie
|
||||
`pie
|
||||
"GitHub"\t:\t100
|
||||
"GitLab"\t:\t50`,
|
||||
`pie
|
||||
`pie
|
||||
\t"GitHub" \t : \t 100
|
||||
\t"GitLab" \t : \t 50
|
||||
`,
|
||||
])('should handle regular sections', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
])('should handle regular sections', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { sections } = result.value;
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
const { sections } = result.value;
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
|
||||
it('should handle sections with showData', () => {
|
||||
const context = `pie showData
|
||||
it('should handle sections with showData', () => {
|
||||
const context = `pie showData
|
||||
"GitHub": 100
|
||||
"GitLab": 50`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { showData, sections } = result.value;
|
||||
expect(showData).toBeTruthy();
|
||||
const { showData, sections } = result.value;
|
||||
expect(showData).toBeTruthy();
|
||||
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
|
||||
it('should handle sections with title', () => {
|
||||
const context = `pie title sample wow
|
||||
it('should handle sections with title', () => {
|
||||
const context = `pie title sample wow
|
||||
"GitHub": 100
|
||||
"GitLab": 50`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { title, sections } = result.value;
|
||||
expect(title).toBe('sample wow');
|
||||
const { title, sections } = result.value;
|
||||
expect(title).toBe('sample wow');
|
||||
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
|
||||
it('should handle sections with accTitle', () => {
|
||||
const context = `pie accTitle: sample wow
|
||||
it('should handle value with positive decimal', () => {
|
||||
const context = `pie
|
||||
"ash": 60.67
|
||||
"bat": 40`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { sections } = result.value;
|
||||
expect(sections[0].label).toBe('ash');
|
||||
expect(sections[0].value).toBe(60.67);
|
||||
|
||||
expect(sections[1].label).toBe('bat');
|
||||
expect(sections[1].value).toBe(40);
|
||||
});
|
||||
|
||||
it('should handle sections with accTitle', () => {
|
||||
const context = `pie accTitle: sample wow
|
||||
"GitHub": 100
|
||||
"GitLab": 50`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { accTitle, sections } = result.value;
|
||||
expect(accTitle).toBe('sample wow');
|
||||
const { accTitle, sections } = result.value;
|
||||
expect(accTitle).toBe('sample wow');
|
||||
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
|
||||
it('should handle sections with single line accDescr', () => {
|
||||
const context = `pie accDescr: sample wow
|
||||
it('should handle sections with single line accDescr', () => {
|
||||
const context = `pie accDescr: sample wow
|
||||
"GitHub": 100
|
||||
"GitLab": 50`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { accDescr, sections } = result.value;
|
||||
expect(accDescr).toBe('sample wow');
|
||||
const { accDescr, sections } = result.value;
|
||||
expect(accDescr).toBe('sample wow');
|
||||
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
|
||||
it('should handle sections with multi line accDescr', () => {
|
||||
const context = `pie accDescr {
|
||||
it('should handle sections with multi line accDescr', () => {
|
||||
const context = `pie accDescr {
|
||||
sample wow
|
||||
}
|
||||
"GitHub": 100
|
||||
"GitLab": 50`;
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Pie);
|
||||
|
||||
const { accDescr, sections } = result.value;
|
||||
expect(accDescr).toBe('sample wow');
|
||||
const { accDescr, sections } = result.value;
|
||||
expect(accDescr).toBe('sample wow');
|
||||
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
expect(sections[0].label).toBe('GitHub');
|
||||
expect(sections[0].value).toBe(100);
|
||||
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
expect(sections[1].label).toBe('GitLab');
|
||||
expect(sections[1].value).toBe(50);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
343
packages/parser/tests/radar.test.ts
Normal file
343
packages/parser/tests/radar.test.ts
Normal file
@@ -0,0 +1,343 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { Radar } from '../src/language/index.js';
|
||||
import { expectNoErrorsOrAlternatives, radarParse as parse } from './test-util.js';
|
||||
|
||||
const mutateGlobalSpacing = (context: string) => {
|
||||
return [
|
||||
context,
|
||||
` ${context} `,
|
||||
`\t${context}\t`,
|
||||
`
|
||||
\t${context}
|
||||
`,
|
||||
];
|
||||
};
|
||||
|
||||
describe('radar', () => {
|
||||
it.each([
|
||||
...mutateGlobalSpacing('radar-beta'),
|
||||
...mutateGlobalSpacing('radar-beta:'),
|
||||
...mutateGlobalSpacing('radar-beta :'),
|
||||
])('should handle regular radar', (context: string) => {
|
||||
const result = parse(context);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
});
|
||||
|
||||
describe('should handle title, accDescr, and accTitle', () => {
|
||||
it.each([
|
||||
...mutateGlobalSpacing(' title My Title'),
|
||||
...mutateGlobalSpacing('\n title My Title'),
|
||||
])('should handle title', (context: string) => {
|
||||
const result = parse(`radar-beta${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { title } = result.value;
|
||||
expect(title).toBe('My Title');
|
||||
});
|
||||
|
||||
it.each([
|
||||
...mutateGlobalSpacing(' accDescr: My Accessible Description'),
|
||||
...mutateGlobalSpacing('\n accDescr: My Accessible Description'),
|
||||
])('should handle accDescr', (context: string) => {
|
||||
const result = parse(`radar-beta${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { accDescr } = result.value;
|
||||
expect(accDescr).toBe('My Accessible Description');
|
||||
});
|
||||
|
||||
it.each([
|
||||
...mutateGlobalSpacing(' accTitle: My Accessible Title'),
|
||||
...mutateGlobalSpacing('\n accTitle: My Accessible Title'),
|
||||
])('should handle accTitle', (context: string) => {
|
||||
const result = parse(`radar-beta${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { accTitle } = result.value;
|
||||
expect(accTitle).toBe('My Accessible Title');
|
||||
});
|
||||
|
||||
it.each([
|
||||
...mutateGlobalSpacing(
|
||||
' title My Title\n accDescr: My Accessible Description\n accTitle: My Accessible Title'
|
||||
),
|
||||
...mutateGlobalSpacing(
|
||||
'\n title My Title\n accDescr: My Accessible Description\n accTitle: My Accessible Title'
|
||||
),
|
||||
])('should handle title + accDescr + accTitle', (context: string) => {
|
||||
const result = parse(`radar-beta${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { title, accDescr, accTitle } = result.value;
|
||||
expect(title).toBe('My Title');
|
||||
expect(accDescr).toBe('My Accessible Description');
|
||||
expect(accTitle).toBe('My Accessible Title');
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle axis', () => {
|
||||
it.each([`axis my-axis`, `axis my-axis["My Axis Label"]`])(
|
||||
'should handle one axis',
|
||||
(context: string) => {
|
||||
const result = parse(`radar-beta\n${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { axes } = result.value;
|
||||
expect(axes).toHaveLength(1);
|
||||
expect(axes[0].$type).toBe('Axis');
|
||||
expect(axes[0].name).toBe('my-axis');
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
`axis my-axis["My Axis Label"]
|
||||
axis my-axis2`,
|
||||
`axis my-axis, my-axis2`,
|
||||
`axis my-axis["My Axis Label"], my-axis2`,
|
||||
`axis my-axis, my-axis2["My Second Axis Label"]`,
|
||||
])('should handle multiple axes', (context: string) => {
|
||||
const result = parse(`radar-beta\n${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { axes } = result.value;
|
||||
expect(axes).toHaveLength(2);
|
||||
expect(axes.every((axis) => axis.$type === 'Axis')).toBe(true);
|
||||
expect(axes[0].name).toBe('my-axis');
|
||||
expect(axes[1].name).toBe('my-axis2');
|
||||
});
|
||||
|
||||
it.each([
|
||||
`axis my-axis["My Axis Label"]
|
||||
axis my-axis2["My Second Axis Label"]`,
|
||||
`axis my-axis ["My Axis Label"], my-axis2\t["My Second Axis Label"]`,
|
||||
])('should handle axis labels', (context: string) => {
|
||||
const result = parse(`radar-beta\n${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { axes } = result.value;
|
||||
expect(axes).toHaveLength(2);
|
||||
expect(axes[0].name).toBe('my-axis');
|
||||
expect(axes[0].label).toBe('My Axis Label');
|
||||
expect(axes[1].name).toBe('my-axis2');
|
||||
expect(axes[1].label).toBe('My Second Axis Label');
|
||||
});
|
||||
|
||||
it('should not allow empty axis names', () => {
|
||||
const result = parse(`radar-beta
|
||||
axis`);
|
||||
expect(result.parserErrors).not.toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should not allow non-comma separated axis names', () => {
|
||||
const result = parse(`radar-beta
|
||||
axis my-axis my-axis2`);
|
||||
expect(result.parserErrors).not.toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle curves', () => {
|
||||
it.each([
|
||||
`radar-beta
|
||||
curve my-curve`,
|
||||
`radar-beta
|
||||
curve my-curve["My Curve Label"]`,
|
||||
])('should not allow curves without axes', (context: string) => {
|
||||
const result = parse(`radar-beta${context}`);
|
||||
expect(result.parserErrors).not.toHaveLength(0);
|
||||
});
|
||||
|
||||
it.each([
|
||||
`radar-beta
|
||||
axis my-axis
|
||||
curve my-curve`,
|
||||
`radar-beta
|
||||
axis my-axis
|
||||
curve my-curve["My Curve Label"]`,
|
||||
])('should not allow curves without entries', (context: string) => {
|
||||
const result = parse(`radar-beta${context}`);
|
||||
expect(result.parserErrors).not.toHaveLength(0);
|
||||
});
|
||||
|
||||
it.each([
|
||||
`curve my-curve { 1 }`,
|
||||
`curve my-curve {
|
||||
1
|
||||
}`,
|
||||
`curve my-curve {
|
||||
|
||||
1
|
||||
|
||||
}`,
|
||||
])('should handle one curve with one entry', (context: string) => {
|
||||
const result = parse(`radar-beta\naxis my-axis\n${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { curves } = result.value;
|
||||
expect(curves).toHaveLength(1);
|
||||
expect(curves[0].$type).toBe('Curve');
|
||||
expect(curves[0].name).toBe('my-curve');
|
||||
expect(curves[0].entries).toHaveLength(1);
|
||||
expect(curves[0].entries[0].$type).toBe('Entry');
|
||||
expect(curves[0].entries[0].value).toBe(1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
`curve my-curve { my-axis 1 }`,
|
||||
`curve my-curve { my-axis : 1 }`,
|
||||
`curve my-curve {
|
||||
my-axis: 1
|
||||
}`,
|
||||
])('should handle one curve with one detailed entry', (context: string) => {
|
||||
const result = parse(`radar-beta\naxis my-axis\n${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { curves } = result.value;
|
||||
expect(curves).toHaveLength(1);
|
||||
expect(curves[0].$type).toBe('Curve');
|
||||
expect(curves[0].name).toBe('my-curve');
|
||||
expect(curves[0].entries).toHaveLength(1);
|
||||
expect(curves[0].entries[0].$type).toBe('Entry');
|
||||
expect(curves[0].entries[0].value).toBe(1);
|
||||
expect(curves[0].entries[0]?.axis?.$refText).toBe('my-axis');
|
||||
});
|
||||
|
||||
it.each([
|
||||
`curve my-curve { ax1 1, ax2 2 }`,
|
||||
`curve my-curve {
|
||||
ax1 1,
|
||||
ax2 2
|
||||
}`,
|
||||
`curve my-curve["My Curve Label"] {
|
||||
ax1: 1, ax2: 2
|
||||
}`,
|
||||
])('should handle one curve with multiple detailed entries', (context: string) => {
|
||||
const result = parse(`radar-beta\naxis ax1, ax1\n${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { curves } = result.value;
|
||||
expect(curves).toHaveLength(1);
|
||||
expect(curves[0].$type).toBe('Curve');
|
||||
expect(curves[0].name).toBe('my-curve');
|
||||
expect(curves[0].entries).toHaveLength(2);
|
||||
expect(curves[0].entries[0].$type).toBe('Entry');
|
||||
expect(curves[0].entries[0].value).toBe(1);
|
||||
expect(curves[0].entries[0]?.axis?.$refText).toBe('ax1');
|
||||
expect(curves[0].entries[1].$type).toBe('Entry');
|
||||
expect(curves[0].entries[1].value).toBe(2);
|
||||
expect(curves[0].entries[1]?.axis?.$refText).toBe('ax2');
|
||||
});
|
||||
|
||||
it.each([
|
||||
`curve c1 { ax1 1, ax2 2 }
|
||||
curve c2 { ax1 3, ax2 4 }`,
|
||||
`curve c1 {
|
||||
ax1 1,
|
||||
ax2 2
|
||||
}
|
||||
curve c2 {
|
||||
ax1 3,
|
||||
ax2 4
|
||||
}`,
|
||||
`curve c1{ 1, 2 }, c2{ 3, 4 }`,
|
||||
])('should handle multiple curves', (context: string) => {
|
||||
const result = parse(`radar-beta\naxis ax1, ax1\n${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { curves } = result.value;
|
||||
expect(curves).toHaveLength(2);
|
||||
expect(curves.every((curve) => curve.$type === 'Curve')).toBe(true);
|
||||
expect(curves[0].name).toBe('c1');
|
||||
expect(curves[1].name).toBe('c2');
|
||||
});
|
||||
|
||||
it('should not allow empty curve names', () => {
|
||||
const result = parse(`radar-beta
|
||||
axis my-axis
|
||||
curve`);
|
||||
expect(result.parserErrors).not.toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should not allow number and detailed entries in the same curve', () => {
|
||||
const result = parse(`radar-beta
|
||||
axis ax1, ax2
|
||||
curve my-curve { 1, ax1 2 }`);
|
||||
expect(result.parserErrors).not.toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should not allow non-comma separated entries', () => {
|
||||
const result = parse(`radar-beta
|
||||
axis ax1, ax2
|
||||
curve my-curve { ax1 1 ax2 2 }`);
|
||||
expect(result.parserErrors).not.toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle options', () => {
|
||||
it.each([`ticks 5`, `min 50`, `max 50`])(
|
||||
`should handle number option %s`,
|
||||
(context: string) => {
|
||||
const result = parse(`radar-beta
|
||||
axis ax1, ax2
|
||||
curve c1 { ax1 1, ax2 2 }
|
||||
${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { options } = result.value;
|
||||
expect(options).toBeDefined();
|
||||
const option = options.find((option) => option.name === context.split(' ')[0]);
|
||||
expect(option).toBeDefined();
|
||||
expect(option?.value).toBe(Number(context.split(' ')[1]));
|
||||
}
|
||||
);
|
||||
|
||||
it.each([`graticule circle`, `graticule polygon`])(
|
||||
`should handle string option %s`,
|
||||
(context: string) => {
|
||||
const result = parse(`radar-beta
|
||||
axis ax1, ax2
|
||||
curve c1 { ax1 1, ax2 2 }
|
||||
${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { options } = result.value;
|
||||
expect(options).toBeDefined();
|
||||
const option = options.find((option) => option.name === context.split(' ')[0]);
|
||||
expect(option).toBeDefined();
|
||||
expect(option?.value).toBe(context.split(' ')[1]);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([`showLegend true`, `showLegend false`])(
|
||||
`should handle boolean option %s`,
|
||||
(context: string) => {
|
||||
const result = parse(`radar-beta
|
||||
axis ax1, ax2
|
||||
curve c1 { ax1 1, ax2 2 }
|
||||
${context}`);
|
||||
expectNoErrorsOrAlternatives(result);
|
||||
expect(result.value.$type).toBe(Radar);
|
||||
|
||||
const { options } = result.value;
|
||||
expect(options).toBeDefined();
|
||||
const option = options.find((option) => option.name === context.split(' ')[0]);
|
||||
expect(option).toBeDefined();
|
||||
expect(option?.value).toBe(context.split(' ')[1] === 'true');
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
@@ -1,16 +1,25 @@
|
||||
import type { LangiumParser, ParseResult } from 'langium';
|
||||
import { expect, vi } from 'vitest';
|
||||
import type {
|
||||
Architecture,
|
||||
ArchitectureServices,
|
||||
Info,
|
||||
InfoServices,
|
||||
Pie,
|
||||
PieServices,
|
||||
Radar,
|
||||
RadarServices,
|
||||
Packet,
|
||||
PacketServices,
|
||||
GitGraph,
|
||||
GitGraphServices,
|
||||
} from '../src/language/index.js';
|
||||
import {
|
||||
createArchitectureServices,
|
||||
createInfoServices,
|
||||
createPieServices,
|
||||
createRadarServices,
|
||||
createPacketServices,
|
||||
createGitGraphServices,
|
||||
} from '../src/language/index.js';
|
||||
|
||||
@@ -41,6 +50,17 @@ export function createInfoTestServices() {
|
||||
}
|
||||
export const infoParse = createInfoTestServices().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;
|
||||
|
||||
const pieServices: PieServices = createPieServices().Pie;
|
||||
const pieParser: LangiumParser = pieServices.parser.LangiumParser;
|
||||
export function createPieTestServices() {
|
||||
@@ -52,6 +72,28 @@ export function createPieTestServices() {
|
||||
}
|
||||
export const pieParse = createPieTestServices().parse;
|
||||
|
||||
const packetServices: PacketServices = createPacketServices().Packet;
|
||||
const packetParser: LangiumParser = packetServices.parser.LangiumParser;
|
||||
export function createPacketTestServices() {
|
||||
const parse = (input: string) => {
|
||||
return packetParser.parse<Packet>(input);
|
||||
};
|
||||
|
||||
return { services: packetServices, parse };
|
||||
}
|
||||
export const packetParse = createPacketTestServices().parse;
|
||||
|
||||
const radarServices: RadarServices = createRadarServices().Radar;
|
||||
const radarParser: LangiumParser = radarServices.parser.LangiumParser;
|
||||
export function createRadarTestServices() {
|
||||
const parse = (input: string) => {
|
||||
return radarParser.parse<Radar>(input);
|
||||
};
|
||||
|
||||
return { services: radarServices, parse };
|
||||
}
|
||||
export const radarParse = createRadarTestServices().parse;
|
||||
|
||||
const gitGraphServices: GitGraphServices = createGitGraphServices().GitGraph;
|
||||
const gitGraphParser: LangiumParser = gitGraphServices.parser.LangiumParser;
|
||||
export function createGitGraphTestServices() {
|
||||
|
Reference in New Issue
Block a user