mirror of
https://github.com/orange-cpp/omath.git
synced 2026-06-10 09:14:34 +00:00
added compile time pattern parsing
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
#include "omath/utility/pe_pattern_scan.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include <omath/utility/pattern_scan.hpp>
|
||||
#include <source_location>
|
||||
#include <print>
|
||||
#include <source_location>
|
||||
TEST(unit_test_pattern_scan, read_test)
|
||||
{
|
||||
const auto result = omath::PatternScanner::parse_pattern("FF ? ?? E9");
|
||||
@@ -50,4 +50,38 @@ TEST(unit_test_pattern_scan, corner_case_4)
|
||||
{
|
||||
const auto result = omath::PatternScanner::parse_pattern("X ? ?? E9 ");
|
||||
EXPECT_FALSE(result.has_value());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(unit_test_pattern_scan, consteval_read_test)
|
||||
{
|
||||
constexpr auto result = omath::PatternScanner::parse_pattern<"FF ? ?? E9">();
|
||||
|
||||
static_assert(result.size() == 4);
|
||||
static_assert(result[0] == static_cast<std::byte>(0xFF));
|
||||
static_assert(result[1] == std::nullopt);
|
||||
static_assert(result[2] == std::nullopt);
|
||||
static_assert(result[3] == static_cast<std::byte>(0xE9));
|
||||
|
||||
EXPECT_EQ(result[0], static_cast<std::byte>(0xFF));
|
||||
EXPECT_EQ(result[1], std::nullopt);
|
||||
EXPECT_EQ(result[2], std::nullopt);
|
||||
EXPECT_EQ(result[3], static_cast<std::byte>(0xE9));
|
||||
}
|
||||
|
||||
TEST(unit_test_pattern_scan, consteval_spacing_and_case)
|
||||
{
|
||||
constexpr auto result = omath::PatternScanner::parse_pattern<" \tde\nAD\r?? ? ef ">();
|
||||
|
||||
static_assert(result.size() == 5);
|
||||
static_assert(result[0] == static_cast<std::byte>(0xDE));
|
||||
static_assert(result[1] == static_cast<std::byte>(0xAD));
|
||||
static_assert(result[2] == std::nullopt);
|
||||
static_assert(result[3] == std::nullopt);
|
||||
static_assert(result[4] == static_cast<std::byte>(0xEF));
|
||||
|
||||
EXPECT_EQ(result[0], static_cast<std::byte>(0xDE));
|
||||
EXPECT_EQ(result[1], static_cast<std::byte>(0xAD));
|
||||
EXPECT_EQ(result[2], std::nullopt);
|
||||
EXPECT_EQ(result[3], std::nullopt);
|
||||
EXPECT_EQ(result[4], static_cast<std::byte>(0xEF));
|
||||
}
|
||||
|
||||
@@ -14,6 +14,16 @@ TEST(unit_test_pattern_scan_extra, IteratorScanFound)
|
||||
EXPECT_EQ(std::distance(buf.begin(), it), 0);
|
||||
}
|
||||
|
||||
TEST(unit_test_pattern_scan_extra, ConstevalIteratorScan)
|
||||
{
|
||||
std::vector<std::byte> buf = {static_cast<std::byte>(0x00), static_cast<std::byte>(0xDE),
|
||||
static_cast<std::byte>(0xAD), static_cast<std::byte>(0xBE),
|
||||
static_cast<std::byte>(0xEF), static_cast<std::byte>(0x11)};
|
||||
const auto it = PatternScanner::scan_for_pattern<"DE ?? BE EF">(buf.begin(), buf.end());
|
||||
EXPECT_NE(it, buf.end());
|
||||
EXPECT_EQ(std::distance(buf.begin(), it), 1);
|
||||
}
|
||||
|
||||
TEST(unit_test_pattern_scan_extra, IteratorScanNotFound)
|
||||
{
|
||||
std::vector<std::byte> buf = {static_cast<std::byte>(0x00), static_cast<std::byte>(0x11),
|
||||
|
||||
Reference in New Issue
Block a user