1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /*
- * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- */
- /**
- * @file test_opt_peekNextHunk.c
- * @brief unittest for shellmatta opt_peekNextHunk
- * @author Stefan Strobel <stefan.strobel@shimatta.net>
- */
- #include "test/framework/catch.hpp"
- #include "src/shellmatta_opt.c"
- #include <string.h>
- TEST_CASE( "shellmatta_opt peekNextHunk next char without space" ) {
- char ret = 0;
- shellmatta_instance_t inst;
- char *dummyData = (char*) "Welcome... to Jurassic Park.";
- char buffer[1024u];
- memcpy(buffer, dummyData, strlen(dummyData));
- inst.buffer = buffer;
- inst.bufferSize = sizeof(buffer);
- inst.inputCount = 28u;
- inst.optionParser.nextOffset = 11u;
- ret = peekNextHunk(&inst);
- CHECK( ret == 't' );
- }
- TEST_CASE( "shellmatta_opt peekNextHunk next char with space" ) {
- char ret = 0;
- shellmatta_instance_t inst;
- char *dummyData = (char*) "Welcome... to Jurassic Park.\0";
- char buffer[1024u];
- memcpy(buffer, dummyData, strlen(dummyData));
- inst.buffer = buffer;
- inst.bufferSize = sizeof(buffer);
- inst.inputCount = 28u;
- inst.optionParser.nextOffset = 13u;
- ret = peekNextHunk(&inst);
- CHECK( ret == 'J' );
- }
- TEST_CASE( "shellmatta_opt peekNextHunk next hunk escape and space" ) {
- char ret = 0;
- shellmatta_instance_t inst;
- char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend.";
- char buffer[1024u];
- uint16_t stringsize = 77u;
- memcpy(buffer, dummyData, stringsize);
- inst.buffer = buffer;
- inst.bufferSize = sizeof(buffer);
- inst.inputCount = stringsize;
-
- inst.optionParser.nextOffset = 28u;
- ret = peekNextHunk(&inst);
- CHECK( ret == 'R' );
- }
- TEST_CASE( "shellmatta_opt peekNextHunk next char with spaces" ) {
- char ret = 0;
- shellmatta_instance_t inst;
- char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend.";
- char buffer[1024u];
- uint16_t stringsize = 77u;
- memcpy(buffer, dummyData, stringsize);
- inst.buffer = buffer;
- inst.bufferSize = sizeof(buffer);
- inst.inputCount = stringsize;
-
- inst.optionParser.nextOffset = 36u;
- ret = peekNextHunk(&inst);
- CHECK( ret == 'm' );
- }
|