From 18478ed494ad6c2e86efde85cdd0f205a6eeaecb Mon Sep 17 00:00:00 2001 From: kamchatka-volcano Date: Mon, 7 Oct 2024 00:46:50 +0500 Subject: [PATCH] -added a custom name for generated raw string literal --- CMakeLists.txt | 2 +- src/textnode.cpp | 2 +- src/utils.cpp | 4 ++-- tests/test_codenode.cpp | 14 +++++++------- tests/test_procedurenode.cpp | 2 +- tests/test_sectionnode.cpp | 20 ++++++++++---------- tests/test_tagnode.cpp | 34 +++++++++++++++++----------------- tests/test_utils.cpp | 4 ++-- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d24d5..439a757 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.18) -project(hypertextcpp VERSION 1.2.0 DESCRIPTION "hypertextcpp") +project(hypertextcpp VERSION 1.2.1 DESCRIPTION "hypertextcpp") include(external/seal_lake) diff --git a/src/textnode.cpp b/src/textnode.cpp index 1b8b48f..1da8af3 100644 --- a/src/textnode.cpp +++ b/src/textnode.cpp @@ -9,7 +9,7 @@ TextNode::TextNode(std::string value) std::string TextNode::renderingCode() const { - return "out << R\"(" + content_ + ")\";"; + return "out << R\"_htcpp_str_(" + content_ + ")_htcpp_str_\";"; } std::string TextNode::content() const diff --git a/src/utils.cpp b/src/utils.cpp index cf8c271..3f16cd5 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -69,10 +69,10 @@ std::string transformRawStrings(const std::string& cppCode, const StreamReaderPo if (res == "`"){ if (!insideString) { rawStringPos = stream.position(); - result += "R\"("; + result += "R\"_htcpp_str_("; } else - result += ")\""; + result += ")_htcpp_str_\""; insideString = !insideString; } else diff --git a/tests/test_codenode.cpp b/tests/test_codenode.cpp index f22bc36..e9a5122 100644 --- a/tests/test_codenode.cpp +++ b/tests/test_codenode.cpp @@ -42,22 +42,22 @@ TEST(ExpressionNode, Basic) TEST(ExpressionNode, WithStringOutput) { test - ("$( isVisible ? \"Hello:)\" : defaultValue())", - "out << ( isVisible ? \"Hello:)\" : defaultValue());"); + ("$( isVisible ? \"Hello:)_htcpp_str_\" : defaultValue())", + "out << ( isVisible ? \"Hello:)_htcpp_str_\" : defaultValue());"); } TEST(ExpressionNode, WithRawStringOutput) { test - ("$( isVisible ? R\"(Hello:))\" : defaultValue())", - "out << ( isVisible ? R\"(Hello:))\" : defaultValue());"); + ("$( isVisible ? R\"_htcpp_str_(Hello:))_htcpp_str_\" : defaultValue())", + "out << ( isVisible ? R\"_htcpp_str_(Hello:))_htcpp_str_\" : defaultValue());"); } TEST(ExpressionNode, WithCustomRawStringOutput) { test ("$( isVisible ? `Hello:)` : defaultValue())", - "out << ( isVisible ? R\"(Hello:))\" : defaultValue());"); + "out << ( isVisible ? R\"_htcpp_str_(Hello:))_htcpp_str_\" : defaultValue());"); } TEST(ExpressionNode, WithCharOutput) @@ -115,7 +115,7 @@ TEST(StatementNode, BasicWithString) { test ("${ auto a = 0; {auto str = `Hello world's{}`;} }", - " auto a = 0; {auto str = R\"(Hello world's{})\";} "); + " auto a = 0; {auto str = R\"_htcpp_str_(Hello world's{})_htcpp_str_\";} "); } TEST(GlobalStatementNode, Basic) @@ -129,7 +129,7 @@ TEST(GlobalStatementNode, BasicWithString) { test ("#{ auto a = 0; {auto str = `Hello {}`;} }", - " auto a = 0; {auto str = R\"(Hello {})\";} "); + " auto a = 0; {auto str = R\"_htcpp_str_(Hello {})_htcpp_str_\";} "); } TEST(InvalidExpressionNode, Unclosed) diff --git a/tests/test_procedurenode.cpp b/tests/test_procedurenode.cpp index 92ae66f..4e870af 100644 --- a/tests/test_procedurenode.cpp +++ b/tests/test_procedurenode.cpp @@ -36,7 +36,7 @@ TEST(ProcedureNode, Basic) { test("#hello_world(){

Hello World!

}", "hello_world", - "out << R\"(

Hello World!

)\";"); + "out << R\"_htcpp_str_(

