@@ -1011,31 +1011,150 @@ describe('Unit: Stage 1 (CST)', () => {
1011
1011
expectPath ( cst , '0.children.0.value' ) . to . equal ( '@param' ) ;
1012
1012
} ) ;
1013
1013
1014
- it ( 'should parse @param with name' , ( ) => {
1014
+ it ( 'should parse required @param with name' , ( ) => {
1015
1015
const testStr = `{% doc %} @param paramWithNoDescription {% enddoc %}` ;
1016
1016
cst = toCST ( testStr ) ;
1017
1017
1018
1018
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1019
- expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'TextNode' ) ;
1020
- expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithNoDescription' ) ;
1021
- expectPath ( cst , '0.children.0.paramName.locStart' ) . to . equal (
1019
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1020
+ expectPath ( cst , '0.children.0.paramName.required' ) . to . equal ( true ) ;
1021
+ expectPath ( cst , '0.children.0.paramName.content.value' ) . to . equal (
1022
+ 'paramWithNoDescription' ,
1023
+ ) ;
1024
+ expectPath ( cst , '0.children.0.paramName.content.locStart' ) . to . equal (
1022
1025
testStr . indexOf ( 'paramWithNoDescription' ) ,
1023
1026
) ;
1024
1027
expectPath ( cst , '0.children.0.paramName.locEnd' ) . to . equal (
1025
1028
testStr . indexOf ( 'paramWithNoDescription' ) + 'paramWithNoDescription' . length ,
1026
1029
) ;
1030
+
1031
+ expectPath ( cst , '0.children.0.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1032
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( '' ) ;
1033
+ } ) ;
1034
+
1035
+ it ( 'should parse an optional @param' , ( ) => {
1036
+ const testStr = `{% doc %}
1037
+ @param [paramWithNoDescription]
1038
+ @param [ paramWithWhitespace ]
1039
+ @param {String} [optionalParam] - The optional param
1040
+ @param {String} [paramWithType]
1041
+ {% enddoc %}` ;
1042
+ cst = toCST ( testStr ) ;
1043
+
1044
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1045
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1046
+ expectPath ( cst , '0.children.0.paramName.required' ) . to . equal ( false ) ;
1047
+ expectPath ( cst , '0.children.0.paramName.content.value' ) . to . equal (
1048
+ 'paramWithNoDescription' ,
1049
+ ) ;
1050
+ expectPath ( cst , '0.children.0.paramName.content.locStart' ) . to . equal (
1051
+ testStr . indexOf ( 'paramWithNoDescription' ) ,
1052
+ ) ;
1053
+ expectPath ( cst , '0.children.0.paramName.content.locEnd' ) . to . equal (
1054
+ testStr . indexOf ( 'paramWithNoDescription' ) + 'paramWithNoDescription' . length ,
1055
+ ) ;
1027
1056
expectPath ( cst , '0.children.0.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1028
1057
expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( '' ) ;
1058
+
1059
+ expectPath ( cst , '0.children.1.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1060
+ expectPath ( cst , '0.children.1.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1061
+ expectPath ( cst , '0.children.1.paramName.required' ) . to . equal ( false ) ;
1062
+ expectPath ( cst , '0.children.1.paramName.content.value' ) . to . equal ( 'paramWithWhitespace' ) ;
1063
+ expectPath ( cst , '0.children.1.paramName.content.locStart' ) . to . equal (
1064
+ testStr . indexOf ( 'paramWithWhitespace' ) ,
1065
+ ) ;
1066
+ expectPath ( cst , '0.children.1.paramName.content.locEnd' ) . to . equal (
1067
+ testStr . indexOf ( 'paramWithWhitespace' ) + 'paramWithWhitespace' . length ,
1068
+ ) ;
1069
+
1070
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1071
+ expectPath ( cst , '0.children.2.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1072
+ expectPath ( cst , '0.children.2.paramName.required' ) . to . equal ( false ) ;
1073
+ expectPath ( cst , '0.children.2.paramType.type' ) . to . equal ( 'TextNode' ) ;
1074
+ expectPath ( cst , '0.children.2.paramType.value' ) . to . equal ( 'String' ) ;
1075
+ expectPath ( cst , '0.children.2.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1076
+ expectPath ( cst , '0.children.2.paramDescription.value' ) . to . equal ( 'The optional param' ) ;
1077
+
1078
+ expectPath ( cst , '0.children.3.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1079
+ expectPath ( cst , '0.children.3.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1080
+ expectPath ( cst , '0.children.3.paramName.required' ) . to . equal ( false ) ;
1081
+ expectPath ( cst , '0.children.3.paramType.value' ) . to . equal ( 'String' ) ;
1082
+ expectPath ( cst , '0.children.3.paramDescription.value' ) . to . equal ( '' ) ;
1083
+ } ) ;
1084
+
1085
+ it ( 'should parse @param with malformed optional delimiters as Text Nodes' , ( ) => {
1086
+ const testStr = `{% doc %}
1087
+ @param paramWithMissingHeadDelim]
1088
+ @param [paramWithMissingTailDelim
1089
+ @param missingHeadWithDescription] - description value
1090
+ @param [missingTailWithDescription - description value
1091
+ @param [too many words] description
1092
+ {% enddoc %}` ;
1093
+ cst = toCST ( testStr ) ;
1094
+
1095
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'TextNode' ) ;
1096
+ expectPath ( cst , '0.children.0.value' ) . to . equal ( '@param paramWithMissingHeadDelim]' ) ;
1097
+ expectPath ( cst , '0.children.0.locStart' ) . to . equal (
1098
+ testStr . indexOf ( '@param paramWithMissingHeadDelim]' ) ,
1099
+ ) ;
1100
+ expectPath ( cst , '0.children.0.locEnd' ) . to . equal (
1101
+ testStr . indexOf ( '@param paramWithMissingHeadDelim]' ) +
1102
+ '@param paramWithMissingHeadDelim]' . length ,
1103
+ ) ;
1104
+
1105
+ expectPath ( cst , '0.children.1.type' ) . to . equal ( 'TextNode' ) ;
1106
+ expectPath ( cst , '0.children.1.value' ) . to . equal ( '@param [paramWithMissingTailDelim' ) ;
1107
+ expectPath ( cst , '0.children.1.locStart' ) . to . equal (
1108
+ testStr . indexOf ( '@param [paramWithMissingTailDelim' ) ,
1109
+ ) ;
1110
+ expectPath ( cst , '0.children.1.locEnd' ) . to . equal (
1111
+ testStr . indexOf ( '@param [paramWithMissingTailDelim' ) +
1112
+ '@param [paramWithMissingTailDelim' . length ,
1113
+ ) ;
1114
+
1115
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'TextNode' ) ;
1116
+ expectPath ( cst , '0.children.2.value' ) . to . equal (
1117
+ '@param missingHeadWithDescription] - description value' ,
1118
+ ) ;
1119
+ expectPath ( cst , '0.children.2.locStart' ) . to . equal (
1120
+ testStr . indexOf ( '@param missingHeadWithDescription] - description value' ) ,
1121
+ ) ;
1122
+ expectPath ( cst , '0.children.2.locEnd' ) . to . equal (
1123
+ testStr . indexOf ( '@param missingHeadWithDescription] - description value' ) +
1124
+ '@param missingHeadWithDescription] - description value' . length ,
1125
+ ) ;
1126
+
1127
+ expectPath ( cst , '0.children.3.type' ) . to . equal ( 'TextNode' ) ;
1128
+ expectPath ( cst , '0.children.3.value' ) . to . equal (
1129
+ '@param [missingTailWithDescription - description value' ,
1130
+ ) ;
1131
+ expectPath ( cst , '0.children.3.locStart' ) . to . equal (
1132
+ testStr . indexOf ( '@param [missingTailWithDescription - description value' ) ,
1133
+ ) ;
1134
+ expectPath ( cst , '0.children.3.locEnd' ) . to . equal (
1135
+ testStr . indexOf ( '@param [missingTailWithDescription - description value' ) +
1136
+ '@param [missingTailWithDescription - description value' . length ,
1137
+ ) ;
1138
+
1139
+ expectPath ( cst , '0.children.4.type' ) . to . equal ( 'TextNode' ) ;
1140
+ expectPath ( cst , '0.children.4.value' ) . to . equal ( '@param [too many words] description' ) ;
1029
1141
} ) ;
1030
1142
1031
1143
it ( 'should parse @param with name and description' , ( ) => {
1032
1144
const testStr = `{% doc %} @param paramWithDescription param with description {% enddoc %}` ;
1033
1145
cst = toCST ( testStr ) ;
1034
1146
1035
1147
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1036
- expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'TextNode' ) ;
1037
- expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithDescription' ) ;
1038
- expectPath ( cst , '0.children.0.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1148
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1149
+ expectPath ( cst , '0.children.0.paramName.required' ) . to . equal ( true ) ;
1150
+ expectPath ( cst , '0.children.0.paramName.content.type' ) . to . equal ( 'TextNode' ) ;
1151
+ expectPath ( cst , '0.children.0.paramName.content.value' ) . to . equal ( 'paramWithDescription' ) ;
1152
+ expectPath ( cst , '0.children.0.paramName.content.locStart' ) . to . equal (
1153
+ testStr . indexOf ( 'paramWithDescription' ) ,
1154
+ ) ;
1155
+ expectPath ( cst , '0.children.0.paramName.content.locEnd' ) . to . equal (
1156
+ testStr . indexOf ( 'paramWithDescription' ) + 'paramWithDescription' . length ,
1157
+ ) ;
1039
1158
expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'param with description' ) ;
1040
1159
} ) ;
1041
1160
@@ -1044,7 +1163,10 @@ describe('Unit: Stage 1 (CST)', () => {
1044
1163
cst = toCST ( testStr ) ;
1045
1164
1046
1165
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1047
- expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithType' ) ;
1166
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1167
+ expectPath ( cst , '0.children.0.paramName.required' ) . to . equal ( true ) ;
1168
+ expectPath ( cst , '0.children.0.paramName.content.type' ) . to . equal ( 'TextNode' ) ;
1169
+ expectPath ( cst , '0.children.0.paramName.content.value' ) . to . equal ( 'paramWithType' ) ;
1048
1170
1049
1171
expectPath ( cst , '0.children.0.paramType.type' ) . to . equal ( 'TextNode' ) ;
1050
1172
expectPath ( cst , '0.children.0.paramType.value' ) . to . equal ( 'String' ) ;
@@ -1059,7 +1181,7 @@ describe('Unit: Stage 1 (CST)', () => {
1059
1181
cst = toCST ( testStr ) ;
1060
1182
1061
1183
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1062
- expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithType' ) ;
1184
+ expectPath ( cst , '0.children.0.paramName.content. value' ) . to . equal ( 'paramWithType' ) ;
1063
1185
1064
1186
expectPath ( cst , '0.children.0.paramType.type' ) . to . equal ( 'TextNode' ) ;
1065
1187
expectPath ( cst , '0.children.0.paramType.value' ) . to . equal ( 'String' ) ;
@@ -1098,11 +1220,11 @@ describe('Unit: Stage 1 (CST)', () => {
1098
1220
cst = toCST ( testStr ) ;
1099
1221
1100
1222
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1101
- expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'param1' ) ;
1223
+ expectPath ( cst , '0.children.0.paramName.content. value' ) . to . equal ( 'param1' ) ;
1102
1224
expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'first parameter' ) ;
1103
1225
1104
1226
expectPath ( cst , '0.children.1.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1105
- expectPath ( cst , '0.children.1.paramName.value' ) . to . equal ( 'param2' ) ;
1227
+ expectPath ( cst , '0.children.1.paramName.content. value' ) . to . equal ( 'param2' ) ;
1106
1228
expectPath ( cst , '0.children.1.paramDescription.value' ) . to . equal ( 'second parameter' ) ;
1107
1229
1108
1230
expectPath ( cst , '0.children.2.type' ) . to . equal ( 'TextNode' ) ;
@@ -1158,7 +1280,7 @@ describe('Unit: Stage 1 (CST)', () => {
1158
1280
'\n This is an example\n' ,
1159
1281
) ;
1160
1282
expectPath ( cst , '0.children.1.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1161
- expectPath ( cst , '0.children.1.paramName.value' ) . to . equal ( 'param1' ) ;
1283
+ expectPath ( cst , '0.children.1.paramName.content. value' ) . to . equal ( 'param1' ) ;
1162
1284
} ) ;
1163
1285
1164
1286
it ( 'should parse example node with whitespace and new lines' , ( ) => {
0 commit comments