yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
common.cc
Go to the documentation of this file.
2
3#include "absl/strings/ascii.h"
4#include "absl/strings/str_cat.h"
5#include "absl/strings/str_format.h"
6#include "absl/strings/str_replace.h"
7
8namespace yaze {
9namespace cli {
10namespace agent {
11
12std::string HarnessAddress(const std::string& host, int port) {
13 return absl::StrFormat("%s:%d", host, port);
14}
15
16std::string JsonEscape(absl::string_view value) {
17 std::string out;
18 out.reserve(value.size() + 8);
19 for (unsigned char c : value) {
20 switch (c) {
21 case '\\':
22 out += "\\\\";
23 break;
24 case '"':
25 out += "\\\"";
26 break;
27 case '\b':
28 out += "\\b";
29 break;
30 case '\f':
31 out += "\\f";
32 break;
33 case '\n':
34 out += "\\n";
35 break;
36 case '\r':
37 out += "\\r";
38 break;
39 case '\t':
40 out += "\\t";
41 break;
42 default:
43 if (c < 0x20) {
44 absl::StrAppend(&out, absl::StrFormat("\\u%04X", static_cast<int>(c)));
45 } else {
46 out.push_back(static_cast<char>(c));
47 }
48 }
49 }
50 return out;
51}
52
53std::string YamlQuote(absl::string_view value) {
54 std::string escaped(value);
55 absl::StrReplaceAll({{"\\", "\\\\"}, {"\"", "\\\""}}, &escaped);
56 return absl::StrCat("\"", escaped, "\"");
57}
58
59std::string FormatOptionalTime(const std::optional<absl::Time>& time) {
60 if (!time.has_value()) {
61 return "n/a";
62 }
63 return absl::FormatTime("%Y-%m-%dT%H:%M:%SZ", *time, absl::UTCTimeZone());
64}
65
66std::string OptionalTimeToIso(const std::optional<absl::Time>& time) {
67 if (!time.has_value()) {
68 return "";
69 }
70 return absl::FormatTime("%Y-%m-%dT%H:%M:%SZ", *time, absl::UTCTimeZone());
71}
72
73std::string OptionalTimeToJson(const std::optional<absl::Time>& time) {
74 std::string iso = OptionalTimeToIso(time);
75 if (iso.empty()) {
76 return "null";
77 }
78 return absl::StrCat("\"", JsonEscape(iso), "\"");
79}
80
81std::string OptionalTimeToYaml(const std::optional<absl::Time>& time) {
82 std::string iso = OptionalTimeToIso(time);
83 if (iso.empty()) {
84 return "null";
85 }
86 return iso;
87}
88
90 switch (status) {
92 return "QUEUED";
94 return "RUNNING";
96 return "PASSED";
98 return "FAILED";
100 return "TIMEOUT";
102 default:
103 return "UNKNOWN";
104 }
105}
106
108 switch (status) {
111 return false;
116 default:
117 return true;
118 }
119}
120
121std::optional<TestRunStatus> ParseStatusFilter(absl::string_view value) {
122 std::string lower = std::string(absl::AsciiStrToLower(value));
123 if (lower == "queued") return TestRunStatus::kQueued;
124 if (lower == "running") return TestRunStatus::kRunning;
125 if (lower == "passed") return TestRunStatus::kPassed;
126 if (lower == "failed") return TestRunStatus::kFailed;
127 if (lower == "timeout") return TestRunStatus::kTimeout;
128 if (lower == "unknown") return TestRunStatus::kUnknown;
129 return std::nullopt;
130}
131
132std::optional<WidgetTypeFilter> ParseWidgetTypeFilter(absl::string_view value) {
133 std::string lower = std::string(absl::AsciiStrToLower(value));
134 if (lower.empty() || lower == "unspecified" || lower == "any") {
136 }
137 if (lower == "all") {
139 }
140 if (lower == "button" || lower == "buttons") {
142 }
143 if (lower == "input" || lower == "textbox" || lower == "field") {
145 }
146 if (lower == "menu" || lower == "menuitem" || lower == "menu-item") {
148 }
149 if (lower == "tab" || lower == "tabs") {
151 }
152 if (lower == "checkbox" || lower == "toggle") {
154 }
155 if (lower == "slider" || lower == "drag" || lower == "sliderfloat") {
157 }
158 if (lower == "canvas" || lower == "viewport") {
160 }
161 if (lower == "selectable" || lower == "list-item") {
163 }
164 if (lower == "other") {
166 }
167 return std::nullopt;
168}
169
170} // namespace agent
171} // namespace cli
172} // namespace yaze
bool IsTerminalStatus(TestRunStatus status)
Definition common.cc:107
std::string FormatOptionalTime(const std::optional< absl::Time > &time)
Definition common.cc:59
std::string YamlQuote(absl::string_view value)
Definition common.cc:53
std::string OptionalTimeToYaml(const std::optional< absl::Time > &time)
Definition common.cc:81
std::string HarnessAddress(const std::string &host, int port)
Definition common.cc:12
const char * TestRunStatusToString(TestRunStatus status)
Definition common.cc:89
std::string JsonEscape(absl::string_view value)
Definition common.cc:16
std::string OptionalTimeToJson(const std::optional< absl::Time > &time)
Definition common.cc:73
std::string OptionalTimeToIso(const std::optional< absl::Time > &time)
Definition common.cc:66
std::optional< TestRunStatus > ParseStatusFilter(absl::string_view value)
Definition common.cc:121
std::optional< WidgetTypeFilter > ParseWidgetTypeFilter(absl::string_view value)
Definition common.cc:132
TestRunStatus
Execution status codes returned by the harness.
Main namespace for the application.