Hello World!

)_htcpp_str_\";"); } diff --git a/tests/test_sectionnode.cpp b/tests/test_sectionnode.cpp index 144579b..17634d2 100644 --- a/tests/test_sectionnode.cpp +++ b/tests/test_sectionnode.cpp @@ -38,52 +38,52 @@ void testError(const std::string& input, const std::string& expectedErrorMsg) TEST(SectionNode, Basic) { test("[[ Hello world! ]]", - "out << R\"( Hello world! )\";"); + "out << R\"_htcpp_str_( Hello world! )_htcpp_str_\";"); } TEST(SectionNode, BasicWithConditionalExtension) { test("[[?(isVisible) Hello world! ]]", - "if (isVisible){ out << R\"( Hello world! )\"; } "); + "if (isVisible){ out << R\"_htcpp_str_( Hello world! )_htcpp_str_\"; } "); } TEST(SectionNode, BasicWithLoopExtension) { test("[[@(auto i = 0; i < 5; ++i) Hello world! ]]", - "for (auto i = 0; i < 5; ++i){ out << R\"( Hello world! )\"; } "); + "for (auto i = 0; i < 5; ++i){ out << R\"_htcpp_str_( Hello world! )_htcpp_str_\"; } "); } TEST(SectionNode, BasicWithConditionalExtensionOnClosingBraces) { test("[[ Hello world! ]]?(isVisible)", - "if (isVisible){ out << R\"( Hello world! )\"; } "); + "if (isVisible){ out << R\"_htcpp_str_( Hello world! )_htcpp_str_\"; } "); } TEST(SectionNode, BasicWithLoopExtensionOnClosingBraces) { test("[[ Hello world! ]]@(auto i = 0; i < 5; ++i)", - "for (auto i = 0; i < 5; ++i){ out << R\"( Hello world! )\"; } "); + "for (auto i = 0; i < 5; ++i){ out << R\"_htcpp_str_( Hello world! )_htcpp_str_\"; } "); } TEST(SectionNode, Nested) { test("[[ Hello

world

[[!]] ]]", - "out << R\"( Hello

world

! )\";"); + "out << R\"_htcpp_str_( Hello

world

! )_htcpp_str_\";"); } TEST(SectionNode, NestedWithConditionalExtension) { test("[[ Hello

?(isVisible)world

[[!]]?(isVisible) ]]?(isVisible)", - "if (isVisible){ out << R\"( Hello )\";if (isVisible){ out << R\"(

world

)\"; } out << R\"( )\";if " - "(isVisible){ out << R\"(!)\"; } out << R\"( )\"; } "); + "if (isVisible){ out << R\"_htcpp_str_( Hello )_htcpp_str_\";if (isVisible){ out << R\"_htcpp_str_(

world

)_htcpp_str_\"; } out << R\"_htcpp_str_( )_htcpp_str_\";if " + "(isVisible){ out << R\"_htcpp_str_(!)_htcpp_str_\"; } out << R\"_htcpp_str_( )_htcpp_str_\"; } "); } TEST(SectionNode, NestedWithLoopExtension) { test("[[ Hello

@(auto i = 0; i < 5; ++i)world

[[!]]@(auto i = 0; i < 3; ++i) ]]@(auto i = 0; i < 5; ++i)", - "for (auto i = 0; i < 5; ++i){ out << R\"( Hello )\";for (auto i = 0; i < 5; ++i){ out << " - "R\"(

world

)\"; } out << R\"( )\";for (auto i = 0; i < 3; ++i){ out << R\"(!)\"; } out << R\"( )\"; } "); + "for (auto i = 0; i < 5; ++i){ out << R\"_htcpp_str_( Hello )_htcpp_str_\";for (auto i = 0; i < 5; ++i){ out << " + "R\"_htcpp_str_(

world

)_htcpp_str_\"; } out << R\"_htcpp_str_( )_htcpp_str_\";for (auto i = 0; i < 3; ++i){ out << R\"_htcpp_str_(!)_htcpp_str_\"; } out << R\"_htcpp_str_( )_htcpp_str_\"; } "); } diff --git a/tests/test_tagnode.cpp b/tests/test_tagnode.cpp index f9be9e7..217a0c6 100644 --- a/tests/test_tagnode.cpp +++ b/tests/test_tagnode.cpp @@ -41,89 +41,89 @@ void testError(const std::string& input, const std::string& expectedErrorMsg) TEST(TagNode, BasicNoAttributes) { test("

Hello world!

", - "out << R\"(

Hello world!

)\";"); + "out << R\"_htcpp_str_(

