@@ -1011,31 +1011,154 @@ 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.paramNameContent.value' ) . to . equal (
1022
+ 'paramWithNoDescription' ,
1023
+ ) ;
1024
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.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.paramNameContent.value' ) . to . equal (
1048
+ 'paramWithNoDescription' ,
1049
+ ) ;
1050
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.locStart' ) . to . equal (
1051
+ testStr . indexOf ( 'paramWithNoDescription' ) ,
1052
+ ) ;
1053
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.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.paramNameContent.value' ) . to . equal (
1063
+ 'paramWithWhitespace' ,
1064
+ ) ;
1065
+ expectPath ( cst , '0.children.1.paramName.paramNameContent.locStart' ) . to . equal (
1066
+ testStr . indexOf ( 'paramWithWhitespace' ) ,
1067
+ ) ;
1068
+ expectPath ( cst , '0.children.1.paramName.paramNameContent.locEnd' ) . to . equal (
1069
+ testStr . indexOf ( 'paramWithWhitespace' ) + 'paramWithWhitespace' . length ,
1070
+ ) ;
1071
+
1072
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1073
+ expectPath ( cst , '0.children.2.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1074
+ expectPath ( cst , '0.children.2.paramName.required' ) . to . equal ( false ) ;
1075
+ expectPath ( cst , '0.children.2.paramType.type' ) . to . equal ( 'TextNode' ) ;
1076
+ expectPath ( cst , '0.children.2.paramType.value' ) . to . equal ( 'String' ) ;
1077
+ expectPath ( cst , '0.children.2.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1078
+ expectPath ( cst , '0.children.2.paramDescription.value' ) . to . equal ( 'The optional param' ) ;
1079
+
1080
+ expectPath ( cst , '0.children.3.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1081
+ expectPath ( cst , '0.children.3.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1082
+ expectPath ( cst , '0.children.3.paramName.required' ) . to . equal ( false ) ;
1083
+ expectPath ( cst , '0.children.3.paramType.value' ) . to . equal ( 'String' ) ;
1084
+ expectPath ( cst , '0.children.3.paramDescription.value' ) . to . equal ( '' ) ;
1085
+ } ) ;
1086
+
1087
+ it ( 'should parse @param with malformed optional delimiters as Text Nodes' , ( ) => {
1088
+ const testStr = `{% doc %}
1089
+ @param paramWithMissingHeadDelim]
1090
+ @param [paramWithMissingTailDelim
1091
+ @param missingHeadWithDescription] - description value
1092
+ @param [missingTailWithDescription - description value
1093
+ @param [too many words] description
1094
+ {% enddoc %}` ;
1095
+ cst = toCST ( testStr ) ;
1096
+
1097
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'TextNode' ) ;
1098
+ expectPath ( cst , '0.children.0.value' ) . to . equal ( '@param paramWithMissingHeadDelim]' ) ;
1099
+ expectPath ( cst , '0.children.0.locStart' ) . to . equal (
1100
+ testStr . indexOf ( '@param paramWithMissingHeadDelim]' ) ,
1101
+ ) ;
1102
+ expectPath ( cst , '0.children.0.locEnd' ) . to . equal (
1103
+ testStr . indexOf ( '@param paramWithMissingHeadDelim]' ) +
1104
+ '@param paramWithMissingHeadDelim]' . length ,
1105
+ ) ;
1106
+
1107
+ expectPath ( cst , '0.children.1.type' ) . to . equal ( 'TextNode' ) ;
1108
+ expectPath ( cst , '0.children.1.value' ) . to . equal ( '@param [paramWithMissingTailDelim' ) ;
1109
+ expectPath ( cst , '0.children.1.locStart' ) . to . equal (
1110
+ testStr . indexOf ( '@param [paramWithMissingTailDelim' ) ,
1111
+ ) ;
1112
+ expectPath ( cst , '0.children.1.locEnd' ) . to . equal (
1113
+ testStr . indexOf ( '@param [paramWithMissingTailDelim' ) +
1114
+ '@param [paramWithMissingTailDelim' . length ,
1115
+ ) ;
1116
+
1117
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'TextNode' ) ;
1118
+ expectPath ( cst , '0.children.2.value' ) . to . equal (
1119
+ '@param missingHeadWithDescription] - description value' ,
1120
+ ) ;
1121
+ expectPath ( cst , '0.children.2.locStart' ) . to . equal (
1122
+ testStr . indexOf ( '@param missingHeadWithDescription] - description value' ) ,
1123
+ ) ;
1124
+ expectPath ( cst , '0.children.2.locEnd' ) . to . equal (
1125
+ testStr . indexOf ( '@param missingHeadWithDescription] - description value' ) +
1126
+ '@param missingHeadWithDescription] - description value' . length ,
1127
+ ) ;
1128
+
1129
+ expectPath ( cst , '0.children.3.type' ) . to . equal ( 'TextNode' ) ;
1130
+ expectPath ( cst , '0.children.3.value' ) . to . equal (
1131
+ '@param [missingTailWithDescription - description value' ,
1132
+ ) ;
1133
+ expectPath ( cst , '0.children.3.locStart' ) . to . equal (
1134
+ testStr . indexOf ( '@param [missingTailWithDescription - description value' ) ,
1135
+ ) ;
1136
+ expectPath ( cst , '0.children.3.locEnd' ) . to . equal (
1137
+ testStr . indexOf ( '@param [missingTailWithDescription - description value' ) +
1138
+ '@param [missingTailWithDescription - description value' . length ,
1139
+ ) ;
1140
+
1141
+ expectPath ( cst , '0.children.4.type' ) . to . equal ( 'TextNode' ) ;
1142
+ expectPath ( cst , '0.children.4.value' ) . to . equal ( '@param [too many words] description' ) ;
1029
1143
} ) ;
1030
1144
1031
1145
it ( 'should parse @param with name and description' , ( ) => {
1032
1146
const testStr = `{% doc %} @param paramWithDescription param with description {% enddoc %}` ;
1033
1147
cst = toCST ( testStr ) ;
1034
1148
1035
1149
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' ) ;
1150
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1151
+ expectPath ( cst , '0.children.0.paramName.required' ) . to . equal ( true ) ;
1152
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.type' ) . to . equal ( 'TextNode' ) ;
1153
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.value' ) . to . equal (
1154
+ 'paramWithDescription' ,
1155
+ ) ;
1156
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.locStart' ) . to . equal (
1157
+ testStr . indexOf ( 'paramWithDescription' ) ,
1158
+ ) ;
1159
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.locEnd' ) . to . equal (
1160
+ testStr . indexOf ( 'paramWithDescription' ) + 'paramWithDescription' . length ,
1161
+ ) ;
1039
1162
expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'param with description' ) ;
1040
1163
} ) ;
1041
1164
@@ -1044,7 +1167,12 @@ describe('Unit: Stage 1 (CST)', () => {
1044
1167
cst = toCST ( testStr ) ;
1045
1168
1046
1169
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1047
- expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithType' ) ;
1170
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'LiquidDocParamNameNode' ) ;
1171
+ expectPath ( cst , '0.children.0.paramName.required' ) . to . equal ( true ) ;
1172
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.type' ) . to . equal ( 'TextNode' ) ;
1173
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.value' ) . to . equal (
1174
+ 'paramWithType' ,
1175
+ ) ;
1048
1176
1049
1177
expectPath ( cst , '0.children.0.paramType.type' ) . to . equal ( 'TextNode' ) ;
1050
1178
expectPath ( cst , '0.children.0.paramType.value' ) . to . equal ( 'String' ) ;
@@ -1059,7 +1187,9 @@ describe('Unit: Stage 1 (CST)', () => {
1059
1187
cst = toCST ( testStr ) ;
1060
1188
1061
1189
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1062
- expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithType' ) ;
1190
+ expectPath ( cst , '0.children.0.paramName.paramNameContent.value' ) . to . equal (
1191
+ 'paramWithType' ,
1192
+ ) ;
1063
1193
1064
1194
expectPath ( cst , '0.children.0.paramType.type' ) . to . equal ( 'TextNode' ) ;
1065
1195
expectPath ( cst , '0.children.0.paramType.value' ) . to . equal ( 'String' ) ;
@@ -1098,11 +1228,11 @@ describe('Unit: Stage 1 (CST)', () => {
1098
1228
cst = toCST ( testStr ) ;
1099
1229
1100
1230
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1101
- expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'param1' ) ;
1231
+ expectPath ( cst , '0.children.0.paramName.paramNameContent. value' ) . to . equal ( 'param1' ) ;
1102
1232
expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'first parameter' ) ;
1103
1233
1104
1234
expectPath ( cst , '0.children.1.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1105
- expectPath ( cst , '0.children.1.paramName.value' ) . to . equal ( 'param2' ) ;
1235
+ expectPath ( cst , '0.children.1.paramName.paramNameContent. value' ) . to . equal ( 'param2' ) ;
1106
1236
expectPath ( cst , '0.children.1.paramDescription.value' ) . to . equal ( 'second parameter' ) ;
1107
1237
1108
1238
expectPath ( cst , '0.children.2.type' ) . to . equal ( 'TextNode' ) ;
0 commit comments