@@ -981,58 +981,97 @@ 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 -%}
988
- @param asdf
989
- @unsupported
990
- {%- enddoc %}` ;
991
-
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 %}` ;
992
990
cst = toCST ( testStr ) ;
993
991
994
992
expectPath ( cst , '0.type' ) . to . equal ( 'LiquidRawTag' ) ;
995
993
expectPath ( cst , '0.name' ) . to . equal ( 'doc' ) ;
996
- expectPath ( cst , '0.body' ) . to . include ( '@param asdf' ) ;
997
994
expectPath ( cst , '0.whitespaceStart' ) . to . equal ( '' ) ;
998
995
expectPath ( cst , '0.whitespaceEnd' ) . to . equal ( '-' ) ;
999
996
expectPath ( cst , '0.delimiterWhitespaceStart' ) . to . equal ( '-' ) ;
1000
997
expectPath ( cst , '0.delimiterWhitespaceEnd' ) . to . equal ( '' ) ;
1001
- expectPath ( cst , '0.blockStartLocStart' ) . to . equal ( 0 ) ;
1002
- 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
+ ) ;
1003
1002
expectPath ( cst , '0.blockEndLocStart' ) . to . equal ( testStr . length - '{%- enddoc %}' . length ) ;
1004
1003
expectPath ( cst , '0.blockEndLocEnd' ) . to . equal ( testStr . length ) ;
1004
+ } ) ;
1005
+
1006
+ it ( 'should parse @param with no name or description' , ( ) => {
1007
+ const testStr = `{% doc %} @param {% enddoc %}` ;
1008
+ cst = toCST ( testStr ) ;
1005
1009
1006
1010
expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1007
- expectPath ( cst , '0.children.0.locStart' ) . to . equal ( testStr . indexOf ( '@param' ) ) ;
1008
- expectPath ( cst , '0.children.0.locEnd' ) . to . equal ( testStr . indexOf ( 'asdf' ) + 'asdf' . length ) ;
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 ( '' ) ;
1016
+ } ) ;
1009
1017
1010
- expectPath ( cst , '0.children.1.type' ) . to . equal ( 'TextNode' ) ;
1011
- expectPath ( cst , '0.children.1.locStart' ) . to . equal ( testStr . indexOf ( '@unsupported' ) ) ;
1012
- expectPath ( cst , '0.children.1.locEnd' ) . to . equal (
1013
- testStr . indexOf ( '@unsupported' ) + '@unsupported' . length ,
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' ) ,
1014
1027
) ;
1015
- }
1016
- } ) ;
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
+ } ) ;
1017
1034
1018
- it ( 'should parse tag open / close' , ( ) => {
1019
- BLOCKS . forEach ( ( block : string ) => {
1020
- for ( const { toCST, expectPath } of testCases ) {
1021
- cst = toCST ( `{% ${ block } args -%}{%- end${ block } %}` ) ;
1022
- expectPath ( cst , '0.type' ) . to . equal ( 'LiquidTagOpen' , block ) ;
1023
- expectPath ( cst , '0.name' ) . to . equal ( block ) ;
1024
- expectPath ( cst , '0.whitespaceStart' ) . to . equal ( null ) ;
1025
- expectPath ( cst , '0.whitespaceEnd' ) . to . equal ( '-' ) ;
1026
- if ( ! NamedTags . hasOwnProperty ( block ) ) {
1027
- expectPath ( cst , '0.markup' ) . to . equal ( 'args' ) ;
1028
- }
1029
- expectPath ( cst , '1.type' ) . to . equal ( 'LiquidTagClose' ) ;
1030
- expectPath ( cst , '1.name' ) . to . equal ( block ) ;
1031
- expectPath ( cst , '1.whitespaceStart' ) . to . equal ( '-' ) ;
1032
- expectPath ( cst , '1.whitespaceEnd' ) . to . equal ( null ) ;
1033
- }
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' ) ;
1034
1044
} ) ;
1035
- } ) ;
1045
+
1046
+ it ( 'should parse unsupported doc tags as text nodes' , ( ) => {
1047
+ const testStr = `{% doc %} @unsupported this tag is not supported {% enddoc %}` ;
1048
+ cst = toCST ( testStr ) ;
1049
+
1050
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'TextNode' ) ;
1051
+ expectPath ( cst , '0.children.0.value' ) . to . equal ( '@unsupported this tag is not supported' ) ;
1052
+ } ) ;
1053
+
1054
+ it ( 'should parse multiple doc tags in sequence' , ( ) => {
1055
+ const testStr = `{% doc %}
1056
+ @param param1 first parameter
1057
+ @param param2 second parameter
1058
+ @unsupported
1059
+ {% enddoc %}` ;
1060
+
1061
+ cst = toCST ( testStr ) ;
1062
+
1063
+ expectPath ( cst , '0.children.0.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1064
+ expectPath ( cst , '0.children.0.paramName.value' ) . to . equal ( 'param1' ) ;
1065
+ expectPath ( cst , '0.children.0.paramDescription.value' ) . to . equal ( 'first parameter' ) ;
1066
+
1067
+ expectPath ( cst , '0.children.1.type' ) . to . equal ( 'LiquidDocParamNode' ) ;
1068
+ expectPath ( cst , '0.children.1.paramName.value' ) . to . equal ( 'param2' ) ;
1069
+ expectPath ( cst , '0.children.1.paramDescription.value' ) . to . equal ( 'second parameter' ) ;
1070
+
1071
+ expectPath ( cst , '0.children.2.type' ) . to . equal ( 'TextNode' ) ;
1072
+ expectPath ( cst , '0.children.2.value' ) . to . equal ( '@unsupported' ) ;
1073
+ } ) ;
1074
+ }
1036
1075
} ) ;
1037
1076
} ) ;
1038
1077
0 commit comments