mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Ensure not closing macro definition parameters throws an error
This commit is contained in:
parent
c1c5378b08
commit
b1d4176b6e
@ -148,6 +148,9 @@ void DefinesStreamProxy::ContinueDefine(const ParserLine& line, const unsigned c
|
||||
const auto lineEndEscapePos = GetLineEndEscapePos(line);
|
||||
if (lineEndEscapePos < 0)
|
||||
{
|
||||
if (m_parameter_state != ParameterState::NOT_IN_PARAMETERS)
|
||||
throw ParsingException(CreatePos(line, currentPos), "Unclosed macro parameters");
|
||||
|
||||
if (currentPos <= 0)
|
||||
m_current_define_value << line.m_line;
|
||||
else
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
class ParsingException final : std::exception
|
||||
class ParsingException final : public std::exception
|
||||
{
|
||||
TokenPos m_pos;
|
||||
std::string m_message;
|
||||
|
@ -1,8 +1,14 @@
|
||||
#include "Parsing/Impl/DefinesStreamProxy.h"
|
||||
#include "Parsing/Mock/MockParserLineStream.h"
|
||||
#include "Parsing/ParsingException.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
#include <catch2/matchers/catch_matchers_exception.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
|
||||
using namespace Catch::Matchers;
|
||||
|
||||
namespace test::parsing::impl::defines_stream_proxy
|
||||
{
|
||||
@ -13,6 +19,12 @@ namespace test::parsing::impl::defines_stream_proxy
|
||||
REQUIRE(line.m_line == value);
|
||||
}
|
||||
|
||||
void ExpectErrorInLine(IParserLineStream* stream, const int lineNumber, const int columnNumber)
|
||||
{
|
||||
REQUIRE_THROWS_MATCHES(
|
||||
stream->NextLine(), ParsingException, MessageMatches(ContainsSubstring("L" + std::to_string(lineNumber) + ":" + std::to_string(columnNumber))));
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Ensure simple define and positive ifdef is working", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
@ -725,6 +737,22 @@ namespace test::parsing::impl::defines_stream_proxy
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Macro definition that has unclosed parameters throws an error", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
"#define testMacro(",
|
||||
" a,",
|
||||
" b,",
|
||||
" c) a + b - c",
|
||||
"testMacro(1, 2, 3)",
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
DefinesStreamProxy proxy(&mockStream);
|
||||
|
||||
ExpectErrorInLine(&proxy, 1, 19);
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Macro usages can span multiple lines if they have args", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
|
Loading…
x
Reference in New Issue
Block a user