mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-27 21:46:57 +02:00
jinja : implement sameas test (#29448)
* implement sameas test * add tests
This commit is contained in:
+22
-2
@@ -515,8 +515,28 @@ const func_builtins & global_builtins() {
|
||||
}},
|
||||
{"test_is_sameas", [](const func_args & args) -> value {
|
||||
// Check if an object points to the same memory address as another object
|
||||
(void)args;
|
||||
throw not_implemented_exception("sameas test not implemented");
|
||||
args.ensure_count(2);
|
||||
auto a = args.get_pos(0);
|
||||
auto b = args.get_pos(1);
|
||||
bool res = false;
|
||||
if (!is_val<value_undefined>(a) && !is_val<value_undefined>(b)) {
|
||||
if (is_val<value_none>(a) && is_val<value_none>(b)) {
|
||||
res = true;
|
||||
} else if (is_val<value_bool>(a) && is_val<value_bool>(b)) {
|
||||
if (a->as_bool() == b->as_bool()) {
|
||||
res = true;
|
||||
}
|
||||
} else if (is_val<value_int>(a) && is_val<value_int>(b)) {
|
||||
const int64_t x = a->as_int();
|
||||
// Allow comparison within small-int cache range
|
||||
if (x >= -5 && x <= 256 && x == b->as_int()) {
|
||||
res = true;
|
||||
}
|
||||
} else if (a == b) {
|
||||
res = true;
|
||||
}
|
||||
}
|
||||
return mk_val<value_bool>(res);
|
||||
}},
|
||||
{"test_is_escaped", [](const func_args & args) -> value {
|
||||
(void)args;
|
||||
|
||||
+25
-1
@@ -1212,12 +1212,36 @@ static void test_tests(testing & t) {
|
||||
"yes"
|
||||
);
|
||||
|
||||
test_template(t, "is sameas",
|
||||
test_template(t, "is sameas boolean",
|
||||
"{{ 'yes' if x is sameas(false) }}",
|
||||
{{"x", false}},
|
||||
"yes"
|
||||
);
|
||||
|
||||
test_template(t, "is sameas integer",
|
||||
"{{ 'yes' if x is sameas(1) }}",
|
||||
{{"x", 1}},
|
||||
"yes"
|
||||
);
|
||||
|
||||
test_template(t, "is sameas object",
|
||||
"{{ 'yes' if x is sameas(x) }}",
|
||||
{{"x", {{"y", false}}}},
|
||||
"yes"
|
||||
);
|
||||
|
||||
test_template(t, "is sameas ref object",
|
||||
"{% set y = x.y %}{{ 'yes' if x.y is sameas(y) and x.y is not sameas(x.z) }}",
|
||||
{{"x", {{"y", {{"z", 1}}}, {"z", {{"z", 1}}}}}},
|
||||
"yes"
|
||||
);
|
||||
|
||||
test_template(t, "is sameas undefined",
|
||||
"{{ 'yes' if x is sameas(x) else 'no' }}",
|
||||
json::object(),
|
||||
"no"
|
||||
);
|
||||
|
||||
test_template(t, "is boolean",
|
||||
"{{ 'yes' if x is boolean }}",
|
||||
{{"x", true}},
|
||||
|
||||
Reference in New Issue
Block a user