-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4338 from mermaid-js/sidv/fixClassGrammar
fix ClassGrammar
- Loading branch information
Showing
6 changed files
with
102 additions
and
18 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
13 changes: 0 additions & 13 deletions
13
packages/mermaid/src/diagrams/class/classDiagramGrammar.spec.js
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/mermaid/src/diagrams/class/classDiagramGrammar.spec.ts
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,16 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
// @ts-ignore - no types | ||
import { LALRGenerator } from 'jison'; | ||
import path from 'path'; | ||
|
||
const getAbsolutePath = (relativePath: string) => { | ||
return new URL(path.join(path.dirname(import.meta.url), relativePath)).pathname; | ||
}; | ||
|
||
describe('class diagram grammar', function () { | ||
it('should have no conflicts', async function () { | ||
const grammarSource = await readFile(getAbsolutePath('./parser/classDiagram.jison'), 'utf8'); | ||
const grammarParser = new LALRGenerator(grammarSource, {}); | ||
expect(grammarParser.conflicts).toBe(0); | ||
}); | ||
}); |
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,78 @@ | ||
import { setConfig } from '../../config.js'; | ||
import classDB from './classDb.js'; | ||
// @ts-ignore - no types in jison | ||
import classDiagram from './parser/classDiagram.jison'; | ||
|
||
setConfig({ | ||
securityLevel: 'strict', | ||
}); | ||
|
||
describe('when parsing class diagram', function () { | ||
beforeEach(function () { | ||
classDiagram.parser.yy = classDB; | ||
classDiagram.parser.yy.clear(); | ||
}); | ||
|
||
it('should parse diagram with direction', () => { | ||
classDiagram.parser.parse(`classDiagram | ||
direction TB | ||
class Student { | ||
-idCard : IdCard | ||
} | ||
class IdCard{ | ||
-id : int | ||
-name : string | ||
} | ||
class Bike{ | ||
-id : int | ||
-name : string | ||
} | ||
Student "1" --o "1" IdCard : carries | ||
Student "1" --o "1" Bike : rides`); | ||
|
||
expect(Object.keys(classDB.getClasses()).length).toBe(3); | ||
expect(classDB.getClasses().Student).toMatchInlineSnapshot(` | ||
{ | ||
"annotations": [], | ||
"cssClasses": [], | ||
"domId": "classId-Student-0", | ||
"id": "Student", | ||
"label": "Student", | ||
"members": [ | ||
"-idCard : IdCard", | ||
], | ||
"methods": [], | ||
"type": "", | ||
} | ||
`); | ||
expect(classDB.getRelations().length).toBe(2); | ||
expect(classDB.getRelations()).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"id1": "Student", | ||
"id2": "IdCard", | ||
"relation": { | ||
"lineType": 0, | ||
"type1": "none", | ||
"type2": 0, | ||
}, | ||
"relationTitle1": "1", | ||
"relationTitle2": "1", | ||
"title": "carries", | ||
}, | ||
{ | ||
"id1": "Student", | ||
"id2": "Bike", | ||
"relation": { | ||
"lineType": 0, | ||
"type1": "none", | ||
"type2": 0, | ||
}, | ||
"relationTitle1": "1", | ||
"relationTitle2": "1", | ||
"title": "rides", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
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