From c5db1cea8f48504dc42d2010636adae141758455 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 13 Jun 2020 11:45:45 -0400 Subject: [PATCH] Add a test case for the math helper and add else blocks to the select test. --- js/test_cases/helpers_math/README.md | 4 ++ js/test_cases/helpers_math/input1.json | 5 +++ js/test_cases/helpers_math/main.dust | 58 ++++++++++++++++++++++++++ js/test_cases/helpers_select/README.md | 4 ++ js/test_cases/helpers_select/main.dust | 14 +++++++ 5 files changed, 85 insertions(+) create mode 100644 js/test_cases/helpers_math/README.md create mode 100644 js/test_cases/helpers_math/input1.json create mode 100644 js/test_cases/helpers_math/main.dust diff --git a/js/test_cases/helpers_math/README.md b/js/test_cases/helpers_math/README.md new file mode 100644 index 0000000..9984083 --- /dev/null +++ b/js/test_cases/helpers_math/README.md @@ -0,0 +1,4 @@ +Early termination +----------------- + +If the math helper has a body then it stops rendering conditionals after the first conditional that returns true. Rendering an else block does not cause early termination, but else blocks are rendered. diff --git a/js/test_cases/helpers_math/input1.json b/js/test_cases/helpers_math/input1.json new file mode 100644 index 0000000..77959bc --- /dev/null +++ b/js/test_cases/helpers_math/input1.json @@ -0,0 +1,5 @@ +{ + "number_7": 7, + "string_7": "7", + "string_cat": "cat" +} diff --git a/js/test_cases/helpers_math/main.dust b/js/test_cases/helpers_math/main.dust new file mode 100644 index 0000000..5108995 --- /dev/null +++ b/js/test_cases/helpers_math/main.dust @@ -0,0 +1,58 @@ +Bodiless math{~n} +============={~n} +{@math key="7" method="add" operand="4" /}{~n} +{@math key=number_7 method="add" operand="4" /}{~n} +{@math key=string_7 method="add" operand="4" /}{~n} +{@math key=string_cat method="add" operand="4" /}{~n} + +Math with body: dot reference{~n} +============================={~n} +{@math key="7" method="add" operand="4"} + {.}{~n} +{/math} + +Math with body: eq literal{~n} +=========================={~n} +{@math key="7" method="add" operand="4"} + {@eq value=11}math result is 11{:else}math result is not 11{/eq}{~n} +{/math} + +Math with body: eq string{~n} +========================={~n} +{@math key="7" method="add" operand="4"} + {@eq value="11"}math result is "11"{:else}math result is not "11"{/eq}{~n} +{/math} + +Math with body: eq else block{~n} +============================={~n} +{@math key="7" method="add" operand="4"} + {@eq value=12}math result is 12{:else}math result is not 12{/eq}{~n} +{/math} + +Math with body: standalone eq{~n} +============================={~n} +{@math key="7" method="add" operand="4"} + {@eq key=12 value=12}12 is 12{:else}12 is not 12{/eq}{~n} +{/math} + +Math with body: standalone else block{~n} +====================================={~n} +{@math key="7" method="add" operand="4"} + {@eq key=11 value=12}11 is 12{:else}11 is not 12{/eq}{~n} +{/math} + +Math with body: early termination{~n} +============================={~n} +{@math key="7" method="add" operand="4"} + {@eq value=11}math result is 11{:else}math result is not 11{/eq}{~n} + {@eq value=11}math result is 11{:else}math result is not 11{/eq}{~n} +{/math} + +Math with body: early termination else block{~n} +============================================{~n} +{@math key="7" method="add" operand="4"} + {@eq value=12}math result is 12{:else}math result is not 12{/eq}{~n} + {@eq value=11}math result is 11{:else}math result is not 11{/eq}{~n} + {@eq value=12}math result is 12{:else}math result is not 12{/eq}{~n} +{/math} + diff --git a/js/test_cases/helpers_select/README.md b/js/test_cases/helpers_select/README.md index e127586..ba85db9 100644 --- a/js/test_cases/helpers_select/README.md +++ b/js/test_cases/helpers_select/README.md @@ -7,6 +7,10 @@ Early termination Comparisons are done in-order and only the first matching comparison (eq/ne/gt/gte/lt/lte) is evaluated. All other non-comparison elements inside the select tag are still rendered normally. +Matching is terminated even if the first matching comparison has its own key. + +Else blocks are rendered until the first matching comparison but else blocks after that are not rendered. + Default vs none --------------- Default was deprecated as of dust 1.6.0 and no longer does anything. It was deprecated because it was essentially the same as none except that there could only be one per select block and it had to be placed after all the other conditions to make sure they were all false. None is more flexible. diff --git a/js/test_cases/helpers_select/main.dust b/js/test_cases/helpers_select/main.dust index 30a8971..6c2d49f 100644 --- a/js/test_cases/helpers_select/main.dust +++ b/js/test_cases/helpers_select/main.dust @@ -101,6 +101,20 @@ Early termination stand-alone comparison{~n} {/pet_names} {/select}{~n} +Early termination else block{~n} +============================{~n} +{@select key=pet} + {@eq value="dog"}Lets name your pet rover{~n}{:else}Lets not name your pet rover{~n}{/eq} + {@eq value="cat"}Lets name your pet fluffy{~n}{:else}Lets not name your pet fluffy{~n}{/eq} + {@eq value="cat"}Lets name your pet whiskers{~n}{:else}Lets not name your pet whiskers{~n}{/eq} + {@eq value="lizard"}Lets name your pet dave{~n}{:else}Lets not name your pet dave{~n}{/eq} + {@any}{person} has a pet!{~n}{/any} + text not inside a comparison{~n} + {#pet_names} + If your pet was a {type} we'd name it {pet_name}{~n} + {/pet_names} +{/select}{~n} + @any alone{~n} =========={~n} {@any}{person} has a pet!{~n}{/any}