@ts-graphviz/ast 0.0.0-pr956-20240225073457 → 0.0.0-pr956-20240225160253

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +291 -3
  2. package/lib/ast.cjs +25 -60
  3. package/lib/ast.js +25 -60
  4. package/package.json +43 -24
  5. package/src/ast.ts +0 -8
  6. package/src/builder/__snapshots__/create-element.test.ts.snap +0 -166
  7. package/src/builder/builder.test.ts +0 -36
  8. package/src/builder/builder.ts +0 -44
  9. package/src/builder/create-element.test.ts +0 -110
  10. package/src/builder/create-element.ts +0 -13
  11. package/src/builder/index.ts +0 -3
  12. package/src/builder/types.ts +0 -226
  13. package/src/dot-shim/index.ts +0 -2
  14. package/src/dot-shim/parser/__snapshots__/parse.test.ts.snap +0 -2613
  15. package/src/dot-shim/parser/dot.peggy +0 -396
  16. package/src/dot-shim/parser/index.ts +0 -1
  17. package/src/dot-shim/parser/parse.test.ts +0 -263
  18. package/src/dot-shim/parser/parse.ts +0 -121
  19. package/src/dot-shim/parser/peggy.options.json +0 -15
  20. package/src/dot-shim/printer/index.ts +0 -6
  21. package/src/dot-shim/printer/plugins/AttributeListPrintPlugin.ts +0 -22
  22. package/src/dot-shim/printer/plugins/AttributePrintPlugin.ts +0 -11
  23. package/src/dot-shim/printer/plugins/CommentPrintPlugin.ts +0 -40
  24. package/src/dot-shim/printer/plugins/DotPrintPlugin.ts +0 -12
  25. package/src/dot-shim/printer/plugins/EdgePrintPlugin.ts +0 -27
  26. package/src/dot-shim/printer/plugins/GraphPrintPlugin.ts +0 -32
  27. package/src/dot-shim/printer/plugins/LiteralPrintPlugin.ts +0 -24
  28. package/src/dot-shim/printer/plugins/NodePrintPlugin.ts +0 -24
  29. package/src/dot-shim/printer/plugins/NodeRefGroupPrintPlugin.ts +0 -17
  30. package/src/dot-shim/printer/plugins/NodeRefPrintPlugin.ts +0 -18
  31. package/src/dot-shim/printer/plugins/SubgraphPrintPlugin.ts +0 -27
  32. package/src/dot-shim/printer/plugins/index.ts +0 -26
  33. package/src/dot-shim/printer/plugins/utils/index.ts +0 -1
  34. package/src/dot-shim/printer/plugins/utils/tokens.ts +0 -51
  35. package/src/dot-shim/printer/printer.ts +0 -46
  36. package/src/dot-shim/printer/stringify.test.ts +0 -823
  37. package/src/dot-shim/printer/stringify.ts +0 -19
  38. package/src/dot-shim/printer/types.ts +0 -74
  39. package/src/model-shim/from-model/converter.ts +0 -43
  40. package/src/model-shim/from-model/from-model.ts +0 -19
  41. package/src/model-shim/from-model/index.ts +0 -3
  42. package/src/model-shim/from-model/plugins/AttributeListPlugin.ts +0 -19
  43. package/src/model-shim/from-model/plugins/EdgePlugin.ts +0 -140
  44. package/src/model-shim/from-model/plugins/GraphPlugin.ts +0 -36
  45. package/src/model-shim/from-model/plugins/NodePlugin.ts +0 -33
  46. package/src/model-shim/from-model/plugins/SubraphPlugin.ts +0 -28
  47. package/src/model-shim/from-model/plugins/index.ts +0 -13
  48. package/src/model-shim/from-model/plugins/utils/convert-attribute.ts +0 -47
  49. package/src/model-shim/from-model/plugins/utils/convert-cluster-children.ts +0 -44
  50. package/src/model-shim/from-model/plugins/utils/convert-comment.ts +0 -16
  51. package/src/model-shim/from-model/plugins/utils/index.ts +0 -3
  52. package/src/model-shim/from-model/types.ts +0 -62
  53. package/src/model-shim/index.ts +0 -2
  54. package/src/model-shim/to-model/converter.ts +0 -42
  55. package/src/model-shim/to-model/index.ts +0 -3
  56. package/src/model-shim/to-model/plugins/DotPlugin.ts +0 -25
  57. package/src/model-shim/to-model/plugins/EdgePlugin.ts +0 -26
  58. package/src/model-shim/to-model/plugins/GraphPlugin.ts +0 -15
  59. package/src/model-shim/to-model/plugins/NodePlugin.ts +0 -25
  60. package/src/model-shim/to-model/plugins/SubgraphPlugin.ts +0 -14
  61. package/src/model-shim/to-model/plugins/index.ts +0 -13
  62. package/src/model-shim/to-model/plugins/utils/apply-statments.ts +0 -96
  63. package/src/model-shim/to-model/plugins/utils/comment-holder.ts +0 -31
  64. package/src/model-shim/to-model/plugins/utils/convert-to-edge-target-tuple.ts +0 -21
  65. package/src/model-shim/to-model/to-model.test.ts +0 -34
  66. package/src/model-shim/to-model/to-model.ts +0 -16
  67. package/src/model-shim/to-model/types.ts +0 -71
  68. package/src/types.ts +0 -370
  69. package/tsconfig.json +0 -8
  70. package/typedoc.json +0 -4
  71. package/vite.config.ts +0 -22
