Skip to content

Commit

Permalink
test(common): add title test cases (#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Yokozuna59 <u.yokozuna@gmail.com>
  • Loading branch information
Yokozuna59 authored May 25, 2023
1 parent 34909ee commit a049582
Showing 1 changed file with 174 additions and 0 deletions.
174 changes: 174 additions & 0 deletions packages/mermaid-parser/tests/common/title.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import { LangiumDocument, createServicesForGrammar } from 'langium';
import { parseHelper } from 'langium/lib/test';
import { beforeAll, describe, expect, it } from 'vitest';

import {
Mermaid,
MermaidGrammar,
MermiadTokenBuilder,
} from '../../src/language';

describe('title', () => {
let parser: (input: string) => Promise<LangiumDocument<Mermaid>>;

beforeAll(async () => {
const services = await createServicesForGrammar({
grammar: MermaidGrammar(),
module: {
parser: {
TokenBuilder: () => new MermiadTokenBuilder(),
},
},
});
parser = parseHelper<Mermaid>(services);
});

describe('normal', () => {
it.each([
// without whitespaces
`pie title`,

// with spaces
`pie title `,

// with tabs
`pie\title\t`,

// with extra whitespaces
`pie
title\t
`,
])('should handle empty title', async (string_: string) => {
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBeUndefined();
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});

it.each([
// without whitespaces
`pie title sample`,

// with spaces
`pie title sample `,

// with tabs
`pie\ttitle\tsample\t`,

// with extra whitespaces
`pie
title\t sample
`,
])('should handle regular title', async (string_: string) => {
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBe('sample');
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});

it.todo('should handle title with accTitle', async () => {
const string_ = `pie title sample + accTitle: test`;
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBe('sample + accTitle: test');
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});

it.todo('should handle title with single line accDescr', async () => {
const string_ = `pie title sample + accDescr: test`;
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBe('sample + accDescr: test');
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});

it.todo('should handle title with multi line accDescr', async () => {
const string_ = `pie title sample + accDescr {test}`;
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBe('sample + accDescr {test}');
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});
});

describe('duplicate', () => {
describe('inside', () => {
it('should handle title inside title', async () => {
const string_ = `pie title title test`;
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBe('title test');
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});
});

describe('after', () => {
it('should handle regular title after empty title', async () => {
const string_ = `pie title:
title sample`;
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBe('sample');
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});

it('should handle empty title after regular title', async () => {
const string_ = `pie title sample
title`;
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBeUndefined();
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});

it('should handle regular title after regular title', async () => {
const string_ = `pie title test
title sample`;
const { parseResult: result } = await parser(string_);
expect(result.parserErrors).toHaveLength(0);
expect(result.lexerErrors).toHaveLength(0);

const value = result.value;
expect(value.title).toBe('sample');
expect(value.accDescr).toBeUndefined();
expect(value.accTitle).toBeUndefined();
});
});
});
});

0 comments on commit a049582

Please sign in to comment.