Skip to content

Commit

Permalink
Fix #168
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMirzayanov committed Sep 6, 2023
1 parent 9e60dd4 commit 31f40a0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
7 changes: 3 additions & 4 deletions testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3578,13 +3578,12 @@ static inline long long stringToLongLong(InStream &in, const char *buffer) {

bool minus = false;
size_t length = strlen(buffer);
if (length == 0 || length > 20)
in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str());

if (length > 1 && buffer[0] == '-')
minus = true;

if (length > 20)
in.quit(_pe, ("Expected integer, but \"" + __testlib_part(buffer) + "\" found").c_str());

long long retval = 0LL;

int zeroes = 0;
Expand Down Expand Up @@ -5418,7 +5417,7 @@ T optValueToIntegral(const std::string &s_, bool nonnegative) {
for (size_t i = pos; i < s.length(); i++) {
if (s[i] < '0' || s[i] > '9')
__testlib_fail("Opts: expected integer but '" + compress(s_) + "' found");
value = value * 10 + s[i] - '0';
value = T(value * 10 + s[i] - '0');
about = about * 10 + s[i] - '0';
}
value *= sign;
Expand Down
12 changes: 12 additions & 0 deletions tests/test-004_use-test.h/refs/r1/stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ FAIL Token parameter [name=n] equals to "abacab", doesn't correspond to pattern
FAIL Token parameter [name=n] equals to "abacabaa", doesn't correspond to pattern "a|test|abacaba|ok|abac" (based on )
FAIL Token parameter [name=n] equals to "abacaba!", doesn't correspond to pattern "a|test|abacaba|ok|abac" (based on )
FAIL Integer element a[4] equals to 4, violates the range [1, 3] (based on )
FAIL Expected integer, but "" found ()
FAIL Expected integer, but "-" found ()
FAIL Expected integer, but "+" found ()
FAIL Expected integer, but "00" found ()
FAIL Expected integer, but "0123" found ()
FAIL Expected integer, but "+123" found ()
FAIL Expected integer, but "9223372036854775808" found ()
FAIL Expected integer, but "-9223372036854775809" found ()
FAIL Expected integer, but "1 " found ()
FAIL Expected integer, but " 1" found ()
FAIL Expected integer, but "1 2" found ()
FAIL Expected integer, but "-0" found ()
3 changes: 2 additions & 1 deletion tests/test-004_use-test.h/refs/r1/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Running test 'tokenize'
Running test 'opts' OK
Running test 'instream' OK
Running test 'pattern' OK
Running test 'stringToLongLong' OK

SUCCESS 6 tests passed.
SUCCESS 7 tests passed.
1 change: 1 addition & 0 deletions tests/test-004_use-test.h/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using namespace std;
#include "tests/test-opts.cpp"
#include "tests/test-instream.cpp"
#include "tests/test-pattern.cpp"
#include "tests/test-stringToLongLong.cpp"

int main() {
disableFinalizeGuard();
Expand Down
2 changes: 1 addition & 1 deletion tests/test-004_use-test.h/tests/test-opts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(opts) {
for (size_t i = 0; i < parts.size(); ++i) {
opts[i + 1] = parts[i].c_str();
}
prepareOpts(opts.size(), (char**)opts.data());
prepareOpts(int(opts.size()), (char**)opts.data());
}
{
GenArrayOpts res;
Expand Down
19 changes: 19 additions & 0 deletions tests/test-004_use-test.h/tests/test-stringToLongLong.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
TEST(stringToLongLong) {
ensure(stringToLongLong(inf, "123") == 123LL);
ensure(stringToLongLong(inf, "-123") == -123LL);
ensure(stringToLongLong(inf, "0") == 0LL);
ensure(stringToLongLong(inf, "9223372036854775807") == 9223372036854775807LL);
ensure(stringToLongLong(inf, "-9223372036854775808") == -9223372036854775807LL - 1LL);
ensure_exit(3, [](){stringToLongLong(inf, "");});
ensure_exit(3, [](){stringToLongLong(inf, "-");});
ensure_exit(3, [](){stringToLongLong(inf, "+");});
ensure_exit(3, [](){stringToLongLong(inf, "00");});
ensure_exit(3, [](){stringToLongLong(inf, "0123");});
ensure_exit(3, [](){stringToLongLong(inf, "+123");});
ensure_exit(3, [](){stringToLongLong(inf, "9223372036854775808");});
ensure_exit(3, [](){stringToLongLong(inf, "-9223372036854775809");});
ensure_exit(3, [](){stringToLongLong(inf, "1 ");});
ensure_exit(3, [](){stringToLongLong(inf, " 1");});
ensure_exit(3, [](){stringToLongLong(inf, "1 2");});
ensure_exit(3, [](){stringToLongLong(inf, "-0");});
}

0 comments on commit 31f40a0

Please sign in to comment.