@@ -1,823 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import { stringify } from './stringify.js';
3
-
4
- describe('stringify', () => {
5
- describe('literal', () => {
6
- test('quated', () => {
7
- expect(
8
- stringify({
9
- type: 'Literal',
10
- value: 'hoge',
11
- quoted: true,
12
- children: [],
13
- }),
14
- ).toMatchInlineSnapshot(`""hoge""`);
15
- });
16
-
17
- test('not quated', () => {
18
- expect(
19
- stringify({
20
- type: 'Literal',
21
- value: 'hoge',
22
- quoted: false,
23
- children: [],
24
- }),
25
- ).toMatchInlineSnapshot(`"hoge"`);
26
- });
27
-
28
- test('html label', () => {
29
- expect(
30
- stringify({
31
- type: 'Literal',
32
- value: 'hoge',
33
- quoted: 'html',
34
- children: [],
35
- }),
36
- ).toMatchInlineSnapshot(`"<hoge>"`);
37
- });
38
- });
39
-
40
- describe('attribyte', () => {
41
- test('simple', () => {
42
- expect(
43
- stringify({
44
- type: 'Literal',
45
- value: 'hoge',
46
- quoted: 'html',
47
- children: [],
48
- }),
49
- ).toMatchInlineSnapshot(`"<hoge>"`);
50
- });
51
- });
52
-
53
- describe('attribytes', () => {
54
- test('node', () => {
55
- expect(
56
- stringify({
57
- type: 'AttributeList',
58
- kind: 'Node',
59
- children: [],
60
- }),
61
- ).toMatchInlineSnapshot(`"node [];"`);
62
- });
63
-
64
- test('edge', () => {
65
- expect(
66
- stringify({
67
- type: 'AttributeList',
68
- kind: 'Edge',
69
- children: [],
70
- }),
71
- ).toMatchInlineSnapshot(`"edge [];"`);
72
- });
73
-
74
- test('graph', () => {
75
- expect(
76
- stringify({
77
- type: 'AttributeList',
78
- kind: 'Graph',
79
- children: [],
80
- }),
81
- ).toMatchInlineSnapshot(`"graph [];"`);
82
- });
83
-
84
- test('with attribute', () => {
85
- expect(
86
- stringify({
87
- type: 'AttributeList',
88
- kind: 'Node',
89
- children: [
90
- {
91
- type: 'Attribute',
92
- key: {
93
- type: 'Literal',
94
- value: 'color',
95
- quoted: false,
96
- children: [],
97
- },
98
-
99
- value: {
100
- type: 'Literal',
101
- value: 'hoge',
102
- quoted: false,
103
- children: [],
104
- },
105
-
106
- children: [],
107
- },
108
- ],
109
- }),
110
- ).toMatchInlineSnapshot(`
111
- "node [
112
- color = hoge;
113
- ];"
114
- `);
115
- });
116
- test('with two attributes', () => {
117
- expect(
118
- stringify({
119
- type: 'AttributeList',
120
- kind: 'Node',
121
- children: [
122
- {
123
- type: 'Attribute',
124
- key: {
125
- type: 'Literal',
126
- value: 'color',
127
- quoted: false,
128
- children: [],
129
- },
130
-
131
- value: {
132
- type: 'Literal',
133
- value: 'hoge',
134
- quoted: false,
135
- children: [],
136
- },
137
-
138
- children: [],
139
- },
140
-
141
- {
142
- type: 'Attribute',
143
- key: {
144
- type: 'Literal',
145
- value: 'bgcolor',
146
- quoted: false,
147
- children: [],
148
- },
149
-
150
- value: {
151
- type: 'Literal',
152
- value: 'fuga',
153
- quoted: false,
154
- children: [],
155
- },
156
-
157
- children: [],
158
- },
159
- ],
160
- }),
161
- ).toMatchInlineSnapshot(`
162
- "node [
163
- color = hoge;
164
- bgcolor = fuga;
165
- ];"
166
- `);
167
- });
168
- });
169
-
170
- describe('node', () => {
171
- test('simple', () => {
172
- expect(
173
- stringify({
174
- type: 'Attribute',
175
- key: {
176
- type: 'Literal',
177
- value: 'color',
178
- quoted: false,
179
- children: [],
180
- },
181
-
182
- value: {
183
- type: 'Literal',
184
- value: 'hoge',
185
- quoted: false,
186
- children: [],
187
- },
188
-
189
- children: [],
190
- }),
191
- ).toMatchInlineSnapshot(`"color = hoge;"`);
192
- });
193
-
194
- test('with attribute', () => {
195
- expect(
196
- stringify({
197
- type: 'Node',
198
- children: [
199
- {
200
- type: 'Attribute',
201
- key: {
202
- type: 'Literal',
203
- value: 'color',
204
- quoted: false,
205
- children: [],
206
- },
207
-
208
- value: {
209
- type: 'Literal',
210
- value: 'hoge',
211
- quoted: false,
212
- children: [],
213
- },
214
-
215
- children: [],
216
- },
217
- ],
218
-
219
- id: {
220
- type: 'Literal',
221
- value: 'hoge',
222
- quoted: true,
223
- children: [],
224
- },
225
- }),
226
- ).toMatchInlineSnapshot(`
227
- ""hoge" [
228
- color = hoge;
229
- ];"
230
- `);
231
- });
232
-
233
- test('with two attributes', () => {
234
- expect(
235
- stringify({
236
- type: 'Node',
237
- children: [
238
- {
239
- type: 'Attribute',
240
- key: {
241
- type: 'Literal',
242
- value: 'color',
243
- quoted: false,
244
- children: [],
245
- },
246
-
247
- value: {
248
- type: 'Literal',
249
- value: 'hoge',
250
- quoted: false,
251
- children: [],
252
- },
253
-
254
- children: [],
255
- },
256
-
257
- {
258
- type: 'Attribute',
259
- key: {
260
- type: 'Literal',
261
- value: 'bgcolor',
262
- quoted: false,
263
- children: [],
264
- },
265
-
266
- value: {
267
- type: 'Literal',
268
- value: 'fuga',
269
- quoted: false,
270
- children: [],
271
- },
272
-
273
- children: [],
274
- },
275
- ],
276
-
277
- id: {
278
- type: 'Literal',
279
- value: 'hoge',
280
- quoted: true,
281
- children: [],
282
- },
283
- }),
284
- ).toMatchInlineSnapshot(`
285
- ""hoge" [
286
- color = hoge;
287
- bgcolor = fuga;
288
- ];"
289
- `);
290
- });
291
- });
292
-
293
- describe('edge', () => {
294
- test('simple', () => {
295
- expect(
296
- stringify({
297
- type: 'Edge',
298
- targets: [
299
- {
300
- type: 'NodeRef',
301
- id: {
302
- type: 'Literal',
303
- value: 'id1',
304
- quoted: true,
305
- children: [],
306
- },
307
-
308
- port: {
309
- type: 'Literal',
310
- value: 'port1',
311
- quoted: true,
312
- children: [],
313
- },
314
-
315
- children: [],
316
- },
317
-
318
- {
319
- type: 'NodeRef',
320
- id: {
321
- type: 'Literal',
322
- value: 'id2',
323
- quoted: true,
324
- children: [],
325
- },
326
-
327
- compass: {
328
- type: 'Literal',
329
- value: 'w',
330
- quoted: false,
331
- children: [],
332
- },
333
-
334
- children: [],
335
- },
336
- ],
337
-
338
- children: [],
339
- }),
340
- ).toMatchInlineSnapshot(`""id1":"port1" -> "id2":w;"`);
341
- });
342
-
343
- test('with attribute', () => {
344
- expect(
345
- stringify({
346
- type: 'Edge',
347
- targets: [
348
- {
349
- type: 'NodeRef',
350
- id: {
351
- type: 'Literal',
352
- value: 'id1',
353
- quoted: true,
354
- children: [],
355
- },
356
-
357
- port: {
358
- type: 'Literal',
359
- value: 'port1',
360
- quoted: true,
361
- children: [],
362
- },
363
-
364
- children: [],
365
- },
366
-
367
- {
368
- type: 'NodeRef',
369
- id: {
370
- type: 'Literal',
371
- value: 'id2',
372
- quoted: true,
373
- children: [],
374
- },
375
-
376
- compass: {
377
- type: 'Literal',
378
- value: 'w',
379
- quoted: false,
380
- children: [],
381
- },
382
-
383
- children: [],
384
- },
385
- ],
386
-
387
- children: [
388
- {
389
- type: 'Attribute',
390
- key: {
391
- type: 'Literal',
392
- value: 'color',
393
- quoted: false,
394
- children: [],
395
- },
396
-
397
- value: {
398
- type: 'Literal',
399
- value: 'hoge',
400
- quoted: false,
401
- children: [],
402
- },
403
-
404
- children: [],
405
- },
406
- ],
407
- }),
408
- ).toMatchInlineSnapshot(`
409
- ""id1":"port1" -> "id2":w [
410
- color = hoge;
411
- ];"
412
- `);
413
- });
414
-
415
- test('with two attributes', () => {
416
- expect(
417
- stringify({
418
- type: 'Edge',
419
- targets: [
420
- {
421
- type: 'NodeRef',
422
- id: {
423
- type: 'Literal',
424
- value: 'id1',
425
- quoted: true,
426
- children: [],
427
- },
428
-
429
- port: {
430
- type: 'Literal',
431
- value: 'port1',
432
- quoted: true,
433
- children: [],
434
- },
435
-
436
- children: [],
437
- },
438
-
439
- {
440
- type: 'NodeRef',
441
- id: {
442
- type: 'Literal',
443
- value: 'id2',
444
- quoted: true,
445
- children: [],
446
- },
447
-
448
- compass: {
449
- type: 'Literal',
450
- value: 'w',
451
- quoted: false,
452
- children: [],
453
- },
454
-
455
- children: [],
456
- },
457
- ],
458
-
459
- children: [
460
- {
461
- type: 'Attribute',
462
- key: {
463
- type: 'Literal',
464
- value: 'color',
465
- quoted: false,
466
- children: [],
467
- },
468
-
469
- value: {
470
- type: 'Literal',
471
- value: 'hoge',
472
- quoted: false,
473
- children: [],
474
- },
475
-
476
- children: [],
477
- },
478
-
479
- {
480
- type: 'Attribute',
481
- key: {
482
- type: 'Literal',
483
- value: 'color',
484
- quoted: false,
485
- children: [],
486
- },
487
-
488
- value: {
489
- type: 'Literal',
490
- value: 'fuga',
491
- quoted: false,
492
- children: [],
493
- },
494
-
495
- children: [],
496
- },
497
- ],
498
- }),
499
- ).toMatchInlineSnapshot(`
500
- ""id1":"port1" -> "id2":w [
501
- color = hoge;
502
- color = fuga;
503
- ];"
504
- `);
505
- });
506
-
507
- test('node ref group', () => {
508
- expect(
509
- stringify({
510
- type: 'Edge',
511
- targets: [
512
- {
513
- type: 'NodeRef',
514
- id: {
515
- type: 'Literal',
516
- value: 'id1',
517
- quoted: true,
518
- children: [],
519
- },
520
-
521
- port: {
522
- type: 'Literal',
523
- value: 'port1',
524
- quoted: true,
525
- children: [],
526
- },
527
-
528
- children: [],
529
- },
530
-
531
- {
532
- type: 'NodeRefGroup',
533
- children: [
534
- {
535
- type: 'NodeRef',
536
- id: {
537
- type: 'Literal',
538
- value: 'id2',
539
- quoted: true,
540
- children: [],
541
- },
542
-
543
- children: [],
544
- },
545
-
546
- {
547
- type: 'NodeRef',
548
- id: {
549
- type: 'Literal',
550
- value: 'id3',
551
- quoted: true,
552
- children: [],
553
- },
554
-
555
- children: [],
556
- },
557
- ],
558
- },
559
- ],
560
-
561
- children: [],
562
- }),
563
- ).toMatchInlineSnapshot(`""id1":"port1" -> {"id2" "id3"};"`);
564
- });
565
- });
566
-
567
- describe('subgraph', () => {
568
- test('with id', () => {
569
- expect(
570
- stringify({
571
- type: 'Subgraph',
572
- id: {
573
- type: 'Literal',
574
- value: 'id1',
575
- quoted: true,
576
- children: [],
577
- },
578
- children: [],
579
- }),
580
- ).toMatchInlineSnapshot(`"subgraph "id1" {}"`);
581
- });
582
-
583
- test('no id', () => {
584
- expect(
585
- stringify({
586
- type: 'Subgraph',
587
- children: [],
588
- }),
589
- ).toMatchInlineSnapshot(`"subgraph {}"`);
590
- });
591
-
592
- test('with children', () => {
593
- expect(
594
- stringify({
595
- type: 'Subgraph',
596
- children: [
597
- {
598
- type: 'Attribute',
599
- key: {
600
- type: 'Literal',
601
- value: 'color',
602
- quoted: false,
603
- children: [],
604
- },
605
-
606
- value: {
607
- type: 'Literal',
608
- value: 'hoge',
609
- quoted: false,
610
- children: [],
611
- },
612
- children: [],
613
- },
614
- ],
615
- }),
616
- ).toMatchInlineSnapshot(`
617
- "subgraph {
618
- color = hoge;
619
- }"
620
- `);
621
- });
622
- });
623
-
624
- describe('graph', () => {
625
- test('directed', () => {
626
- expect(
627
- stringify({
628
- type: 'Graph',
629
- strict: false,
630
- directed: true,
631
- id: {
632
- type: 'Literal',
633
- value: 'id1',
634
- quoted: true,
635
- children: [],
636
- },
637
- children: [],
638
- }),
639
- ).toMatchInlineSnapshot(`"digraph "id1" {}"`);
640
- });
641
-
642
- test('strict directed', () => {
643
- expect(
644
- stringify({
645
- type: 'Graph',
646
- strict: true,
647
- directed: true,
648
- id: {
649
- type: 'Literal',
650
- value: 'id1',
651
- quoted: true,
652
- children: [],
653
- },
654
-
655
- children: [],
656
- }),
657
- ).toMatchInlineSnapshot(`"strict digraph "id1" {}"`);
658
- });
659
-
660
- test('graph', () => {
661
- expect(
662
- stringify({
663
- type: 'Graph',
664
- strict: false,
665
- directed: false,
666
- id: {
667
- type: 'Literal',
668
- value: 'id1',
669
- quoted: true,
670
- children: [],
671
- },
672
-
673
- children: [],
674
- }),
675
- ).toMatchInlineSnapshot(`"graph "id1" {}"`);
676
- });
677
-
678
- test('strict graph', () => {
679
- expect(
680
- stringify({
681
- type: 'Graph',
682
- strict: true,
683
- directed: false,
684
- id: {
685
- type: 'Literal',
686
- value: 'id1',
687
- quoted: true,
688
- children: [],
689
- },
690
-
691
- children: [],
692
- }),
693
- ).toMatchInlineSnapshot(`"strict graph "id1" {}"`);
694
- });
695
-
696
- test('no id', () => {
697
- expect(
698
- stringify({
699
- type: 'Graph',
700
- strict: false,
701
- directed: true,
702
- children: [],
703
- }),
704
- ).toMatchInlineSnapshot(`"digraph {}"`);
705
- });
706
-
707
- test('with children', () => {
708
- expect(
709
- stringify({
710
- type: 'Graph',
711
- strict: false,
712
- directed: true,
713
- children: [
714
- {
715
- type: 'Attribute',
716
- key: {
717
- type: 'Literal',
718
- value: 'color',
719
- quoted: false,
720
- children: [],
721
- },
722
-
723
- value: {
724
- type: 'Literal',
725
- value: 'hoge',
726
- quoted: false,
727
- children: [],
728
- },
729
-
730
- children: [],
731
- },
732
- ],
733
- }),
734
- ).toMatchInlineSnapshot(`
735
- "digraph {
736
- color = hoge;
737
- }"
738
- `);
739
- });
740
- });
741
-
742
- describe('comment', () => {
743
- test('block', () => {
744
- expect(
745
- stringify({
746
- type: 'Comment',
747
- kind: 'Block',
748
- value: 'test\ntest',
749
- children: [],
750
- }),
751
- ).toMatchInlineSnapshot(`
752
- "/**
753
- * test
754
- * test
755
- */"
756
- `);
757
- });
758
-
759
- test('macro', () => {
760
- expect(
761
- stringify({
762
- type: 'Comment',
763
- kind: 'Macro',
764
- value: 'foo\nbar',
765
- children: [],
766
- }),
767
- ).toMatchInlineSnapshot(`
768
- "# foo
769
- # bar"
770
- `);
771
- });
772
-
773
- test('slach', () => {
774
- expect(
775
- stringify({
776
- type: 'Comment',
777
- kind: 'Slash',
778
- value: 'foo\nbar',
779
- children: [],
780
- }),
781
- ).toMatchInlineSnapshot(`
782
- "// foo
783
- // bar"
784
- `);
785
- });
786
- });
787
-
788
- describe('dot', () => {
789
- test('slach', () => {
790
- expect(
791
- stringify({
792
- type: 'Dot',
793
- children: [
794
- {
795
- type: 'Comment',
796
- kind: 'Slash',
797
- value: 'foo\nbar',
798
- children: [],
799
- },
800
-
801
- {
802
- type: 'Graph',
803
- strict: false,
804
- directed: false,
805
- id: {
806
- type: 'Literal',
807
- value: 'id1',
808
- quoted: true,
809
- children: [],
810
- },
811
-
812
- children: [],
813
- },
814
- ],
815
- }),
816
- ).toMatchInlineSnapshot(`
817
- "// foo
818
- // bar
819
- graph "id1" {}"
820
- `);
821
- });
822
- });
823
- });