Skip to content

Commit 028dcc5

Browse files
committed
add attachments compatibility test
1 parent 07a77d7 commit 028dcc5

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cmake.useCMakePresets": "always",
33
"cucumberautocomplete.steps": [
4+
"compatibility/*/*.cpp",
45
"cucumber_cpp/example/steps/*.cpp",
56
"cucumber_cpp/acceptance_test/steps/*.cpp"
67
],
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

cucumber_cpp/library/engine/ExecutionContext.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace cucumber_cpp::library::engine
3030
void Attach(std::string data, OptionsOrMediaType mediaType);
3131
void Attach(std::istream& data, OptionsOrMediaType mediaType);
3232
void Log(std::string text);
33-
void Link(std::string url, std::optional<std::string> title);
33+
void Link(std::string url, std::optional<std::string> title = std::nullopt);
3434

3535
Context& context;
3636

0 commit comments

Comments
 (0)