@@ -981,53 +981,125 @@ 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 parse @param with no name or description' , ( ) => {
1007
+ const testStr = `{% doc %} @param {% enddoc %}` ;
1008
+ cst = toCST ( testStr ) ;
1009
+
1010
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1011
+ expectPath ( cst , '0.children.0.value' ) . to . equal ( '@param' ) ;
1012
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'TextNode' ) ;
1013
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( '' ) ;
1014
+ expectPath ( cst , '0.children.0.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1015
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( '' ) ;
1029
1016
} ) ;
1030
- } ) ;
1017
+
1018
+ it ( 'should parse @param with name but no description' , ( ) => {
1019
+ const testStr = `{% doc %} @param paramWithNoDescription {% enddoc %}` ;
1020
+ cst = toCST ( testStr ) ;
1021
+
1022
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1023
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'TextNode' ) ;
1024
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithNoDescription' ) ;
1025
+ expectPath ( cst , '0.children.0.paramName.locStart' ) . to . equal (
1026
+ testStr . indexOf ( 'paramWithNoDescription' ) ,
1027
+ ) ;
1028
+ expectPath ( cst , '0.children.0.paramName.locEnd' ) . to . equal (
1029
+ testStr . indexOf ( 'paramWithNoDescription' ) + 'paramWithNoDescription' . length ,
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 @param with name and description' , ( ) => {
1036
+ const testStr = `{% doc %} @param paramWithDescription param with description {% enddoc %}` ;
1037
+ cst = toCST ( testStr ) ;
1038
+
1039
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1040
+ expectPath ( cst , '0.children.0.paramName.type' ) . to . equal ( 'TextNode' ) ;
1041
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithDescription' ) ;
1042
+ expectPath ( cst , '0.children.0.paramDescription.type' ) . to . equal ( 'TextNode' ) ;
1043
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'param with description' ) ;
1044
+ } ) ;
1045
+
1046
+ it ( 'should parse @param with type' , ( ) => {
1047
+ const testStr = `{% doc %} @param {String} paramWithType {% enddoc %}` ;
1048
+ cst = toCST ( testStr ) ;
1049
+
1050
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1051
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'paramWithType' ) ;
1052
+
1053
+ expectPath ( cst , '0.children.0.paramType.type' ) . to . equal ( 'TextNode' ) ;
1054
+ expectPath ( cst , '0.children.0.paramType.value' ) . to . equal ( 'String' ) ;
1055
+ expectPath ( cst , '0.children.0.paramType.locStart' ) . to . equal ( testStr . indexOf ( '{String}' ) ) ;
1056
+ expectPath ( cst , '0.children.0.paramType.locEnd' ) . to . equal (
1057
+ testStr . indexOf ( '{String}' ) + '{String}' . length ,
1058
+ ) ;
1059
+ } ) ;
1060
+
1061
+ it ( 'should parse @param with description seperated by a dash' , ( ) => {
1062
+ const testStr = `{% doc %}
1063
+ @param dashWithSpace - param with description
1064
+ @param dashWithNoSpace -param with description
1065
+ @param notDashSeparated param with description
1066
+ {% enddoc %}` ;
1067
+ cst = toCST ( testStr ) ;
1068
+
1069
+ expectPath ( cst , '0.children.0.paramDescription.dashSeparated' ) . to . equal ( true ) ;
1070
+ expectPath ( cst , '0.children.1.paramDescription.dashSeparated' ) . to . equal ( true ) ;
1071
+ expectPath ( cst , '0.children.2.paramDescription.dashSeparated' ) . to . equal ( false ) ;
1072
+ } ) ;
1073
+
1074
+ it ( 'should parse unsupported doc tags as text nodes' , ( ) => {
1075
+ const testStr = `{% doc %} @unsupported this tag is not supported {% enddoc %}` ;
1076
+ cst = toCST ( testStr ) ;
1077
+
1078
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'TextNode' ) ;
1079
+ expectPath ( cst , '0.children.0.value' ) . to . equal ( '@unsupported this tag is not supported' ) ;
1080
+ } ) ;
1081
+
1082
+ it ( 'should parse multiple doc tags in sequence' , ( ) => {
1083
+ const testStr = `{% doc %}
1084
+ @param param1 first parameter
1085
+ @param param2 second parameter
1086
+ @unsupported
1087
+ {% enddoc %}` ;
1088
+
1089
+ cst = toCST ( testStr ) ;
1090
+
1091
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1092
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'param1' ) ;
1093
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'first parameter' ) ;
1094
+
1095
+ expectPath ( cst , '0.children.1.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1096
+ expectPath ( cst , '0.children.1.paramName.value' ) . to . equal ( 'param2' ) ;
1097
+ expectPath ( cst , '0.children.1.paramDescription.value' ) . to . equal ( 'second parameter' ) ;
1098
+
1099
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'TextNode' ) ;
1100
+ expectPath ( cst , '0.children.2.value' ) . to . equal ( '@unsupported' ) ;
1101
+ } ) ;
1102
+ }
1031
1103
} ) ;
1032
1104
} ) ;
1033
1105
0 commit comments