Hello world!

)_htcpp_str_\";"); } TEST(TagNode, Basic) { test("
Hello world!
", - "out << R\"(
Hello world!
)\";"); + "out << R\"_htcpp_str_(
Hello world!
)_htcpp_str_\";"); } TEST(TagNode, BasicWithConditionalExtension) { test("
?(isVisible) Hello world!
", - "if (isVisible){ out << R\"(
Hello world!
)\"; } "); + "if (isVisible){ out << R\"_htcpp_str_(
Hello world!
)_htcpp_str_\"; } "); } TEST(TagNode, BasicWithConditionalExtensionOnClosingTag) { test("
Hello world!
?(isVisible)", - "if (isVisible){ out << R\"(
Hello world!
)\"; } "); + "if (isVisible){ out << R\"_htcpp_str_(
Hello world!
)_htcpp_str_\"; } "); } TEST(TagNode, BasicWithLoopExtension) { test("
@(auto i = 0; i < 5; ++i) Hello world!
", - "for (auto i = 0; i < 5; ++i){ out << R\"(
Hello world!
)\"; } "); + "for (auto i = 0; i < 5; ++i){ out << R\"_htcpp_str_(
Hello world!
)_htcpp_str_\"; } "); } TEST(TagNode, BasicWithLoopExtensionOnClosingTag) { test("
Hello world!
@(auto i = 0; i < 5; ++i)", - "for (auto i = 0; i < 5; ++i){ out << R\"(
Hello world!
)\"; } "); + "for (auto i = 0; i < 5; ++i){ out << R\"_htcpp_str_(
Hello world!
)_htcpp_str_\"; } "); } TEST(TagNode, WithOtherNodes) { test("", - "out << R\"()\";"); + "out << R\"_htcpp_str_()_htcpp_str_\";"); } TEST(TagNode, NestedWithAttributes) { test("

Hello world!

", - "out << R\"(

Hello world!

)\";"); + "out << R\"_htcpp_str_(

Hello world!

)_htcpp_str_\";"); } TEST(TagNode, NestedWithAttributesWithConditionalExtension) { test("
?(isVisible)

?(isVisible)Hello world!

", - "if (isVisible){ out << R\"(
)\";if (isVisible){ out << R\"(

Hello world!

)\"; } out << " - "R\"(
)\"; } "); + "if (isVisible){ out << R\"_htcpp_str_(
)_htcpp_str_\";if (isVisible){ out << R\"_htcpp_str_(

Hello world!

)_htcpp_str_\"; } out << " + "R\"_htcpp_str_(
)_htcpp_str_\"; } "); } TEST(TagNode, NestedWithAttributesWithLoopExtension) { test("
@(auto i = 0; i < 5; ++i)

@(auto i = 0; i < 5; ++i)Hello world!

", - "for (auto i = 0; i < 5; ++i){ out << R\"(
)\";for (auto i = 0; i < 5; ++i){ out << " - "R\"(

Hello world!

)\"; } out << R\"(
)\"; } "); + "for (auto i = 0; i < 5; ++i){ out << R\"_htcpp_str_(
)_htcpp_str_\";for (auto i = 0; i < 5; ++i){ out << " + "R\"_htcpp_str_(

Hello world!

)_htcpp_str_\"; } out << R\"_htcpp_str_(
)_htcpp_str_\"; } "); } TEST(TagNode, EmptyElementNoAttributes) { test("
", - "out << R\"(
)\";"); + "out << R\"_htcpp_str_(
)_htcpp_str_\";"); } TEST(TagNode, EmptyElement) { test("", - "out << R\"()\";"); + "out << R\"_htcpp_str_()_htcpp_str_\";"); } TEST(TagNode, EmptyElementWithConditionalExtension) { test("?(isVisible)", - "if (isVisible){ out << R\"()\"; } "); + "if (isVisible){ out << R\"_htcpp_str_()_htcpp_str_\"; } "); } TEST(TagNode, EmptyElementWithLoopExtension) { test("@(auto i = 0; i < 5; ++i)", - "for (auto i = 0; i < 5; ++i){ out << R\"()\"; } "); + "for (auto i = 0; i < 5; ++i){ out << R\"_htcpp_str_()_htcpp_str_\"; } "); } TEST(InvalidTagNode, UnclosedTag) diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index c67e1fd..91a8aca 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -8,12 +8,12 @@ TEST(Utils, TransformRawString) { auto code = "auto x = `Hello World`;"; EXPECT_EQ(htcpp::utils::transformRawStrings(code, {1, 1}), - "auto x = R\"(Hello World)\";"); + "auto x = R\"_htcpp_str_(Hello World)_htcpp_str_\";"); } { auto code = "auto x = ``;"; EXPECT_EQ(htcpp::utils::transformRawStrings(code, {1, 1}), - "auto x = R\"()\";"); + "auto x = R\"_htcpp_str_()_htcpp_str_\";"); } }