2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-11 06:32:27 +00:00

Add raw string and user defined literals to c++11 tests

This commit is contained in:
Jay Berkenbilt 2022-01-01 11:28:24 -05:00
parent c60b4ea55a
commit 7d48b446b3
2 changed files with 26 additions and 0 deletions

View File

@ -474,6 +474,7 @@
"xpdf", "xpdf",
"xpost", "xpost",
"xsltproc", "xsltproc",
"yabcy",
"yscale", "yscale",
"yuiop", "yuiop",
"zabcdefghi", "zabcdefghi",

View File

@ -1,6 +1,7 @@
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <cstdlib>
#include <functional> #include <functional>
#include <type_traits> #include <type_traits>
#include <cstdint> #include <cstdint>
@ -361,6 +362,29 @@ void do_regex()
assert((*m3)[2].matched); assert((*m3)[2].matched);
} }
static long operator ""_x(char const* v)
{
return strtol(v, nullptr, 16);
}
static std::string operator ""_y(char const* v, size_t len)
{
return "y" + std::string(v, len) + "y";
}
void do_user_defined_literals()
{
assert(10_x == 16); // operator""_x("10")
assert("abc"_y == "yabcy"); // operator""_y("abc", 3)
// Raw literals. Optional matching label before and after ()
// allows embedding something that looks like the default end
// delimiter in the string.
assert(R"(abc)"_y == "yabcy");
// This construct does not work in MSVC as of version 2019.
// assert(R"x(a)"bc)x"_y == "ya)\"bcy");
}
int main() int main()
{ {
do_functional(); do_functional();
@ -370,6 +394,7 @@ int main()
do_default_deleted(); do_default_deleted();
do_smart_pointers(); do_smart_pointers();
do_regex(); do_regex();
do_user_defined_literals();
std::cout << "assertions passed\n"; std::cout << "assertions passed\n";
return 0; return 0;
} }