-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(common): add title test cases (#74)
Signed-off-by: Yokozuna59 <u.yokozuna@gmail.com>
- Loading branch information
1 parent
34909ee
commit a049582
Showing
1 changed file
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); |