-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,518 additions
and
14 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,9 @@ | ||
--- | ||
'@pintora/core': minor | ||
'@pintora/diagrams': minor | ||
'@pintora/renderer': minor | ||
'@pintora/test-shared': minor | ||
'pintora-website': minor | ||
--- | ||
|
||
Add classDiagram |
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
119 changes: 119 additions & 0 deletions
119
packages/pintora-diagrams/src/class/__tests__/__snapshots__/class-parser.spec.ts.snap
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,119 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`class parser can parse class label 1`] = ` | ||
{ | ||
"class1": { | ||
"annotation": "", | ||
"fullName": "class1", | ||
"label": "class1", | ||
"members": [ | ||
{ | ||
"access": "public", | ||
"isMethod": false, | ||
"modifier": null, | ||
"name": "RED", | ||
"raw": "RED", | ||
"typeName": "", | ||
}, | ||
], | ||
"name": "class1", | ||
"namespace": "", | ||
}, | ||
} | ||
`; | ||
|
||
exports[`class parser can parse methods and fields 1`] = ` | ||
{ | ||
"classes": { | ||
"C1": { | ||
"annotation": "", | ||
"fullName": "C1", | ||
"label": "C1", | ||
"members": [ | ||
{ | ||
"access": "public", | ||
"isMethod": false, | ||
"modifier": null, | ||
"name": "field1", | ||
"raw": "string field1", | ||
"typeName": "string", | ||
}, | ||
{ | ||
"access": "public", | ||
"isMethod": true, | ||
"modifier": null, | ||
"name": "method1()", | ||
"raw": "int method1()", | ||
"typeName": "int", | ||
}, | ||
{ | ||
"access": "public", | ||
"isMethod": false, | ||
"modifier": null, | ||
"name": "field2", | ||
"raw": "field2: number", | ||
"typeName": "number", | ||
}, | ||
{ | ||
"access": "public", | ||
"isMethod": true, | ||
"name": "method2()", | ||
"raw": "method2()", | ||
"typeName": "", | ||
}, | ||
], | ||
"name": "C1", | ||
"namespace": "", | ||
}, | ||
}, | ||
"configParams": [], | ||
"overrideConfig": {}, | ||
"relations": [], | ||
"title": "", | ||
} | ||
`; | ||
|
||
exports[`class parser can parse relationship between classes 1`] = ` | ||
[ | ||
{ | ||
"dashed": false, | ||
"label": "", | ||
"labelLeft": null, | ||
"labelRight": null, | ||
"left": "A1", | ||
"relation": "INHERITANCE", | ||
"right": "A2", | ||
"type": "addRelation", | ||
}, | ||
{ | ||
"dashed": false, | ||
"label": "", | ||
"labelLeft": null, | ||
"labelRight": null, | ||
"left": "B1", | ||
"relation": "COMPOSITION", | ||
"right": "B2", | ||
"type": "addRelation", | ||
}, | ||
{ | ||
"dashed": false, | ||
"label": "", | ||
"labelLeft": null, | ||
"labelRight": null, | ||
"left": "C1", | ||
"relation": "AGGREGATION", | ||
"right": "C2", | ||
"type": "addRelation", | ||
}, | ||
{ | ||
"dashed": false, | ||
"label": "association", | ||
"labelLeft": null, | ||
"labelRight": null, | ||
"left": "D1", | ||
"relation": "ASSOCIATION", | ||
"right": "D2", | ||
"type": "addRelation", | ||
}, | ||
] | ||
`; |
119 changes: 119 additions & 0 deletions
119
packages/pintora-diagrams/src/class/__tests__/class-parser.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,119 @@ | ||
import { parse } from '../parser' | ||
import db from '../db' | ||
import { stripStartEmptyLines } from '@pintora/test-shared' | ||
|
||
describe('class parser', () => { | ||
afterEach(() => { | ||
db.clear() | ||
}) | ||
|
||
it('can parse class name', () => { | ||
const example = stripStartEmptyLines(` | ||
classDiagram | ||
class C1 | ||
class N1.N2.C2 | ||
`) | ||
parse(example) | ||
const ir = db.getDiagramIR() | ||
expect(ir.classes['C1']).toMatchObject({ name: 'C1' }) | ||
expect(ir.classes['N1.N2.C2']).toMatchObject({ name: 'C2', fullName: 'N1.N2.C2', namespace: 'N1.N2' }) | ||
}) | ||
|
||
it('can parse methods and fields', () => { | ||
const example = stripStartEmptyLines(` | ||
classDiagram | ||
class C1 { | ||
string field1 | ||
int method1() | ||
field2: number | ||
} | ||
C1: method2() | ||
`) | ||
parse(example) | ||
const ir = db.getDiagramIR() | ||
expect(ir).toMatchSnapshot() | ||
// console.log(JSON.stringify(ir, null, 2)) | ||
}) | ||
|
||
it('can parse member with modifier', () => { | ||
const example = stripStartEmptyLines(` | ||
classDiagram | ||
class C1 { | ||
{ static } int method1() | ||
{abstract} string field1 | ||
} | ||
`) | ||
parse(example) | ||
const ir = db.getDiagramIR() | ||
expect(ir.classes['C1'].members[0].modifier).toEqual('static') | ||
expect(ir.classes['C1'].members[1].modifier).toEqual('abstract') | ||
}) | ||
|
||
it('can parse relationship between classes', () => { | ||
const example = stripStartEmptyLines(` | ||
classDiagram | ||
A1 <|-- A2 | ||
B1 *-- B2 | ||
C1 o-- C2 | ||
D1 --> D2 : association | ||
`) | ||
parse(example) | ||
const ir = db.getDiagramIR() | ||
expect(ir.relations).toMatchSnapshot() | ||
}) | ||
|
||
it('can parse quoted labels on relations', () => { | ||
const example = stripStartEmptyLines(` | ||
classDiagram | ||
C1 "1" *-- "many" C2 : contains | ||
`) | ||
parse(example) | ||
const ir = db.getDiagramIR() | ||
expect(ir.relations[0]).toMatchObject({ | ||
type: 'addRelation', | ||
left: 'C1', | ||
right: 'C2', | ||
relation: 'COMPOSITION', | ||
labelLeft: '1', | ||
labelRight: 'many', | ||
label: 'contains', | ||
dashed: false, | ||
}) | ||
}) | ||
|
||
it('can parse class annotation', () => { | ||
const example = stripStartEmptyLines(` | ||
classDiagram | ||
<< Interface >> C1 | ||
class C2 { | ||
<< Serializable >> | ||
string test | ||
} | ||
`) | ||
parse(example) | ||
const ir = db.getDiagramIR() | ||
expect(ir.classes).toMatchObject({ | ||
C1: { | ||
annotation: 'Interface', | ||
}, | ||
C2: { | ||
annotation: 'Serializable', | ||
}, | ||
}) | ||
}) | ||
|
||
it('can parse class label', () => { | ||
const example = stripStartEmptyLines(` | ||
classDiagram | ||
class "This is class label" as class1 | ||
class class1 { | ||
RED | ||
} | ||
`) | ||
parse(example) | ||
const ir = db.getDiagramIR() | ||
expect(ir.classes).toMatchSnapshot() | ||
}) | ||
}) |
Oops, something went wrong.