From 934acf135d2ef22247464c0b5b4d81af47ef70a1 Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Sun, 30 Mar 2025 23:27:26 +0100 Subject: [PATCH 1/2] Add upper filter --- include/minja/minja.hpp | 20 ++++++++++++-------- tests/test-syntax.cpp | 5 ++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/minja/minja.hpp b/include/minja/minja.hpp index 12ca8af..67222fe 100644 --- a/include/minja/minja.hpp +++ b/include/minja/minja.hpp @@ -2607,14 +2607,18 @@ inline std::shared_ptr Context::builtins() { auto & text = args.at("text"); return text.is_null() ? text : Value(strip(text.get())); })); - globals.set("lower", simple_function("lower", { "text" }, [](const std::shared_ptr &, Value & args) { - auto text = args.at("text"); - if (text.is_null()) return text; - std::string res; - auto str = text.get(); - std::transform(str.begin(), str.end(), std::back_inserter(res), ::tolower); - return Value(res); - })); + auto char_transform_function = [](const std::string & name, const std::function & fn) { + return simple_function(name, { "text" }, [=](const std::shared_ptr &, Value & args) { + auto text = args.at("text"); + if (text.is_null()) return text; + std::string res; + auto str = text.get(); + std::transform(str.begin(), str.end(), std::back_inserter(res), fn); + return Value(res); + }); + }; + globals.set("lower", char_transform_function("lower", ::tolower)); + globals.set("upper", char_transform_function("upper", ::toupper)); globals.set("default", Value::callable([=](const std::shared_ptr &, ArgumentsValue & args) { args.expectArgs("default", {2, 3}, {0, 1}); auto & value = args.args[0]; diff --git a/tests/test-syntax.cpp b/tests/test-syntax.cpp index fdc7ca5..5b894d3 100644 --- a/tests/test-syntax.cpp +++ b/tests/test-syntax.cpp @@ -88,7 +88,7 @@ TEST(SyntaxTest, SimpleCases) { EXPECT_EQ( "ok", render("{# Hey\nHo #}{#- Multiline...\nComments! -#}{{ 'ok' }}{# yo #}", {}, {})); - + EXPECT_EQ( " b", render(R"( {% set _ = 1 %} {% set _ = 2 %}b)", {}, lstrip_trim_blocks)); @@ -130,6 +130,9 @@ TEST(SyntaxTest, SimpleCases) { EXPECT_EQ( "abc", render("{{ 'AbC' | lower }}", {}, {})); + EXPECT_EQ( + "ME", + render("{{ 'me' | upper }}", {}, {})); EXPECT_EQ( "the default1", render("{{ foo | default('the default') }}{{ 1 | default('nope') }}", {}, {})); From 580203e43edd83930cc4120df936eb2e6526c8af Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Sun, 30 Mar 2025 23:27:37 +0100 Subject: [PATCH 2/2] Test inclusionAI/Ling-Coder-lite template --- tests/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8475fd4..d7e6fa5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -137,6 +137,7 @@ set(MODEL_IDS huihui-ai/Qwen2.5-14B-Instruct-1M-abliterated ibm-granite/granite-3.1-8b-instruct Ihor/Text2Graph-R1-Qwen2.5-0.5b + inclusionAI/Ling-Coder-lite indischepartij/MiniCPM-3B-OpenHermes-2.5-v2 Infinigence/Megrez-3B-Instruct inflatebot/MN-12B-Mag-Mell-R1