From b7022291a8a613d2f1d8c652c54a21db442708dc Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 11 Dec 2023 23:18:00 +0100 Subject: [PATCH] Add unit tests for expected behaviour for DefinesStreamProxy --- .../Parsing/Impl/DefinesStreamProxyTests.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/ParserTests/Parsing/Impl/DefinesStreamProxyTests.cpp b/test/ParserTests/Parsing/Impl/DefinesStreamProxyTests.cpp index 335c8c6c..c713ceb4 100644 --- a/test/ParserTests/Parsing/Impl/DefinesStreamProxyTests.cpp +++ b/test/ParserTests/Parsing/Impl/DefinesStreamProxyTests.cpp @@ -596,4 +596,50 @@ namespace test::parsing::impl::defines_stream_proxy REQUIRE(proxy.Eof()); } + + TEST_CASE("DefinesStreamProxy: Macro definition can span multiple lines when used with backslash", "[parsing][parsingstream]") + { + const std::vector lines{ + "#define testMacro( \\", + " a, \\", + " b, \\", + " c) a + b - c", + "testMacro(1, 2, 3)", + }; + + MockParserLineStream mockStream(lines); + DefinesStreamProxy proxy(&mockStream); + + ExpectLine(&proxy, 1, ""); + ExpectLine(&proxy, 2, ""); + ExpectLine(&proxy, 3, ""); + ExpectLine(&proxy, 4, ""); + ExpectLine(&proxy, 5, "1 + 2 - 3"); + + REQUIRE(proxy.Eof()); + } + + TEST_CASE("DefinesStreamProxy: Macro usages can span multiple lines if they have args", "[parsing][parsingstream]") + { + const std::vector lines{ + "#define testMacro(a, b, c) Hello a, this is b. Lets meet at c!", + "testMacro(", + "Peter,", + "Anna,", + "the cinema", + ")", + }; + + MockParserLineStream mockStream(lines); + DefinesStreamProxy proxy(&mockStream); + + ExpectLine(&proxy, 1, ""); + ExpectLine(&proxy, 2, ""); + ExpectLine(&proxy, 3, ""); + ExpectLine(&proxy, 4, ""); + ExpectLine(&proxy, 5, ""); + ExpectLine(&proxy, 6, "Hello Peter, this is Anna. Lets meet at the cinema!"); + + REQUIRE(proxy.Eof()); + } } // namespace test::parsing::impl::defines_stream_proxy