Skip to content

Commit

Permalink
Fix not rendering uint64_t values greater than the int64_t max value (#…
Browse files Browse the repository at this point in the history
…278)

* Fix not properly rendering uint64_t values greater than the int64_t max value

* Move render check to variables subcase
  • Loading branch information
2x2anthony authored Nov 7, 2023
1 parent 67d6fea commit 0066e60
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/inja/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Renderer : public NodeVisitor {
void print_data(const std::shared_ptr<json> value) {
if (value->is_string()) {
*output_stream << value->get_ref<const json::string_t&>();
} else if (value->is_number_unsigned()) {
*output_stream << value->get<const json::number_unsigned_t>();
} else if (value->is_number_integer()) {
*output_stream << value->get<const json::number_integer_t>();
} else if (value->is_null()) {
Expand Down
2 changes: 2 additions & 0 deletions single_include/inja/inja.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,8 @@ class Renderer : public NodeVisitor {
void print_data(const std::shared_ptr<json> value) {
if (value->is_string()) {
*output_stream << value->get_ref<const json::string_t&>();
} else if (value->is_number_unsigned()) {
*output_stream << value->get<const json::number_unsigned_t>();
} else if (value->is_number_integer()) {
*output_stream << value->get<const json::number_integer_t>();
} else if (value->is_null()) {
Expand Down
2 changes: 2 additions & 0 deletions test/test-renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ TEST_CASE("types") {
data["relatives"]["brother"] = "Chris";
data["relatives"]["sister"] = "Jenny";
data["vars"] = {2, 3, 4, 0, -1, -2, -3};
data["max_value"] = 18446744073709551615ull;

SUBCASE("basic") {
CHECK(env.render("", data) == "");
Expand All @@ -38,6 +39,7 @@ TEST_CASE("types") {
CHECK(env.render("{{ \"{{ no_value }}\" }}", data) == "{{ no_value }}");
CHECK(env.render("{{ @name }}", data) == "@name");
CHECK(env.render("{{ $name }}", data) == "$name");
CHECK(env.render("{{max_value}}", data) == "18446744073709551615");

CHECK_THROWS_WITH(env.render("{{unknown}}", data), "[inja.exception.render_error] (at 1:3) variable 'unknown' not found");
}
Expand Down

0 comments on commit 0066e60

Please sign in to comment.