aboutsummaryrefslogtreecommitdiff
path: root/deps/inja/test/test-units.cpp
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-04-27 11:23:17 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-04-27 11:23:17 +0200
commit36cc18d2b6d0eefd00a25a02bb4a407e700b5f9f (patch)
tree575b98e789934a2153a9063d1b91afb42dc27ef4 /deps/inja/test/test-units.cpp
parentdd086a1608b0e3cd5565174225b8197792bad4b9 (diff)
parent514cb71a6a3e116c229c5dc874369f8632530dc7 (diff)
Merge commit '514cb71a6a3e116c229c5dc874369f8632530dc7' as 'deps/inja'
Diffstat (limited to 'deps/inja/test/test-units.cpp')
-rw-r--r--deps/inja/test/test-units.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/deps/inja/test/test-units.cpp b/deps/inja/test/test-units.cpp
new file mode 100644
index 0000000..95862f2
--- /dev/null
+++ b/deps/inja/test/test-units.cpp
@@ -0,0 +1,51 @@
+// Copyright (c) 2020 Pantor. All rights reserved.
+
+TEST_CASE("source location") {
+ std::string content = R""""(Lorem Ipsum
+ Dolor
+Amid
+Set ().$
+Try this
+
+)"""";
+
+ CHECK(inja::get_source_location(content, 0).line == 1);
+ CHECK(inja::get_source_location(content, 0).column == 1);
+
+ CHECK(inja::get_source_location(content, 10).line == 1);
+ CHECK(inja::get_source_location(content, 10).column == 11);
+
+ CHECK(inja::get_source_location(content, 25).line == 4);
+ CHECK(inja::get_source_location(content, 25).column == 1);
+
+ CHECK(inja::get_source_location(content, 29).line == 4);
+ CHECK(inja::get_source_location(content, 29).column == 5);
+
+ CHECK(inja::get_source_location(content, 43).line == 6);
+ CHECK(inja::get_source_location(content, 43).column == 1);
+}
+
+TEST_CASE("copy environment") {
+ inja::Environment env;
+ env.add_callback("double", 1, [](inja::Arguments &args) {
+ int number = args.at(0)->get<int>();
+ return 2 * number;
+ });
+
+ inja::Template t1 = env.parse("{{ double(2) }}");
+ env.include_template("tpl", t1);
+ std::string test_tpl = "{% include \"tpl\" %}";
+
+ REQUIRE(env.render(test_tpl, json()) == "4");
+
+ inja::Environment copy(env);
+ CHECK(copy.render(test_tpl, json()) == "4");
+
+ // overwrite template in source env
+ inja::Template t2 = env.parse("{{ double(4) }}");
+ env.include_template("tpl", t2);
+ REQUIRE(env.render(test_tpl, json()) == "8");
+
+ // template is unchanged in copy
+ CHECK(copy.render(test_tpl, json()) == "4");
+}