-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathdescriptions.test.ts
More file actions
1204 lines (1060 loc) · 33.7 KB
/
descriptions.test.ts
File metadata and controls
1204 lines (1060 loc) · 33.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as prettier from "prettier";
import { AllOptions } from "../src/types";
function subject(code: string, options: Partial<AllOptions> = {}) {
return prettier.format(code, {
plugins: ["prettier-plugin-jsdoc"],
parser: "babel-ts",
...options,
} as AllOptions);
}
test("description contain paragraph", async () => {
const result = await subject(`
/**
* Does the following things:
*
* 1. Thing 1
*
* 2. Thing 2
*
* 3. Thing 3
*/
`);
expect(result).toMatchSnapshot();
const result2 = await subject(`
/**
* Does the following things:
*
* 1. Thing 1
* 2. Thing 2
* 3. Thing 3
*/
`);
expect(result2).toMatchSnapshot();
const result3 = await subject(`
class test {
/**
* Lorem ipsum dolor sit amet, consectetur adipiscing elit,
* sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
*
* Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
*
* lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
*/
a(){}
}
`);
expect(result3).toMatchSnapshot();
const result4 = await subject(`
/**
* Transforms data
*
* @override
*/
/**
* Bounce give a renderContent and show that around children when isVisible is
* true
*
* @example
* <Bounce
* isVisible={isVisible}
* dismiss={() => setVisible(false)}
* renderContent={() => {
* return <InsideOfPopeUp />;
* }}>
* <Button />
* </Bounce>;
*
* @type {React.FC<BounceProps>}
*/
/**
* @param {string} a
*
* \`\`\`js
* var a = 0;
* \`\`\`
*/
`);
expect(result4).toMatchSnapshot();
});
test("description new line with dash", async () => {
const result1 = await subject(`
/**
* We will allow the scroll view to give up its lock iff it acquired the lock
* during an - animation. This is a very useful default that happens to satisfy
* many common user experiences.
*
* - Stop a scroll on the left edge, then turn that into an outer view's
* backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer
* view dismiss.
* - However, without catching the scroll view mid-bounce (while it is
* motionless), if you drag far enough for the scroll view to become
* responder (and therefore drag the scroll view a bit), any backswipe
* navigation of a swipe gesture higher in the view hierarchy, should be
* rejected.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
/**
* - stop a scroll on the left edge, then turn that into an outer view's
* backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer
* view dismiss.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
/**- stop a scroll on the left edge, then turn that into an outer view's
* backswipe.
* - Stop a scroll mid-bounce at the top, continue pulling to have the outer
* view dismiss.
*/
function scrollResponderHandleTerminationRequest() {
return !this.state.observedScrollSinceBecomingResponder;
}
`);
expect(result1).toMatchSnapshot();
const result2 = await subject(`
/**
* Measures the \`HitRect\` node on activation. The Bounding rectangle is with
* respect to viewport - not page, so adding the \`pageXOffset/pageYOffset\`
* should result in points that are in the same coordinate system as an
* event's \`globalX/globalY\` data values.
*
* - Consider caching this for the lifetime of the component, or possibly being able to share this
* cache between any \`ScrollMap\` view.
*
* @private
*
* @sideeffects
*/
`);
expect(result2).toMatchSnapshot();
const result3 = await subject(`
/**
* Handles parsing of a test case file.
*
*
* A test case file consists of at least two parts, separated by a line of dashes.
* This separation line must start at the beginning of the line and consist of at least three dashes.
*
* The test case file can either consist of two parts:
*
* const a=''
* const b={c:[]}
*
*
* or of three parts:
*
* {source code}
* ----
* {expected token stream}
* ----
* {text comment explaining the test case}
*
* If the file contains more than three parts, the remaining parts are just ignored.
* If the file however does not contain at least two parts (so no expected token stream),
* the test case will later be marked as failed.
*
*
*/
`);
expect(result3).toMatchSnapshot();
});
test("numbers and code in description", async () => {
const result1 = await subject(`
/**
* ========================== PressResponder Tutorial ==========================
*
* The \`PressResponder\` class helps you create press interactions by analyzing the
* geometry of elements and observing when another responder (e.g. ScrollView)
* has stolen the touch lock. It offers hooks for your component to provide
* interaction feedback to the user:
*
* - When a press has activated (e.g. highlight an element)
* - When a press has deactivated (e.g. un-highlight an element)
* - When a press sould trigger an action, meaning it activated and deactivated while within the geometry of the element without the lock being stolen.
*
* A high quality interaction isn't as simple as you might think. There should
* be a slight delay before activation. Moving your finger beyond an element's
* bounds should trigger deactivation, but moving the same finger back within an
* element's bounds should trigger reactivation.
*
* 1- In order to use \`PressResponder\`, do the following:
*\`\`\`js
* const pressResponder = new PressResponder(config);
*\`\`\`
* 2. Choose the rendered component who should collect the press events. On that
* element, spread \`pressability.getEventHandlers()\` into its props.
*\`\`\`js
* return (
* <View {...this.state.pressResponder.getEventHandlers()} />
* );
*\`\`\`
* 3. Reset \`PressResponder\` when your component unmounts.
*\`\`\`js
* componentWillUnmount() {
* this.state.pressResponder.reset();
* }
*\`\`\`
* ==================== Implementation Details ====================
*
* \`PressResponder\` only assumes that there exists a \`HitRect\` node. The \`PressRect\`
* is an abstract box that is extended beyond the \`HitRect\`.
*
* # Geometry
* When the press is released outside the \`HitRect\`,
* the responder is NOT eligible for a "press".
*
*/
`);
expect(await subject(await subject(result1))).toEqual(result1);
expect(await subject(await subject(result1))).toMatchSnapshot();
const result2 = await subject(`
/**
* 1- a keydown event occurred immediately before a focus event
* 2- a focus event happened on an element which requires keyboard interaction (e.g., a text field);
* 2- a focus event happened on an element which requires keyboard interaction (e.g., a text field);
*/
`);
expect(result2).toMatchSnapshot();
const result3 = await subject(
`
/**
* The script uses two heuristics to determine whether the keyboard is being used:
*
* 1. a keydown event occurred lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliqimmediately before a focus event;
* 2. a focus evenlorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliqt happened on an element which requires keyboard interaction (e.g., a text field);
*
* lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliq
* W3C Software Notice and License: https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
*/
`,
{
jsdocDescriptionWithDot: true,
},
);
expect(
await subject(result3, {
jsdocDescriptionWithDot: true,
}),
).toEqual(result3);
expect(result3).toMatchSnapshot();
const result4 = await subject(`
/**
* Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus.
*
* 1. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.
* 2. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.
*
* Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.
*
* @public
*/
`);
expect(result4).toMatchSnapshot();
});
test("Nested list", async () => {
const result1 = await subject(
`
/**
* 1. Foo
* 1. Entry 1
* 2. Entry 2
* - Foo
* - bar
* 3. Entry 3
* 2. Bar
* 1. Entry 1
* 2. Entry 2
* 3. Entry 3
*/
`,
);
expect(result1).toMatchSnapshot();
});
test("New line with \\", async () => {
const result1 = await subject(
`
/**
* A short description,\
* A long description.
*/
`,
);
expect(result1).toMatchSnapshot();
expect(await subject(result1)).toEqual(result1);
});
test("List in tags", async () => {
const result1 = await subject(
`
/**
* @param {any} var An example list:
*
* - Item 1
* - Item 2
*
* @returns {Promise} A return value.
*/
/**
* @param {any} var An example list:
*
* - Item 1
* - Item 2
*
*/
`,
);
expect(result1).toMatchSnapshot();
});
test("code in description", async () => {
const result1 = await subject(`
/**
* \`Touchable\`: Taps done right.
*
* You hook your \`ResponderEventPlugin\` events into \`Touchable\`. \`Touchable\`
* will measure time/geometry and tells you when to give feedback to the user.
*
* ====================== Touchable Tutorial ===============================
* The \`Touchable\` mixin helps you handle the "press" interaction. It analyzes
* the geometry of elements, and observes when another responder (scroll view
* etc) has stolen the touch lock. It notifies your component when it should
* give feedback to the user. (bouncing/highlighting/unhighlighting).
*
* - When a touch was activated (typically you highlight)
* - When a touch was deactivated (typically you unhighlight)
* - When a touch was "pressed" - a touch ended while still within the geometry
* of the element, and no other element (like scroller) has "stolen" touch
* lock ("responder") (Typically you bounce the element).
*
* A good tap interaction isn't as simple as you might think. There should be a
* slight delay before showing a highlight when starting a touch. If a
* subsequent touch move exceeds the boundary of the element, it should
* unhighlight, but if that same touch is brought back within the boundary, it
* should rehighlight again. A touch can move in and out of that boundary
* several times, each time toggling highlighting, but a "press" is only
* triggered if that touch ends while within the element's boundary and no
* scroller (or anything else) has stolen the lock on touches.
*
* To create a new type of component that handles interaction using the
* \`Touchable\` mixin, do the following:
*
* - Initialize the \`Touchable\` state.
*\`\`\`js
* getInitialState: function( ) {
* return merge(this.touchableGetInitialState(), yourComponentState);
* }
*\`\`\`
* - Choose the rendered component who's touches should start the interactive
* sequence. On that rendered node, forward all \`Touchable\` responder
* handlers. You can choose any rendered node you like. Choose a node whose
* hit target you'd like to instigate the interaction sequence:
*\`\`\`js
* // In render function:
* return (
* <View
*
* onStartShouldSetResponder={this.touchableHandleStartShouldSetResponder}
* onResponderTerminationRequest={this.touchableHandleResponderTerminationRequest}
* onResponderGrant={this.touchableHandleResponderGrant}
* onResponderMove={this.touchableHandleResponderMove}
* onResponderRelease={this.touchableHandleResponderRelease}
* onResponderTerminate={this.touchableHandleResponderTerminate}>
* <View>
* Even though the hit detection/interactions are triggered by the
* wrapping (typically larger) node, we usually end up implementing
* custom logic that highlights this inner one.
* </View>
* </View>
* );
*\`\`\`
* - You may set up your own handlers for each of these events, so long as you
* also invoke the \`touchable*\` handlers inside of your custom handler.
*
* - Implement the handlers on your component class in order to provide
* feedback to the user. See documentation for each of these class methods
* that you should implement.
*\`\`\`js
* touchableHandlePress: function() {
* this.performBounceAnimation(); // or whatever you want to do.
* },
* touchableHandleActivePressIn: function() {
* this.beginHighlighting(...); // Whatever you like to convey activation
* },
* touchableHandleActivePressOut: function() {
* this.endHighlighting(...); // Whatever you like to convey deactivation
* },
*\`\`\`
* - There are more advanced methods you can implement (see documentation below):
* \`\`\`js
* touchableGetHighlightDelayMS: function() {
* return 20;
* }
* // In practice, *always* use a predeclared constant (conserve memory).
* touchableGetPressRectOffset: function() {
* return {top: 20, left: 20, right: 20, bottom: 100};
* }
* \`\`\`
*/
`);
expect(result1).toMatchSnapshot();
const result2 = await subject(
await subject(`
/**
* Utility type for getting the values for specific style keys.
* # test:
* The following is bad because position is more restrictive than 'string':
* \`\`\`
* type Props = {position: string};
* \`\`\`
*
* You should use the following instead:
*
* \`\`\`
* type Props = {position: TypeForStyleKey<'position'>};
* \`\`\`
*
* This will correctly give you the type 'absolute' | 'relative'
*/
`),
);
expect(await subject(await subject(result2))).toEqual(result2);
expect(result2).toMatchSnapshot();
});
test("printWidth", async () => {
const _subject = (content: string) =>
subject(content, {
jsdocPrintWidth: 80,
});
const result1 = await _subject(
`/**
* A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
* A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
* A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
*
* A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
* A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
* A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
*/`,
);
expect(await _subject(await _subject(result1))).toEqual(result1);
expect(result1).toMatchSnapshot();
});
test("matches prettier markdown format", async () => {
const result1 = await subject(
`/**
* Header
* ======
*
* _Look,_ code blocks are formatted *too!*
*
* \`\`\` js
* function identity(x) { return x }
* \`\`\`
*
* Pilot|Airport|Hours
* --|:--:|--:
* John Doe|SKG|1338
* Jane Roe|JFK|314
*
* - - - - - - - - - - - - - - -
*
* + List
* + with a [link] (/to/somewhere)
* + and [another one]
*
*
* [another one]: http://example.com 'Example title'
*
* Lorem ipsum dolor sit amet, consectetur adipiscing elit.
* Curabitur consectetur maximus risus, sed maximus tellus tincidunt et.
*
* @param {string} a __very__ important!
* @param {string} b _less_ important...
* @param {string} a __very__ important!
* @param {string} b *less* important...
*/`,
);
expect(result1).toMatchSnapshot();
});
test("description start underscores", async () => {
const result1 = await subject(
`/**
* @param {string} a __very__ important!
* @param {string} b _less_ important...
*/`,
);
expect(result1).toMatchSnapshot();
});
test("`#` in text", async () => {
const result1 = await subject(
`/**
* JS: \`console.log("foo # bar");\`
*
* Some # text
*
* More text
*/`,
);
expect(result1).toMatchSnapshot();
});
test("empty lines", async () => {
const result1 = await subject(
`/**
* Foo
*
*
*
*
*
* Bar
*
*
*
*
* @param a Baz
*/`,
);
expect(result1).toMatchSnapshot();
});
test("Non-english description with dot", async () => {
const result = await subject(
`/**
* Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu groß
*
* Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu 3434
*
* @description Wir brauchen hier eine effizientere Lösung. Die generierten Dateien sind zu groß
* @param a ssss
*/
/**
* Unicode est un standard informatique qui permet des échanges de textes dans différentes langues, à un niveau mondial. Il est développé par le Consortium Unicode, qui vise au codage de texte écrit en donnant à tout caractère de n'importe quel système d'écriture un nom et un identifiant numérique, et ce de manière unifiée, quels que soient la plate-forme informatique ou le logiciel utilisé
*
* @see https://fr.wikipedia.org/wiki/Unicode
*/
/**
* Юнико́д[1] (чаще всего) или Унико́д[2] (англ. Unicode) — стандарт кодирования символов, включающий в себя знаки почти всех письменных языков мира[3]. В настоящее время стандарт является преобладающим в Интернете
*
* @see https://ru.wikipedia.org/wiki/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4
*/
/**
* Unicode(ユニコード)は、符号化文字集合や文字符号化方式などを定めた、文字コードの業界規格。文字集合(文字セット)が単一の大規模文字セットであること(「Uni」という名はそれに由来する)などが特徴である
*
* @see https://ja.wikipedia.org/wiki/Unicode
*/
`,
{
jsdocDescriptionWithDot: true,
},
);
expect(result).toMatchSnapshot();
});
test("New Lines with star", async () => {
const result1 = await subject(
`/**
* Simplifies the token stream to ease the matching with the expected token stream.
*
* * Strings are kept as-is
* * In arrays each value is transformed individually
* * Values that are empty (empty arrays or strings only containing whitespace)
*
* @param {TokenStream} tokenStream
* @returns {SimplifiedTokenStream}
*/
`,
);
expect(result1).toMatchSnapshot();
const result2 = await subject(
`/**
* Some comment text.
*
* **Warning:** I am a warning.
*/
`,
);
expect(result2).toMatchSnapshot();
});
test("# in block code", async () => {
const result1 = await subject(
`/**
* \`\`\`py
* # This program adds two numbers
*
* num1 = 1.5
* num2 = 6.3
*
* # Add two numbers
* sum = num1 + num2
*
* # Display the sum
* print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
* \`\`\`
*/
`,
);
expect(result1).toMatchSnapshot();
});
test("Long words", async () => {
const result2 = await subject(
`
/**
* 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567
*/
`,
{
jsdocCommentLineStrategy: "multiline",
},
);
expect(result2).toMatchSnapshot();
});
test("Markdown Table", async () => {
const result1 = await subject(
`
/**
* description
* | A| B |C |
* | - | - | - |
* |C | V | B |
* |1|2|3|
*
* description
*
*
* | A| B |C |
* |C | V | B |
* |1|2|3|
* end
*/
`,
);
expect(result1).toMatchSnapshot();
const result2 = await subject(
`
/**
* | A| B |C |
* | - | - | - |
* |C | V | B |
* |1|2|3|
*/
`,
);
expect(result2).toMatchSnapshot();
const result3 = await subject(
`
/**
* @param {string} a description
* | A| B |C |
* | - | - | - |
* |C | V | B |
* |1|2|3|
*/
`,
);
expect(result3).toMatchSnapshot();
const result4 = await subject(
`
/**
* description
* \`\`\`
* fenced code
* | A| B |C |
* | - | - | - |
* |C | V | B |
* |1|2|3|
* \`\`\`
*
* \`\`\`
* Second fenced table-like
* 10
* |--3
* \`--4
* \`\`\`
*/
`,
);
expect(result4).toMatchSnapshot();
const result5 = await subject(
`
/**
* description
*
* indented code
*
* | A| B |C |
* | - | - | - |
* |C | V | B |
* |1|2|3|
*/
`,
);
expect(result5).toMatchSnapshot();
});
test("Jsdoc link in description", async () => {
const result1 = await subject(`
/**
* Calculate the
* {@link https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between two sets.
* @param second
* @param first
*/
export function difference<T>(first: Set<T>, second: Set<T>): Set<T>
/**
* Calculate the
* {@link https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* {@link https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between two sets.
*/
/**
* Calculate the
* {@link https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between
* {@link https://en.wikipedia.org/wiki/Complement}
* between two sets.
*/`);
expect(result1).toMatchSnapshot();
});
test("Jsdoc link synonyms in description", async () => {
const result1 = await subject(`
/**
* Calculate the
* {@linkcode https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between two sets.
* @param second
* @param first
*/
export function difference<T>(first: Set<T>, second: Set<T>): Set<T>
/**
* Calculate the
* {@linkcode https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* {@linkcode https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between two sets.
*/
/**
* Calculate the
* {@linkcode https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between
* {@linkcode https://en.wikipedia.org/wiki/Complement}
* between two sets.
*/
/**
* Calculate the
* {@linkplain https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between two sets.
* @param second
* @param first
*/
export function difference<T>(first: Set<T>, second: Set<T>): Set<T>
/**
* Calculate the
* {@linkplain https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* {@linkplain https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between two sets.
*/
/**
* Calculate the
* {@linkplain https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement difference}
* between
* {@linkplain https://en.wikipedia.org/wiki/Complement}
* between two sets.
*/`);
expect(result1).toMatchSnapshot();
});
test("Markdown link", async () => {
const result1 = await subject(`
/**
@param {string} [dir] [Next.js](https://nextjs.org) project directory path.
*/
`);
expect(result1).toMatchSnapshot();
});
test("Jsx tsx css ", async () => {
const result1 = await subject(`
/**
* \`\`\`js
* let a
* \`\`\`
*
* \`\`\`jsx
* let a
* \`\`\`
*
* \`\`\`css
* .body {color:red;
* }
* \`\`\`
*
* \`\`\`html
* <div class="body" > </ div>
* \`\`\`
*/
`);
expect(result1).toMatchSnapshot();
});
test("Not Capitalizing", async () => {
const comment = `/**
* simplifies the token stream to ease the matching with the expected token stream.
* Simplifies the token stream to ease the matching with the expected token stream.
*
* * Strings are kept as-is
* * in arrays each value is transformed individually
* * Values that are empty (empty arrays or strings only containing whitespace)
*
* @param {TokenStream} tokenStream Description
* @returns {SimplifiedTokenStream} description
*/
`;
const result1 = await subject(comment, {
jsdocCapitalizeDescription: false,
});
expect(result1).toMatchSnapshot();
const result2 = await subject(comment, {
jsdocCapitalizeDescription: true,
});
expect(result2).toMatchSnapshot();
});
test("Code in description", async () => {
const comment = `
/**
* Inspired from react-native View
*
* \`\`\`js
* import { View } from "react-native";
*
*
*
* function MyComponent() {
* return (
* <View style={{ alignItems: 'center' }}>
* <View variant="a" href="/" onPress={()=>{
* history.push('/')
* }} style={{ width:300,height:50 }} >
* <Text>Hello World</Text>
* </View>
* </View>
* );
* }
* \`\`\`
*/
`;
const indented = `
/**
* description
*
* an indented code block
* of a few lines.
*/
`;
const fenced = `
/**
* description
*
* \`\`\`
* A fenced code block
* spanning a few lines.
* \`\`\`
*/
`;
const result1 = await subject(comment);
expect(result1).toMatchSnapshot();
const result2 = await subject(indented);
expect(result2).toMatchSnapshot();
const result3 = await subject(indented, { jsdocPreferCodeFences: true });
expect(result3).toMatchSnapshot();
const result4 = await subject(fenced);
expect(result4).toMatchSnapshot();
const result5 = await subject(fenced, { jsdocPreferCodeFences: true });
expect(result5).toMatchSnapshot();
});
test("Link ", async () => {
const result = await subject(`
/**
* Name of something.
*
* See [documentation](1) for more details.