Skip to content

Commit 27cff5d

Browse files
add edge cases
1 parent d752fde commit 27cff5d

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

code/tests/cases/test_parser.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,43 @@ FOSSIL_TEST_CASE(c_argument_types) {
139139
fossil_io_parser_free(palette);
140140
} // end case
141141

142+
FOSSIL_TEST_CASE(c_null_palette) {
143+
fossil_io_parser_palette_t *palette = NULL;
144+
FOSSIL_TEST_ASSUME(fossil_io_parser_add_command(palette, "test_command", "Test Command Description") == NULL, "Adding command to NULL palette should return NULL");
145+
fossil_io_parser_parse(palette, 0, NULL);
146+
} // end case
147+
148+
FOSSIL_TEST_CASE(c_empty_command_name) {
149+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
150+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "", "Empty Command Name Description");
151+
FOSSIL_TEST_ASSUME(command == NULL, "Command with empty name should not be added");
152+
fossil_io_parser_free(palette);
153+
} // end case
154+
155+
FOSSIL_TEST_CASE(c_duplicate_command_name) {
156+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
157+
fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
158+
fossil_io_parser_command_t *duplicate = fossil_io_parser_add_command(palette, "test_command", "Duplicate Command Description");
159+
FOSSIL_TEST_ASSUME(duplicate == NULL, "Duplicate command name should not be allowed");
160+
fossil_io_parser_free(palette);
161+
} // end case
162+
163+
FOSSIL_TEST_CASE(c_null_argument_name) {
164+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
165+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
166+
fossil_io_parser_argument_t *argument = fossil_io_parser_add_argument(command, NULL, FOSSIL_IO_PARSER_STRING, NULL, 0);
167+
FOSSIL_TEST_ASSUME(argument == NULL, "Argument with NULL name should not be added");
168+
fossil_io_parser_free(palette);
169+
} // end case
170+
171+
FOSSIL_TEST_CASE(c_invalid_argument_type) {
172+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
173+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
174+
fossil_io_parser_argument_t *argument = fossil_io_parser_add_argument(command, "invalid_arg", FOSSIL_IO_PARSER_INVALID, NULL, 0);
175+
FOSSIL_TEST_ASSUME(argument == NULL, "Argument with invalid type should not be added");
176+
fossil_io_parser_free(palette);
177+
} // end case
178+
142179
// * * * * * * * * * * * * * * * * * * * * * * * *
143180
// * Fossil Logic Test Pool
144181
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -149,6 +186,11 @@ FOSSIL_TEST_GROUP(c_parser_test_cases) {
149186
FOSSIL_TEST_ADD(c_parser_suite, c_parse_command);
150187
FOSSIL_TEST_ADD(c_parser_suite, c_free_palette);
151188
FOSSIL_TEST_ADD(c_parser_suite, c_argument_types);
189+
FOSSIL_TEST_ADD(c_parser_suite, c_null_palette);
190+
FOSSIL_TEST_ADD(c_parser_suite, c_empty_command_name);
191+
FOSSIL_TEST_ADD(c_parser_suite, c_duplicate_command_name);
192+
FOSSIL_TEST_ADD(c_parser_suite, c_null_argument_name);
193+
FOSSIL_TEST_ADD(c_parser_suite, c_invalid_argument_type);
152194

153195
FOSSIL_TEST_REGISTER(c_parser_suite);
154196
} // end of group

code/tests/cases/test_parser.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,48 @@ FOSSIL_TEST_CASE(cpp_wrapper_argument_types) {
249249
parser.free(palette);
250250
} // end case
251251

252+
FOSSIL_TEST_CASE(cpp_wrapper_null_palette) {
253+
fossil::io::Parser parser;
254+
fossil_io_parser_palette_t *palette = NULL;
255+
FOSSIL_TEST_ASSUME(parser.add_command(palette, "test_command", "Test Command Description") == NULL, "Adding command to NULL palette should return NULL");
256+
parser.parse(palette, 0, NULL);
257+
} // end case
258+
259+
FOSSIL_TEST_CASE(cpp_wrapper_empty_command_name) {
260+
fossil::io::Parser parser;
261+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
262+
fossil_io_parser_command_t *command = parser.add_command(palette, "", "Empty Command Name Description");
263+
FOSSIL_TEST_ASSUME(command == NULL, "Command with empty name should not be added");
264+
parser.free(palette);
265+
} // end case
266+
267+
FOSSIL_TEST_CASE(cpp_wrapper_duplicate_command_name) {
268+
fossil::io::Parser parser;
269+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
270+
parser.add_command(palette, "wrapper_command", "Wrapper Command Description");
271+
fossil_io_parser_command_t *duplicate = parser.add_command(palette, "wrapper_command", "Duplicate Command Description");
272+
FOSSIL_TEST_ASSUME(duplicate == NULL, "Duplicate command name should not be allowed");
273+
parser.free(palette);
274+
} // end case
275+
276+
FOSSIL_TEST_CASE(cpp_wrapper_null_argument_name) {
277+
fossil::io::Parser parser;
278+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
279+
fossil_io_parser_command_t *command = parser.add_command(palette, "wrapper_command", "Wrapper Command Description");
280+
fossil_io_parser_argument_t *argument = parser.add_argument(command, NULL, FOSSIL_IO_PARSER_STRING, NULL, 0);
281+
FOSSIL_TEST_ASSUME(argument == NULL, "Argument with NULL name should not be added");
282+
parser.free(palette);
283+
} // end case
284+
285+
FOSSIL_TEST_CASE(cpp_wrapper_invalid_argument_type) {
286+
fossil::io::Parser parser;
287+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
288+
fossil_io_parser_command_t *command = parser.add_command(palette, "wrapper_command", "Wrapper Command Description");
289+
fossil_io_parser_argument_t *argument = parser.add_argument(command, "invalid_arg", FOSSIL_IO_PARSER_INVALID, NULL, 0);
290+
FOSSIL_TEST_ASSUME(argument == NULL, "Argument with invalid type should not be added");
291+
parser.free(palette);
292+
} // end case
293+
252294
// * * * * * * * * * * * * * * * * * * * * * * * *
253295
// * Fossil Logic Test Pool
254296
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -267,6 +309,11 @@ FOSSIL_TEST_GROUP(cpp_parser_test_cases) {
267309
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_parse_command);
268310
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_free_palette);
269311
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_argument_types);
312+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_null_palette);
313+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_empty_command_name);
314+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_duplicate_command_name);
315+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_null_argument_name);
316+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_invalid_argument_type);
270317

271318
FOSSIL_TEST_REGISTER(cpp_parser_suite);
272319
} // end of group

0 commit comments

Comments
 (0)