More explicit error messages.
All checks were successful
Remind unit tests / tests (push) Successful in 47s

This commit is contained in:
Dianne Skoll
2024-09-07 13:25:31 -04:00
parent 8c3d2c4003
commit 5b7d4a07ec
2 changed files with 28 additions and 13 deletions

View File

@@ -1919,8 +1919,14 @@ static int set_constant_value(expr_node *atom)
return OK;
} else if (*s == '\'') { /* It's a literal date */
s++;
if ((r=ParseLiteralDate(&s, &dse, &tim)) != 0) return r;
if (*s != '\'') return E_BAD_DATE;
if ((r=ParseLiteralDate(&s, &dse, &tim)) != 0) {
Eprint("%s: %s", ErrMsg[r], DBufValue(&ExprBuf));
return r;
}
if (*s != '\'') {
Eprint("%s: %s", ErrMsg[E_BAD_DATE], DBufValue(&ExprBuf));
return E_BAD_DATE;
}
if (tim == NO_TIME) {
atom->u.value.type = DATE_TYPE;
atom->u.value.v.val = dse;
@@ -1944,7 +1950,10 @@ static int set_constant_value(expr_node *atom)
}
if (*s == ':' || *s == '.' || *s == TimeSep) { /* Must be a literal time */
s++;
if (!isdigit(*s)) return E_BAD_TIME;
if (!isdigit(*s)) {
Eprint("%s: `%s'", ErrMsg[E_BAD_TIME], DBufValue(&ExprBuf));
return E_BAD_TIME;
}
h = val;
m = 0;
while (isdigit(*s)) {
@@ -1960,9 +1969,15 @@ static int set_constant_value(expr_node *atom)
s++;
}
}
if (*s || h>23 || m>59) return E_BAD_TIME;
if (*s || h>23 || m>59) {
Eprint("%s: `%s'", ErrMsg[E_BAD_TIME], DBufValue(&ExprBuf));
return E_BAD_TIME;
}
if (ampm) {
if (h < 1 || h > 12) return E_BAD_TIME;
if (h < 1 || h > 12) {
Eprint("%s: `%s'", ErrMsg[E_BAD_TIME], DBufValue(&ExprBuf));
return E_BAD_TIME;
}
if (ampm == 'a') {
if (h == 12) {
h = 0;

View File

@@ -3486,7 +3486,7 @@ REM AT 13:00PM MSG foo 13p
DEBUG +x
SET x 0:00am + 0
../tests/test.rem(625): Ill-formed time
../tests/test.rem(625): Ill-formed time: `0:00am'
SET x 1:00AM + 0
01:00 + 0 => 01:00
SET x 2:00am + 0
@@ -3512,10 +3512,10 @@ SET x 11:00AM + 0
SET x 12:00am + 0
00:00 + 0 => 00:00
SET x 13:00AM + 0
../tests/test.rem(638): Ill-formed time
../tests/test.rem(638): Ill-formed time: `13:00AM'
SET x 0:00pm + 0
../tests/test.rem(640): Ill-formed time
../tests/test.rem(640): Ill-formed time: `0:00pm'
SET x 1:00PM + 0
13:00 + 0 => 13:00
SET x 2:00pm + 0
@@ -3541,10 +3541,10 @@ SET x 11:00PM + 0
SET x 12:00pm + 0
12:00 + 0 => 12:00
SET x 13:00PM + 0
../tests/test.rem(653): Ill-formed time
../tests/test.rem(653): Ill-formed time: `13:00PM'
SET x '2015-02-03@0:00am' + 0
../tests/test.rem(655): Ill-formed time
../tests/test.rem(655): Ill-formed time: '2015-02-03@0:00am'
SET x '2015-02-03@1:00AM' + 0
2015-02-03@01:00 + 0 => 2015-02-03@01:00
SET x '2015-02-03@2:00am' + 0
@@ -3570,10 +3570,10 @@ SET x '2015-02-03@11:00AM' + 0
SET x '2015-02-03@12:00am' + 0
2015-02-03@00:00 + 0 => 2015-02-03@00:00
SET x '2015-02-03@13:00AM' + 0
../tests/test.rem(668): Ill-formed time
../tests/test.rem(668): Ill-formed time: '2015-02-03@13:00AM'
SET x '2015-02-03@0:00pm' + 0
../tests/test.rem(670): Ill-formed time
../tests/test.rem(670): Ill-formed time: '2015-02-03@0:00pm'
SET x '2015-02-03@1:00PM' + 0
2015-02-03@13:00 + 0 => 2015-02-03@13:00
SET x '2015-02-03@2:00pm' + 0
@@ -3599,7 +3599,7 @@ SET x '2015-02-03@11:00PM' + 0
SET x '2015-02-03@12:00pm' + 0
2015-02-03@12:00 + 0 => 2015-02-03@12:00
SET x '2015-02-03@13:00PM' + 0
../tests/test.rem(683): Ill-formed time
../tests/test.rem(683): Ill-formed time: '2015-02-03@13:00PM'
# Test the ampm function
set x ampm(0:12) + ""