|
|
@@ -191,6 +191,84 @@ static void test_conditionals(testing & t) {
|
|
|
json::object(),
|
|
|
"yes"
|
|
|
);
|
|
|
+
|
|
|
+ test_template(t, "is undefined falsy",
|
|
|
+ "{{ 'yes' if not y else 'no' }}",
|
|
|
+ json::object(),
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is undefined attribute falsy",
|
|
|
+ "{{ 'yes' if not y.x else 'no' }}",
|
|
|
+ {{"y", true}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is undefined key falsy",
|
|
|
+ "{{ 'yes' if not y['x'] else 'no' }}",
|
|
|
+ {{"y", {{}}}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is empty array falsy",
|
|
|
+ "{{ 'yes' if not y else 'no' }}",
|
|
|
+ {{"y", json::array()}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is empty object falsy",
|
|
|
+ "{{ 'yes' if not y else 'no' }}",
|
|
|
+ {{"y", json::object()}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is empty string falsy",
|
|
|
+ "{{ 'yes' if not y else 'no' }}",
|
|
|
+ {{"y", ""}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is 0 falsy",
|
|
|
+ "{{ 'yes' if not y else 'no' }}",
|
|
|
+ {{"y", 0}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is 0.0 falsy",
|
|
|
+ "{{ 'yes' if not y else 'no' }}",
|
|
|
+ {{"y", 0.0}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is non-empty array truthy",
|
|
|
+ "{{ 'yes' if y else 'no' }}",
|
|
|
+ {{"y", json::array({""})}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is non-empty object truthy",
|
|
|
+ "{{ 'yes' if y else 'no' }}",
|
|
|
+ {{"y", {"x", false}}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is non-empty string truthy",
|
|
|
+ "{{ 'yes' if y else 'no' }}",
|
|
|
+ {{"y", "0"}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is 1 truthy",
|
|
|
+ "{{ 'yes' if y else 'no' }}",
|
|
|
+ {{"y", 1}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
+
|
|
|
+ test_template(t, "is 1.0 truthy",
|
|
|
+ "{{ 'yes' if y else 'no' }}",
|
|
|
+ {{"y", 1.0}},
|
|
|
+ "yes"
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
static void test_loops(testing & t) {
|