@@ -981,53 +981,134 @@ describe('Unit: Stage 1 (CST)', () => {
981
981
expectPath ( cst , '0.blockEndLocEnd' ) . to . equal ( testStr . length ) ;
982
982
}
983
983
} ) ;
984
+ } ) ;
984
985
985
- it ( 'should parse doc tags ', ( ) => {
986
- for ( const { toCST, expectPath } of testCases ) {
987
- const testStr = `{% doc -%} Renders loading-spinner. {%- enddoc %}` ;
988
-
986
+ describe ( 'Case: LiquidDoc ', ( ) => {
987
+ for ( const { toCST, expectPath } of testCases ) {
988
+ it ( 'should parse basic doc tag structure' , ( ) => {
989
+ const testStr = `{% doc -%} content {%- enddoc %}` ;
989
990
cst = toCST ( testStr ) ;
991
+
990
992
expectPath ( cst , '0.type' ) . to . equal ( 'LiquidRawTag' ) ;
991
993
expectPath ( cst , '0.name' ) . to . equal ( 'doc' ) ;
992
- expectPath ( cst , '0.body' ) . to . include ( 'Renders loading-spinner' ) ;
993
994
expectPath ( cst , '0.whitespaceStart' ) . to . equal ( '' ) ;
994
995
expectPath ( cst , '0.whitespaceEnd' ) . to . equal ( '-' ) ;
995
996
expectPath ( cst , '0.delimiterWhitespaceStart' ) . to . equal ( '-' ) ;
996
997
expectPath ( cst , '0.delimiterWhitespaceEnd' ) . to . equal ( '' ) ;
997
- expectPath ( cst , '0.blockStartLocStart' ) . to . equal ( 0 ) ;
998
- expectPath ( cst , '0.blockStartLocEnd' ) . to . equal ( 0 + '{% doc -%}' . length ) ;
998
+ expectPath ( cst , '0.blockStartLocStart' ) . to . equal ( testStr . indexOf ( '{% doc -%}' ) ) ;
999
+ expectPath ( cst , '0.blockStartLocEnd' ) . to . equal (
1000
+ testStr . indexOf ( '{% doc -%}' ) + '{% doc -%}' . length ,
1001
+ ) ;
999
1002
expectPath ( cst , '0.blockEndLocStart' ) . to . equal ( testStr . length - '{%- enddoc %}' . length ) ;
1000
1003
expectPath ( cst , '0.blockEndLocEnd' ) . to . equal ( testStr . length ) ;
1001
- expectPath ( cst , '0.children' ) . to . deep . equal ( [
1002
- {
1003
- locEnd : 35 ,
1004
- locStart : 11 ,
1005
- source : '{% doc -%} Renders loading-spinner. {%- enddoc %}' ,
1006
- type : 'TextNode' ,
1007
- value : 'Renders loading-spinner.' ,
1008
- } ,
1009
- ] ) ;
1010
- }
1011
- } ) ;
1004
+ } ) ;
1012
1005
1013
- it ( 'should parse tag open / close' , ( ) => {
1014
- BLOCKS . forEach ( ( block : string ) => {
1015
- for ( const { toCST, expectPath } of testCases ) {
1016
- cst = toCST ( `{% ${ block } args -%}{%- end${ block } %}` ) ;
1017
- expectPath ( cst , '0.type' ) . to . equal ( 'LiquidTagOpen' , block ) ;
1018
- expectPath ( cst , '0.name' ) . to . equal ( block ) ;
1019
- expectPath ( cst , '0.whitespaceStart' ) . to . equal ( null ) ;
1020
- expectPath ( cst , '0.whitespaceEnd' ) . to . equal ( '-' ) ;
1021
- if ( ! NamedTags . hasOwnProperty ( block ) ) {
1022
- expectPath ( cst , '0.markup' ) . to . equal ( 'args' ) ;
1023
- }
1024
- expectPath ( cst , '1.type' ) . to . equal ( 'LiquidTagClose' ) ;
1025
- expectPath ( cst , '1.name' ) . to . equal ( block ) ;
1026
- expectPath ( cst , '1.whitespaceStart' ) . to . equal ( '-' ) ;
1027
- expectPath ( cst , '1.whitespaceEnd' ) . to . equal ( null ) ;
1028
- }
1006
+ it ( 'should not parse @param without a name' , ( ) => {
1007
+ const testStr = `{% doc %} @param {% enddoc %}` ;
1008
+ cst = toCST ( testStr ) ;
1009
+
1010
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'TextNode' ) ;
1011
+ expectPath ( cst , '0.children.0.value' ) . to . equal ( '@param' ) ;
1029
1012
} ) ;
1030
- } ) ;
1013
+
1014
+ it ( 'should parse @param with name' , ( ) => {
1015
+ const testStr = `{% doc %} @param paramWithNoDescription {% enddoc %}` ;
1016
+ cst = toCST ( testStr ) ;
1017
+
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 (
1022
+ testStr . indexOf ( 'paramWithNoDescription' ) ,
1023
+ ) ;
1024
+ expectPath ( cst , '0.children.0.paramName.locEnd' ) . to . equal (
1025
+ testStr . indexOf ( 'paramWithNoDescription' ) + 'paramWithNoDescription' . length ,
1026
+ ) ;
1027
+ expectPath ( cst , '0.children.0.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1028
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( '' ) ;
1029
+ } ) ;
1030
+
1031
+ it ( 'should parse @param with name and description' , ( ) => {
1032
+ const testStr = `{% doc %} @param paramWithDescription param with description {% enddoc %}` ;
1033
+ cst = toCST ( testStr ) ;
1034
+
1035
+ 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' ) ;
1039
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'param with description' ) ;
1040
+ } ) ;
1041
+
1042
+ it ( 'should parse @param with type' , ( ) => {
1043
+ const testStr = `{% doc %} @param {String} paramWithType {% enddoc %}` ;
1044
+ cst = toCST ( testStr ) ;
1045
+
1046
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1047
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithType' ) ;
1048
+
1049
+ expectPath ( cst , '0.children.0.paramType.type' ) . to . equal ( 'TextNode' ) ;
1050
+ expectPath ( cst , '0.children.0.paramType.value' ) . to . equal ( 'String' ) ;
1051
+ expectPath ( cst , '0.children.0.paramType.locStart' ) . to . equal ( testStr . indexOf ( 'String' ) ) ;
1052
+ expectPath ( cst , '0.children.0.paramType.locEnd' ) . to . equal (
1053
+ testStr . indexOf ( 'String' ) + 'String' . length ,
1054
+ ) ;
1055
+ } ) ;
1056
+
1057
+ it ( 'should strip whitespace around param type for @param annotation' , ( ) => {
1058
+ const testStr = `{% doc %} @param { String } paramWithType {% enddoc %}` ;
1059
+ cst = toCST ( testStr ) ;
1060
+
1061
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1062
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithType' ) ;
1063
+
1064
+ expectPath ( cst , '0.children.0.paramType.type' ) . to . equal ( 'TextNode' ) ;
1065
+ expectPath ( cst , '0.children.0.paramType.value' ) . to . equal ( 'String' ) ;
1066
+ expectPath ( cst , '0.children.0.paramType.locStart' ) . to . equal ( testStr . indexOf ( 'String' ) ) ;
1067
+ expectPath ( cst , '0.children.0.paramType.locEnd' ) . to . equal (
1068
+ testStr . indexOf ( 'String' ) + 'String' . length ,
1069
+ ) ;
1070
+ } ) ;
1071
+
1072
+ it ( 'should accept punctation inside the param description body' , ( ) => {
1073
+ const testStr = `{% doc %} @param paramName paramDescription - asdf . \`should\` work {% enddoc %}` ;
1074
+ cst = toCST ( testStr ) ;
1075
+
1076
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal (
1077
+ 'paramDescription - asdf . `should` work' ,
1078
+ ) ;
1079
+ } ) ;
1080
+
1081
+ it ( 'should parse fallback nodes as text nodes' , ( ) => {
1082
+ const testStr = `{% doc %} @unsupported this should get matched as a fallback node and translated into a text node {% enddoc %}` ;
1083
+ cst = toCST ( testStr ) ;
1084
+
1085
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'TextNode' ) ;
1086
+ expectPath ( cst , '0.children.0.value' ) . to . equal (
1087
+ '@unsupported this should get matched as a fallback node and translated into a text node' ,
1088
+ ) ;
1089
+ } ) ;
1090
+
1091
+ it ( 'should parse multiple doc tags in sequence' , ( ) => {
1092
+ const testStr = `{% doc %}
1093
+ @param param1 first parameter
1094
+ @param param2 second parameter
1095
+ @unsupported
1096
+ {% enddoc %}` ;
1097
+
1098
+ cst = toCST ( testStr ) ;
1099
+
1100
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1101
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'param1' ) ;
1102
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'first parameter' ) ;
1103
+
1104
+ expectPath ( cst , '0.children.1.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1105
+ expectPath ( cst , '0.children.1.paramName.value' ) . to . equal ( 'param2' ) ;
1106
+ expectPath ( cst , '0.children.1.paramDescription.value' ) . to . equal ( 'second parameter' ) ;
1107
+
1108
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'TextNode' ) ;
1109
+ expectPath ( cst , '0.children.2.value' ) . to . equal ( '@unsupported' ) ;
1110
+ } ) ;
1111
+ }
1031
1112
} ) ;
1032
1113
} ) ;
1033
1114
0 commit comments