Debian Codegraph @

tests/src/cli2/test_PositionalArgumentTranslator.cpp

raw
1 #include <pbcopper/cli2/internal/PositionalArgumentTranslator.h>
2
3 #include <gtest/gtest.h>
4
5 #include <pbcopper/cli2/PositionalArgument.h>
6 #include <pbcopper/cli2/internal/PositionalArgumentData.h>
7
8 using PositionalArgument = PacBio::CLI_v2::PositionalArgument;
9 using PositionalArgumentData = PacBio::CLI_v2::internal::PositionalArgumentData;
10 using PositionalArgumentTranslator = PacBio::CLI_v2::internal::PositionalArgumentTranslator;
11
12 // clang-format off
13
14 TEST(CLI2_PositionalArgumentTranslator, throws_on_empty_text)
15 {
16 const PositionalArgument testArg{}; // (DB): leave these braces, because icpc
17 EXPECT_THROW(PositionalArgumentTranslator::Translate(testArg), std::runtime_error);
18 }
19
20 TEST(CLI2_PositionalArgumentTranslator, throws_if_name_is_missing)
21 {
22 const PositionalArgument testArg
23 {
24 R"({
25 "description" : "test_description"
26 })"
27 };
28
29 EXPECT_THROW(PositionalArgumentTranslator::Translate(testArg), std::runtime_error);
30 }
31
32 TEST(CLI2_PositionalArgumentTranslator, throws_if_name_is_empty)
33 {
34 const PositionalArgument testArg
35 {
36 R"({
37 "name" : "",
38 "description" : "test_description"
39 })"
40 };
41
42 EXPECT_THROW(PositionalArgumentTranslator::Translate(testArg), std::runtime_error);
43 }
44
45 TEST(CLI2_PositionalArgumentTranslator, throws_if_description_is_missing)
46 {
47 const PositionalArgument testArg
48 {
49 R"({
50 "name" : "test"
51 })"
52 };
53
54 EXPECT_THROW(PositionalArgumentTranslator::Translate(testArg), std::runtime_error);
55 }
56
57 TEST(CLI2_PositionalArgumentTranslator, throws_if_description_is_empty)
58 {
59 const PositionalArgument testArg
60 {
61 R"({
62 "name" : "test",
63 "description" : ""
64 })"
65 };
66
67 EXPECT_THROW(PositionalArgumentTranslator::Translate(testArg), std::runtime_error);
68 }
69
70 TEST(CLI2_PositionalArgumentTranslator, creates_minimal_positional_arg)
71 {
72 const PositionalArgument testArg
73 {
74 R"({
75 "name" : "test_name",
76 "description" : "test_description"
77 })"
78 };
79
80 const auto posArgData = PositionalArgumentTranslator::Translate(testArg);
81 EXPECT_EQ("test_name", posArgData.Name);
82 EXPECT_EQ("test_description", posArgData.Description);
83 EXPECT_TRUE(posArgData.Required);
84 EXPECT_EQ(PacBio::CLI_v2::OptionValueType::STRING, posArgData.Type);
85 }
86
87 TEST(CLI2_PositionalArgumentTranslator, creates_file_positional_arg)
88 {
89 const PositionalArgument testArg
90 {
91 R"({
92 "name" : "test_name",
93 "description" : "test_description",
94 "type" : "file"
95 })"
96 };
97
98 const auto posArgData = PositionalArgumentTranslator::Translate(testArg);
99 EXPECT_EQ("test_name", posArgData.Name);
100 EXPECT_EQ("test_description", posArgData.Description);
101 EXPECT_TRUE(posArgData.Required);
102 EXPECT_EQ(PacBio::CLI_v2::OptionValueType::FILE, posArgData.Type);
103 }
104
105 TEST(CLI2_PositionalArgumentTranslator, creates_dir_positional_arg)
106 {
107 const PositionalArgument testArg
108 {
109 R"({
110 "name" : "test_name",
111 "description" : "test_description",
112 "type" : "dir"
113 })"
114 };
115
116 const auto posArgData = PositionalArgumentTranslator::Translate(testArg);
117 EXPECT_EQ("test_name", posArgData.Name);
118 EXPECT_EQ("test_description", posArgData.Description);
119 EXPECT_TRUE(posArgData.Required);
120 EXPECT_EQ(PacBio::CLI_v2::OptionValueType::DIR, posArgData.Type);
121 }
122
123 TEST(CLI2_PositionalArgumentTranslator, creates_optional_positional_arg)
124 {
125 const PositionalArgument testArg
126 {
127 R"({
128 "name" : "test_name",
129 "description" : "test_description",
130 "required" : false
131 })"
132 };
133 const auto posArgData = PositionalArgumentTranslator::Translate(testArg);
134 EXPECT_EQ("test_name", posArgData.Name);
135 EXPECT_EQ("test_description", posArgData.Description);
136 EXPECT_FALSE(posArgData.Required);
137 EXPECT_EQ(PacBio::CLI_v2::OptionValueType::STRING, posArgData.Type);
138 }
139
140 TEST(CLI2_PositionalArgumentTranslator, can_create_description_from_array)
141 {
142 const std::string expectedText{
143 "Specifies the level of info which will be output produced on stderr. "
144 "0 turns all output off, 1 outputs only warnings, while levels 2 and "
145 "above outputs a status message every 1000000 (2), 100000 (3), 1000 (4), "
146 "100 (5), 10 (6) and 1 (7) reads."
147 };
148
149 const PositionalArgument testArg
150 {
151 R"({
152 "name" : "test_name",
153 "description" : [
154 "Specifies the level of info which will be output produced on stderr. ",
155 "0 turns all output off, 1 outputs only warnings, while levels 2 and ",
156 "above outputs a status message every 1000000 (2), 100000 (3), 1000 (4), ",
157 "100 (5), 10 (6) and 1 (7) reads."
158 ],
159 "required" : false
160 })"
161 };
162
163 const auto testOptionData = PositionalArgumentTranslator::Translate(testArg);
164 EXPECT_EQ(expectedText, testOptionData.Description);
165 }
166
167 // clang-format on