Skip to content

Commit

Permalink
feat: [sequence] add participant boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
hikerpig committed May 9, 2022
1 parent 5ecb6db commit f22f85c
Show file tree
Hide file tree
Showing 11 changed files with 645 additions and 309 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-parents-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pintora/diagrams': patch
---

feat: [sequence] add participant boxes
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('sequence parser', () => {
it('can parse unicode chars', () => {
const backquoteExample = stripStartEmptyLines(`
sequenceDiagram
autonumber
autonumber
用户 ->> Pintora: 帮我画张时序图
activate Pintora
alt DSL 正确
Expand Down Expand Up @@ -106,10 +106,10 @@ sequenceDiagram

it('can parse participant', () => {
const example = stripStartEmptyLines(`
sequenceDiagram
sequenceDiagram
participant A as "Alice"
participant B as Bobby Bob
participant C
participant C
A-->B: hello
A-->C: yoho
`)
Expand Down Expand Up @@ -175,6 +175,58 @@ sequenceDiagram
})
})

it('can parse participant inside box', () => {
const example = stripStartEmptyLines(`
sequenceDiagram
box #d6d3fa "group participants"
participant A as "Alice"
participant B
endbox
`)
parse(example)
const ir = db.getDiagramIR()
// console.log(JSON.stringify(ir, null, 2))
expect(ir.participantBoxes).toMatchObject({
1: {
id: '1',
text: 'group participants',
actors: ['A', 'B'],
background: '#d6d3fa',
},
})
expect(ir.actors).toMatchObject({
A: {
name: 'A',
description: 'Alice',
boxId: '1',
},
B: {
name: 'B',
boxId: '1',
},
})
})

it('can parse participant box without title', () => {
const example = stripStartEmptyLines(`
sequenceDiagram
box
participant A as "Alice"
participant B
endbox
`)
parse(example)
const ir = db.getDiagramIR()
// console.log(JSON.stringify(ir, null, 2))
expect(ir.participantBoxes).toMatchObject({
1: {
id: '1',
text: null,
actors: ['A', 'B'],
},
})
})

it('can parse multiline message', () => {
const example = stripStartEmptyLines(`
sequenceDiagram
Expand Down
Loading

0 comments on commit f22f85c

Please sign in to comment.