jinja: support none|string (#18995)
* jinja: support none|string * Update common/jinja/value.cpp Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Update tests/test-jinja.cpp Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Add as_string() --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
This commit is contained in:
parent
3802d3c78f
commit
c301172f66
|
|
@ -1005,6 +1005,7 @@ const func_builtins & value_none_t::get_builtins() const {
|
||||||
static const func_builtins builtins = {
|
static const func_builtins builtins = {
|
||||||
{"default", default_value},
|
{"default", default_value},
|
||||||
{"tojson", tojson},
|
{"tojson", tojson},
|
||||||
|
{"string", [](const func_args &) -> value { return mk_val<value_string>("None"); }}
|
||||||
};
|
};
|
||||||
return builtins;
|
return builtins;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -342,12 +342,12 @@ struct value_none_t : public value_t {
|
||||||
virtual std::string type() const override { return "None"; }
|
virtual std::string type() const override { return "None"; }
|
||||||
virtual bool is_none() const override { return true; }
|
virtual bool is_none() const override { return true; }
|
||||||
virtual bool as_bool() const override { return false; }
|
virtual bool as_bool() const override { return false; }
|
||||||
|
virtual string as_string() const override { return string("None"); }
|
||||||
virtual std::string as_repr() const override { return type(); }
|
virtual std::string as_repr() const override { return type(); }
|
||||||
virtual const func_builtins & get_builtins() const override;
|
virtual const func_builtins & get_builtins() const override;
|
||||||
};
|
};
|
||||||
using value_none = std::shared_ptr<value_none_t>;
|
using value_none = std::shared_ptr<value_none_t>;
|
||||||
|
|
||||||
|
|
||||||
struct value_undefined_t : public value_t {
|
struct value_undefined_t : public value_t {
|
||||||
std::string hint; // for debugging, to indicate where undefined came from
|
std::string hint; // for debugging, to indicate where undefined came from
|
||||||
value_undefined_t(const std::string & h = "") : hint(h) {}
|
value_undefined_t(const std::string & h = "") : hint(h) {}
|
||||||
|
|
|
||||||
|
|
@ -609,6 +609,12 @@ static void test_filters(testing & t) {
|
||||||
json::object(),
|
json::object(),
|
||||||
"hello"
|
"hello"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test_template(t, "none to string",
|
||||||
|
"{{ x|string }}",
|
||||||
|
{{"x", nullptr}},
|
||||||
|
"None"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_literals(testing & t) {
|
static void test_literals(testing & t) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue