|
| 1 | +#include "cucumber_cpp/CucumberCpp.hpp" |
| 2 | +#include "library/engine/ExecutionContext.hpp" |
| 3 | +#include <algorithm> |
| 4 | +#include <cstdint> |
| 5 | +#include <numeric> |
| 6 | +#include <sstream> |
| 7 | +#include <string> |
| 8 | + |
| 9 | +namespace |
| 10 | +{ |
| 11 | + const std::filesystem::path currentCompileDir = std::filesystem::path{ std::source_location::current().file_name() }.parent_path(); |
| 12 | +} |
| 13 | + |
| 14 | +WHEN(R"(the string {string} is attached as {string})", (const std::string& text, const std::string& mediaType)) |
| 15 | +{ |
| 16 | + Attach(text, mediaType); |
| 17 | +} |
| 18 | + |
| 19 | +WHEN(R"(the string {string} is logged)", (const std::string& text)) |
| 20 | +{ |
| 21 | + Log(text); |
| 22 | +} |
| 23 | + |
| 24 | +WHEN(R"(text with ANSI escapes is logged)") |
| 25 | +{ |
| 26 | + Log("This displays a \x1b[31mr\x1b[0m\x1b[91ma\x1b[0m\x1b[33mi\x1b[0m\x1b[32mn\x1b[0m\x1b[34mb\x1b[0m\x1b[95mo\x1b[0m\x1b[35mw\x1b[0m"); |
| 27 | +} |
| 28 | + |
| 29 | +WHEN(R"(the following string is attached as {string}:)", (const std::string& mediaType)) |
| 30 | +{ |
| 31 | + Attach(docString->content, mediaType); |
| 32 | +} |
| 33 | + |
| 34 | +WHEN(R"(an array with {int} bytes is attached as {string})", (std::int32_t size, const std::string& mediaType)) |
| 35 | +{ |
| 36 | + std::string data(size, '\0'); |
| 37 | + std::iota(data.begin(), data.end(), 0); |
| 38 | + std::stringstream stream{ data }; |
| 39 | + Attach(stream, mediaType); |
| 40 | +} |
| 41 | + |
| 42 | +WHEN(R"(a PDF document is attached and renamed)") |
| 43 | +{ |
| 44 | + std::ifstream pdfFile{ currentCompileDir / "document.pdf", std::ios::binary }; |
| 45 | + Attach(pdfFile, cucumber_cpp::library::engine::AttachOptions{ "application/pdf", "renamed.pdf" }); |
| 46 | +} |
| 47 | + |
| 48 | +WHEN(R"(a link to {string} is attached)", (const std::string& url)) |
| 49 | +{ |
| 50 | + Link(url); |
| 51 | +} |
0 commit comments