forked from mermaid-js/mermaid
-
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.
Co-authored-by: Ashley Engelund (weedySeaDragon @ github) <[email protected]> Signed-off-by: Reda Al Sulais <[email protected]>
- Loading branch information
1 parent
125ec46
commit c9f6816
Showing
4 changed files
with
75 additions
and
12 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
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
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,50 @@ | ||
import { beforeAll, describe, expect, it } from 'vitest'; | ||
import type { TokenType, TokenVocabulary } from 'chevrotain'; | ||
|
||
import { sankeyServices } from './test-util.js'; | ||
|
||
describe('SankeyTokenBuilder', () => { | ||
describe('token order', () => { | ||
let tokenVocab: TokenVocabulary; | ||
let tokenVocabNames: string[]; | ||
|
||
beforeAll(() => { | ||
// Get the ordered tokens (the vocabulary) from the grammar | ||
tokenVocab = sankeyServices.parser.TokenBuilder.buildTokens(sankeyServices.Grammar, { | ||
caseInsensitive: sankeyServices.LanguageMetaData.caseInsensitive, | ||
}); | ||
// coerce the tokenVocab to a type that can use .map | ||
tokenVocabNames = (tokenVocab as TokenType[]).map((tokenVocabEntry: TokenType) => { | ||
return tokenVocabEntry.name; | ||
}); | ||
}); | ||
|
||
it('whitespace is always first', () => { | ||
expect(tokenVocabNames[0]).toEqual('WHITESPACE'); | ||
}); | ||
it('sankey-beta comes after whitespace', () => { | ||
expect(tokenVocabNames[1]).toEqual('sankey-beta'); | ||
}); | ||
|
||
describe('terminal rules with @greedy in comments are put at the end of the ordered list of tokens', () => { | ||
const NUM_EXPECTED_GREEDY_RULES = 2; | ||
|
||
let greedyGroupStartIndex = 0; | ||
beforeAll(() => { | ||
greedyGroupStartIndex = tokenVocabNames.length - NUM_EXPECTED_GREEDY_RULES - 1; | ||
}); | ||
|
||
it('SANKEY_LINK_NODE rule has @greedy so it is in the last group of all @greedy terminal rules', () => { | ||
expect(tokenVocabNames.indexOf('SANKEY_LINK_NODE')).toBeGreaterThanOrEqual( | ||
greedyGroupStartIndex | ||
); | ||
}); | ||
|
||
it('SANKEY_LINK_VALUE rule has @greedy so it is in the last group of all @greedy terminal rules', () => { | ||
expect(tokenVocabNames.indexOf('SANKEY_LINK_VALUE')).toBeGreaterThanOrEqual( | ||
Check failure on line 44 in packages/parser/tests/sankey-tokenBuilder.test.ts GitHub Actions / unit-testpackages/parser/tests/sankey-tokenBuilder.test.ts > SankeyTokenBuilder > token order > terminal rules with @greedy in comments are put at the end of the ordered list of tokens > SANKEY_LINK_VALUE rule has @greedy so it is in the last group of all @greedy terminal rules
|
||
greedyGroupStartIndex | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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