@@ -1011,11 +1011,12 @@ 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.required' ) . to . equal ( true ) ;
1019
1020
expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'TextNode' ) ;
1020
1021
expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithNoDescription' ) ;
1021
1022
expectPath ( cst , '0.children.0.paramName.locStart' ) . to . equal (
@@ -1028,6 +1029,105 @@ describe('Unit: Stage 1 (CST)', () => {
1028
1029
expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( '' ) ;
1029
1030
} ) ;
1030
1031
1032
+ it ( 'should parse an optional @param' , ( ) => {
1033
+ const testStr = `{% doc %}
1034
+ @param [paramWithNoDescription]
1035
+ @param [ paramWithWhitespace ]
1036
+ @param {String} [optionalParam] - The optional param
1037
+ {% enddoc %}` ;
1038
+ cst = toCST ( testStr ) ;
1039
+
1040
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1041
+ expectPath ( cst , '0.children.0.required' ) . to . equal ( false ) ;
1042
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'TextNode' ) ;
1043
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithNoDescription' ) ;
1044
+ expectPath ( cst , '0.children.0.paramName.locStart' ) . to . equal (
1045
+ testStr . indexOf ( 'paramWithNoDescription' ) ,
1046
+ ) ;
1047
+ expectPath ( cst , '0.children.0.paramName.locEnd' ) . to . equal (
1048
+ testStr . indexOf ( 'paramWithNoDescription' ) + 'paramWithNoDescription' . length ,
1049
+ ) ;
1050
+ expectPath ( cst , '0.children.0.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1051
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( '' ) ;
1052
+
1053
+ expectPath ( cst , '0.children.1.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1054
+ expectPath ( cst , '0.children.1.required' ) . to . equal ( false ) ;
1055
+ expectPath ( cst , '0.children.1.paramName.type' ) . to . equal ( 'TextNode' ) ;
1056
+ expectPath ( cst , '0.children.1.paramName.value' ) . to . equal ( 'paramWithWhitespace' ) ;
1057
+ expectPath ( cst , '0.children.1.paramName.locStart' ) . to . equal (
1058
+ testStr . indexOf ( 'paramWithWhitespace' ) ,
1059
+ ) ;
1060
+ expectPath ( cst , '0.children.1.paramName.locEnd' ) . to . equal (
1061
+ testStr . indexOf ( 'paramWithWhitespace' ) + 'paramWithWhitespace' . length ,
1062
+ ) ;
1063
+
1064
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1065
+ expectPath ( cst , '0.children.2.required' ) . to . equal ( false ) ;
1066
+ expectPath ( cst , '0.children.2.paramType.value' ) . to . equal ( 'String' ) ;
1067
+ } ) ;
1068
+
1069
+ it ( 'should parse @param with missing optional fallback Text Nodes' , ( ) => {
1070
+ const testStr = `{% doc %}
1071
+ @param paramWithMissingHeadDelim]
1072
+ @param [paramWithMissingTailDelim
1073
+ @param missingHeadWithDescription] - description value
1074
+ @param [missingTailWithDescription - description value
1075
+ @param [too many words] description
1076
+ {% enddoc %}` ;
1077
+ cst = toCST ( testStr ) ;
1078
+
1079
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'TextNode' ) ;
1080
+ expectPath ( cst , '0.children.0.value' ) . to . equal ( '@param paramWithMissingHeadDelim]' ) ;
1081
+ expectPath ( cst , '0.children.0.locStart' ) . to . equal (
1082
+ testStr . indexOf ( '@param paramWithMissingHeadDelim]' ) ,
1083
+ ) ;
1084
+ expectPath ( cst , '0.children.0.locEnd' ) . to . equal (
1085
+ testStr . indexOf ( '@param paramWithMissingHeadDelim]' ) +
1086
+ '@param paramWithMissingHeadDelim]' . length ,
1087
+ ) ;
1088
+
1089
+ expectPath ( cst , '0.children.1.type' ) . to . equal ( 'TextNode' ) ;
1090
+ expectPath ( cst , '0.children.1.value' ) . to . equal ( '@param [paramWithMissingTailDelim' ) ;
1091
+ expectPath ( cst , '0.children.1.locStart' ) . to . equal (
1092
+ testStr . indexOf ( '@param [paramWithMissingTailDelim' ) ,
1093
+ ) ;
1094
+ expectPath ( cst , '0.children.1.locEnd' ) . to . equal (
1095
+ testStr . indexOf ( '@param [paramWithMissingTailDelim' ) +
1096
+ '@param [paramWithMissingTailDelim' . length ,
1097
+ ) ;
1098
+
1099
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'TextNode' ) ;
1100
+ expectPath ( cst , '0.children.2.value' ) . to . equal (
1101
+ '@param missingHeadWithDescription] - description value' ,
1102
+ ) ;
1103
+ expectPath ( cst , '0.children.2.locStart' ) . to . equal (
1104
+ testStr . indexOf ( '@param missingHeadWithDescription] - description value' ) ,
1105
+ ) ;
1106
+ expectPath ( cst , '0.children.2.locEnd' ) . to . equal (
1107
+ testStr . indexOf ( '@param missingHeadWithDescription] - description value' ) +
1108
+ '@param missingHeadWithDescription] - description value' . length ,
1109
+ ) ;
1110
+
1111
+ expectPath ( cst , '0.children.3.type' ) . to . equal ( 'TextNode' ) ;
1112
+ expectPath ( cst , '0.children.3.value' ) . to . equal (
1113
+ '@param [missingTailWithDescription - description value' ,
1114
+ ) ;
1115
+ expectPath ( cst , '0.children.3.locStart' ) . to . equal (
1116
+ testStr . indexOf ( '@param [missingTailWithDescription - description value' ) ,
1117
+ ) ;
1118
+ expectPath ( cst , '0.children.3.locEnd' ) . to . equal (
1119
+ testStr . indexOf ( '@param [missingTailWithDescription - description value' ) +
1120
+ '@param [missingTailWithDescription - description value' . length ,
1121
+ ) ;
1122
+
1123
+ expectPath ( cst , '0.children.4.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1124
+ expectPath ( cst , '0.children.4.required' ) . to . equal ( false ) ;
1125
+ expectPath ( cst , '0.children.4.paramName.type' ) . to . equal ( 'TextNode' ) ;
1126
+ expectPath ( cst , '0.children.4.paramName.value' ) . to . equal ( 'too many words' ) ;
1127
+ expectPath ( cst , '0.children.4.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1128
+ expectPath ( cst , '0.children.4.paramDescription.value' ) . to . equal ( 'description' ) ;
1129
+ } ) ;
1130
+
1031
1131
it ( 'should parse @param with name and description' , ( ) => {
1032
1132
const testStr = `{% doc %} @param paramWithDescription param with description {% enddoc %}` ;
1033
1133
cst = toCST ( testStr ) ;
0 commit comments