@@ -13,68 +13,6 @@ import { extractTagName } from "../lib/converter/comments/tagName.js";
1313import { type FileId , FileRegistry } from "../lib/models/FileRegistry.js" ;
1414import { dedent , MinimalSourceFile , type NormalizedPath } from "#utils" ;
1515
16- const CONTENT_PARTS = [ "text" , "`code`" ] ;
17- const SEPARATORS = [ " " , "\n" , "\n " , "\n\n" ] ;
18- const MAX_CONTENT_PARTS = 3 ;
19- function * generateLinkTitleCases ( ) {
20- const makeCase = ( linkTitle : string ) => {
21- const ok = ! linkTitle . includes ( "\n\n" ) ;
22- const input = `[${ linkTitle } ](./relative.md)` ;
23- const expect : CommentDisplayPart [ ] = input
24- . replace ( "(./relative.md)" , "(" )
25- . split ( / ( ` c o d e ` ) / g)
26- . map ( ( text ) => {
27- const kind = text [ 0 ] === "`" ? "code" : "text" ;
28- return { kind, text } ;
29- } ) ;
30- if ( ok ) {
31- expect . push (
32- {
33- kind : "relative-link" ,
34- text : "./relative.md" ,
35- target : 1 as FileId ,
36- targetAnchor : undefined ,
37- } ,
38- { kind : "text" , text : ")" } ,
39- ) ;
40- } else {
41- expect [ expect . length - 1 ] . text += "./relative.md)" ;
42- }
43- expect [ expect . length - 1 ] . text += "\n[" ;
44- expect . push (
45- { kind : "code" , text : "`code`" } ,
46- { kind : "text" , text : "](" } ,
47- {
48- kind : "relative-link" ,
49- text : "./relative.md" ,
50- target : 1 as FileId ,
51- targetAnchor : undefined ,
52- } ,
53- { kind : "text" , text : ")" } ,
54- ) ;
55- return { input : input + "\n[`code`](./relative.md)" , expect } ;
56- } ;
57- for ( let n = 1 ; n <= MAX_CONTENT_PARTS ; n ++ ) {
58- // 3 bits for each part (except the first): <A><BB>
59- // <A> selects a part from CONTENT_PARTS
60- // <BB> selects a preceding separator from SEPARATORS
61- for ( let bits = 0 ; bits < 2 ** ( 3 * n ) ; bits += 4 ) {
62- const inner = Array . from ( { length : n } , ( _ , i ) => {
63- const partSelections = bits >> ( 3 * i ) ;
64- const part = CONTENT_PARTS [ partSelections & 4 ? 1 : 0 ] ;
65- const sepText = SEPARATORS [ partSelections & 3 ] ;
66- return i === 0 ? part : `${ sepText } ${ part } ` ;
67- } ) . join ( "" ) ;
68- // We also wrap the parts with arbitrary leading and trailing whitespace
69- for ( const prefix of [ "" , ...SEPARATORS ] ) {
70- for ( const suffix of [ "" , ...SEPARATORS ] ) {
71- yield makeCase ( `${ prefix } ${ inner } ${ suffix } ` ) ;
72- }
73- }
74- }
75- }
76- }
77-
7816describe ( "Block Comment Lexer" , ( ) => {
7917 function lex ( text : string ) : Token [ ] {
8018 return Array . from ( lexBlockComment ( text ) ) ;
@@ -1595,16 +1533,25 @@ describe("Comment Parser", () => {
15951533 } ) ;
15961534
15971535 it ( "Parses markdown link titles with arbitrarily-separated arbitrary combinations of text and code" , ( ) => {
1598- const embedInComment = ( input : string ) => {
1599- const lines = input . split ( "\n" ) ;
1600- const embedded = `/**\n${ lines . map ( line => " * " + line ) . join ( "\n" ) } \n */` ;
1601- return getComment ( embedded ) ;
1602- } ;
1603-
1604- for ( const { input, expect } of generateLinkTitleCases ( ) ) {
1605- const comment = embedInComment ( input ) ;
1606- equal ( comment . summary , expect , `input: ${ JSON . stringify ( input ) } ` ) ;
1536+ const comment = `/**
1537+ [text](./1)
1538+ [text \`code\`]( \t ./2 )
1539+ [\ntext \`code\`\n](./3)
1540+ [\ntext\n\`code\`\n]( ./4 )
1541+ [ \t\`code\` text]( \t./5\t )
1542+
1543+ [\n\n\`code\`](./no1)
1544+ [text\n\n](./no2)
1545+ [ text\n](\n \n ./no3 \n)
1546+ [ text\n\ntext](./no4)
1547+ */` ;
1548+
1549+ const relativeParts = getComment ( comment ) . summary . filter ( p => p . kind === "relative-link" ) ;
1550+
1551+ for ( let i = 0 ; i < relativeParts . length ; i ++ ) {
1552+ equal ( relativeParts [ i ] . text , `./${ i + 1 } ` ) ;
16071553 }
1554+ equal ( relativeParts . length , 5 ) ;
16081555 } ) ;
16091556
16101557 it ( "Recognizes markdown reference definition blocks" , ( ) => {
@@ -1848,27 +1795,28 @@ describe("Raw Comment Parser", () => {
18481795 } ) ;
18491796
18501797 it ( "Parses markdown link titles with arbitrarily-separated arbitrary combinations of text and code" , ( ) => {
1851- for ( const { input, expect } of generateLinkTitleCases ( ) ) {
1852- const comment = getComment ( input ) ;
1853- equal ( comment . content , expect , `input: ${ JSON . stringify ( input ) } ` ) ;
1798+ const comment = `/**
1799+ [text](./1)
1800+ [text \`code\`]( \t ./2 )
1801+ [\ntext \`code\`\n](./3)
1802+ [\ntext\n\`code\`\n]( ./4 )
1803+ [ \t\`code\` text]( \t./5\t )
1804+
1805+ [\n\n\`code\`](./no1)
1806+ [text\n\n](./no2)
1807+ [ text\n](\n \n ./no3 \n)
1808+ [ text\n\ntext](./no4)
1809+ */` ;
1810+
1811+ const relativeParts = getComment ( comment ) . content . filter ( p => p . kind === "relative-link" ) ;
1812+
1813+ for ( let i = 0 ; i < relativeParts . length ; i ++ ) {
1814+ equal ( relativeParts [ i ] . text , `./${ i + 1 } ` ) ;
18541815 }
1816+ equal ( relativeParts . length , 5 ) ;
18551817 } ) ;
18561818} ) ;
18571819
1858- describe ( "Markdown Link Title Generation" , ( ) => {
1859- const inputs : string [ ] = [ ] ;
1860- for ( const { input } of generateLinkTitleCases ( ) ) {
1861- inputs . push ( input ) ;
1862- }
1863- const inputsSet = new Set ( inputs ) ;
1864- equal ( inputsSet . size , inputs . length , "each generated input must be unique" ) ;
1865-
1866- const expectCount = Array . from ( { length : MAX_CONTENT_PARTS } , ( _ , i ) => i + 1 )
1867- . map ( n => ( SEPARATORS . length * CONTENT_PARTS . length ) ** n / SEPARATORS . length * ( SEPARATORS . length + 1 ) ** 2 )
1868- . reduce ( ( a , b ) => a + b ) ;
1869- equal ( inputsSet . size , expectCount , "generated input count" ) ;
1870- } ) ;
1871-
18721820describe ( "extractTagName" , ( ) => {
18731821 it ( "Handles simple name" , ( ) => {
18741822 equal ( extractTagName ( "T - abc" ) , { name : "T" , newText : "abc" } ) ;
0 commit comments