@@ -22,6 +22,7 @@ describe('Unit: getSnippetDefinition', () => {
22
22
name : 'product-card' ,
23
23
liquidDoc : {
24
24
parameters : [ ] ,
25
+ examples : [ ] ,
25
26
} ,
26
27
} ) ;
27
28
} ) ;
@@ -48,36 +49,151 @@ describe('Unit: getSnippetDefinition', () => {
48
49
description : 'The first param' ,
49
50
type : 'String' ,
50
51
required : true ,
52
+ nodeType : 'param' ,
51
53
} ,
52
54
{
53
55
name : 'secondParam' ,
54
56
description : 'The second param' ,
55
57
type : 'Number' ,
56
58
required : true ,
59
+ nodeType : 'param' ,
57
60
} ,
58
61
{
59
62
name : 'optionalParam' ,
60
63
description : 'The optional param' ,
61
64
type : 'String' ,
62
65
required : false ,
66
+ nodeType : 'param' ,
63
67
} ,
64
68
{
65
69
name : 'paramWithNoType' ,
66
70
description : 'param with no type' ,
67
71
type : null ,
68
72
required : true ,
73
+ nodeType : 'param' ,
69
74
} ,
70
75
{
71
76
name : 'paramWithOnlyName' ,
72
77
description : null ,
73
78
type : null ,
74
79
required : true ,
80
+ nodeType : 'param' ,
75
81
} ,
76
82
{
77
83
name : 'paramWithNoDescription' ,
78
84
description : null ,
79
85
type : 'Number' ,
80
86
required : true ,
87
+ nodeType : 'param' ,
88
+ } ,
89
+ ] ,
90
+ examples : [ ] ,
91
+ } ,
92
+ } ) ;
93
+ } ) ;
94
+
95
+ it ( 'should extract examples from @example annotations' , async ( ) => {
96
+ const ast = toAST ( `
97
+ {% doc %}
98
+ @example
99
+ {{ product }}
100
+ {% enddoc %}
101
+ ` ) ;
102
+
103
+ const result = getSnippetDefinition ( ast , 'product-card' ) ;
104
+ expect ( result ) . to . deep . equal ( {
105
+ name : 'product-card' ,
106
+ liquidDoc : {
107
+ parameters : [ ] ,
108
+ examples : [
109
+ {
110
+ content : '\n {{ product }}\n' ,
111
+ nodeType : 'example' ,
112
+ } ,
113
+ ] ,
114
+ } ,
115
+ } ) ;
116
+ } ) ;
117
+
118
+ it ( 'should extract examples from @example annotations with multiple lines' , async ( ) => {
119
+ const ast = toAST ( `
120
+ {% doc %}
121
+ @example
122
+ {{ product }}
123
+ {{ product.title }}
124
+ {% enddoc %}
125
+ ` ) ;
126
+
127
+ const result = getSnippetDefinition ( ast , 'product-card' ) ;
128
+ expect ( result ) . to . deep . equal ( {
129
+ name : 'product-card' ,
130
+ liquidDoc : {
131
+ parameters : [ ] ,
132
+ examples : [
133
+ {
134
+ content : '\n {{ product }}\n {{ product.title }}\n' ,
135
+ nodeType : 'example' ,
136
+ } ,
137
+ ] ,
138
+ } ,
139
+ } ) ;
140
+ } ) ;
141
+
142
+ it ( 'should extract example from @example and @param annotations' , async ( ) => {
143
+ const ast = toAST ( `
144
+ {% doc %}
145
+ @param {String} product - The product
146
+ @example
147
+ {{ product }} // This is an example
148
+ {% enddoc %}
149
+ ` ) ;
150
+
151
+ const result = getSnippetDefinition ( ast , 'product-card' ) ;
152
+ expect ( result ) . to . deep . equal ( {
153
+ name : 'product-card' ,
154
+ liquidDoc : {
155
+ parameters : [
156
+ {
157
+ name : 'product' ,
158
+ description : 'The product' ,
159
+ type : 'String' ,
160
+ required : true ,
161
+ nodeType : 'param' ,
162
+ } ,
163
+ ] ,
164
+ examples : [
165
+ {
166
+ content : '\n {{ product }} // This is an example\n' ,
167
+ nodeType : 'example' ,
168
+ } ,
169
+ ] ,
170
+ } ,
171
+ } ) ;
172
+ } ) ;
173
+
174
+ it ( 'should extract multiple examples from @example annotations' , async ( ) => {
175
+ const ast = toAST ( `
176
+ {% doc %}
177
+ @example
178
+ {{ product }}
179
+ @example
180
+ {{ product.title }}
181
+ {% enddoc %}
182
+ ` ) ;
183
+
184
+ const result = getSnippetDefinition ( ast , 'product-card' ) ;
185
+ expect ( result ) . to . deep . equal ( {
186
+ name : 'product-card' ,
187
+ liquidDoc : {
188
+ parameters : [ ] ,
189
+ examples : [
190
+ {
191
+ content : '\n {{ product }}\n' ,
192
+ nodeType : 'example' ,
193
+ } ,
194
+ {
195
+ content : '\n {{ product.title }}\n' ,
196
+ nodeType : 'example' ,
81
197
} ,
82
198
] ,
83
199
} ,
0 commit comments