diff --git a/interpreter.c b/interpreter.c index f90698d..2f03ae4 100644 --- a/interpreter.c +++ b/interpreter.c @@ -20,34 +20,6 @@ char *copyString(char *data) return p; } -/** - * Checks if a string follows the format of a decimal number. - * - * \param [in] data The string to check the format of. - * - * \retval 0 The string is not a decimal number. - * - * \retval 1 The string is a decimal number. - */ -unsigned int isDecString(const char *data) -{ - size_t n; - size_t len = strlen(data); - - /* Check for an empty string */ - if (len == 0) return 0; - - /* Check for non-digit, non-hyphen, and non-period characters */ - for (n = 0; n < len; n++) { - if (!isdigit(data[n]) - && data[n] != '.' - && data[n] != '-') - return 0; - } - - return 1; -} - /** * Checks if a string follows the format of a hexadecimal number. * @@ -1338,32 +1310,14 @@ ValueObject *castIntegerExplicit(ValueObject *node, /* Perform interpolation */ ValueObject *ret = NULL; ValueObject *interp = castStringExplicit(node, scope); - long long value; if (!interp) return NULL; - if (!isDecString(getString(interp))) { - error(IN_UNABLE_TO_CAST_VALUE); - deleteValueObject(interp); - return NULL; - } - if (sscanf(getString(interp), "%lli", &value) != 1) { - error(IN_EXPECTED_INTEGER_VALUE); - deleteValueObject(interp); - return NULL; - } + long long value = strtoll(getString(interp), NULL, 0); ret = createIntegerValueObject(value); deleteValueObject(interp); return ret; } else { - long long value; - if (!isDecString(getString(node))) { - error(IN_UNABLE_TO_CAST_VALUE); - return NULL; - } - if (sscanf(getString(node), "%lli", &value) != 1) { - error(IN_EXPECTED_INTEGER_VALUE); - return NULL; - } + long long value = strtoll(getString(node), NULL, 0); return createIntegerValueObject(value); } case VT_FUNC: @@ -1409,32 +1363,14 @@ ValueObject *castFloatExplicit(ValueObject *node, /* Perform interpolation */ ValueObject *ret = NULL; ValueObject *interp = castStringExplicit(node, scope); - float value; if (!interp) return NULL; - if (!isDecString(getString(interp))) { - error(IN_UNABLE_TO_CAST_VALUE); - deleteValueObject(interp); - return NULL; - } - if (sscanf(getString(interp), "%f", &value) != 1) { - error(IN_EXPECTED_DECIMAL); - deleteValueObject(interp); - return NULL; - } + float value = strtof(getString(interp), NULL); ret = createFloatValueObject(value); deleteValueObject(interp); return ret; } else { - float value; - if (!isDecString(getString(node))) { - error(IN_UNABLE_TO_CAST_VALUE); - return NULL; - } - if (sscanf(getString(node), "%f", &value) != 1) { - error(IN_EXPECTED_DECIMAL); - return NULL; - } + float value = strtof(getString(node), NULL); return createFloatValueObject(value); } case VT_FUNC: diff --git a/interpreter.h b/interpreter.h index 7dbd9d6..7b78b81 100644 --- a/interpreter.h +++ b/interpreter.h @@ -133,7 +133,6 @@ typedef struct scopeobject { /**@{*/ void printInterpreterError(const char *, IdentifierNode *, ScopeObject *); char *copyString(char *); -unsigned int isDecString(const char *); unsigned int isHexString(const char *); char *resolveIdentifierName(IdentifierNode *, ScopeObject *); int resolveTerminalSlot(ScopeObject *, ScopeObject *, IdentifierNode *, ScopeObject **, IdentifierNode **); diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/CMakeLists.txt b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/CMakeLists.txt index 754994b..093aff6 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/CMakeLists.txt @@ -1,2 +1,2 @@ INCLUDE(AddLolTest) -ADD_LOL_TEST(2-EmptyString ERROR) +ADD_LOL_TEST(2-EmptyString OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.err b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.err deleted file mode 100644 index e69de29..0000000 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.lol b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.lol index f6c21a6..f47d7d8 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.lol +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.lol @@ -1,3 +1,3 @@ HAI 1.3 - MAEK "" A NUMBR + VISIBLE MAEK "" A NUMBR KTHXBYE diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.out b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.out @@ -0,0 +1 @@ +0 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.readme b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.readme index 621ab9a..c1d4aa7 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.readme +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/2-EmptyString/test.readme @@ -1,2 +1,2 @@ This test checks to make sure explicitly casting an empty string to an integer -type results in an error. +type results in 0. diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/CMakeLists.txt b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/CMakeLists.txt index 76c3f19..d14ceab 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/CMakeLists.txt @@ -1,2 +1,2 @@ INCLUDE(AddLolTest) -ADD_LOL_TEST(3-NonNumber ERROR) +ADD_LOL_TEST(3-NonNumber OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.err b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.err deleted file mode 100644 index e69de29..0000000 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.lol b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.lol index ff0b1c4..b1f22b9 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.lol +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.lol @@ -1,3 +1,3 @@ HAI 1.3 - MAEK "abc" A NUMBR + VISIBLE MAEK "abc" A NUMBR KTHXBYE diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.out b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.out @@ -0,0 +1 @@ +0 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.readme b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.readme index 2e9553b..1364d4e 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.readme +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/3-NonNumber/test.readme @@ -1,2 +1,2 @@ This test checks to make sure explicitly casting a non-number string to an -integer type results in an error. +integer type results in 0. diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/CMakeLists.txt b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/CMakeLists.txt new file mode 100644 index 0000000..9bb607c --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(AddLolTest) +ADD_LOL_TEST(4-RelaxedNumbers OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.lol b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.lol new file mode 100644 index 0000000..cc11f72 --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.lol @@ -0,0 +1,6 @@ +HAI 1.3 + VISIBLE MAEK " 123" A NUMBR BTW leading whitespace is ignored + VISIBLE MAEK "123x" A NUMBR BTW parsing stops at the first non-digit + VISIBLE MAEK "0377" A NUMBR BTW octal prefix + VISIBLE MAEK "0xFF" A NUMBR BTW hexadecimal prefix +KTHXBYE diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.out b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.out new file mode 100644 index 0000000..93374fc --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.out @@ -0,0 +1,4 @@ +123 +123 +255 +255 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.readme b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.readme new file mode 100644 index 0000000..485f16d --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.readme @@ -0,0 +1,2 @@ +This test checks that the explicit cast operator correctly casts string values +to integer types as would be done by libc's strtoll() function. diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/CMakeLists.txt b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/CMakeLists.txt index d8ddc15..63389f9 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/3-ToInteger/5-FromString/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(1-Numbers) add_subdirectory(2-EmptyString) add_subdirectory(3-NonNumber) +add_subdirectory(4-RelaxedNumbers) diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/CMakeLists.txt b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/CMakeLists.txt index 754994b..093aff6 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/CMakeLists.txt @@ -1,2 +1,2 @@ INCLUDE(AddLolTest) -ADD_LOL_TEST(2-EmptyString ERROR) +ADD_LOL_TEST(2-EmptyString OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.err b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.err deleted file mode 100644 index e69de29..0000000 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.lol b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.lol index 3a7e9a5..0b028a8 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.lol +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.lol @@ -1,3 +1,3 @@ HAI 1.3 - MAEK "" A NUMBAR + VISIBLE MAEK "" A NUMBAR KTHXBYE diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.out b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.out new file mode 100644 index 0000000..fb1088c --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.out @@ -0,0 +1 @@ +0.00 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.readme b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.readme index cf463bc..be2002f 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.readme +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/2-EmptyString/test.readme @@ -1,2 +1,2 @@ This test checks to make sure explicitly casting an empty string to a floating -point decimal type results in an error. +point decimal type results in 0.00. diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/CMakeLists.txt b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/CMakeLists.txt index 76c3f19..d14ceab 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/CMakeLists.txt @@ -1,2 +1,2 @@ INCLUDE(AddLolTest) -ADD_LOL_TEST(3-NonNumber ERROR) +ADD_LOL_TEST(3-NonNumber OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.err b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.err deleted file mode 100644 index e69de29..0000000 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.lol b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.lol index 1adbf1e..783ea36 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.lol +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.lol @@ -1,3 +1,3 @@ HAI 1.3 - MAEK "abc" A NUMBAR + VISIBLE MAEK "abc" A NUMBAR KTHXBYE diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.out b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.out new file mode 100644 index 0000000..fb1088c --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.out @@ -0,0 +1 @@ +0.00 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.readme b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.readme index 3af145a..15345c7 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.readme +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/3-NonNumber/test.readme @@ -1,2 +1,2 @@ This test checks to make sure explicitly casting a non-number string to a -floating point decimal type results in an error. +floating point decimal type results in 0.00. diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/CMakeLists.txt b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/CMakeLists.txt new file mode 100644 index 0000000..9bb607c --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(AddLolTest) +ADD_LOL_TEST(4-RelaxedNumbers OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.lol b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.lol new file mode 100644 index 0000000..67f77cd --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.lol @@ -0,0 +1,4 @@ +HAI 1.3 + VISIBLE MAEK " 1.23" A NUMBAR BTW leading whitespace is ignored + VISIBLE MAEK "1.23x" A NUMBAR BTW parsing stops at the first non-digit +KTHXBYE diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.out b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.out new file mode 100644 index 0000000..f549c6b --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.out @@ -0,0 +1,2 @@ +1.23 +1.23 diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.readme b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.readme new file mode 100644 index 0000000..f02cbf0 --- /dev/null +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.readme @@ -0,0 +1,2 @@ +This test checks that the explicit cast operator correctly casts string values +to floating point decimal types as would be done by libc's strtof() function. diff --git a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/CMakeLists.txt b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/CMakeLists.txt index d8ddc15..63389f9 100644 --- a/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/17-ExplicitCast/4-ToFloat/5-FromString/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(1-Numbers) add_subdirectory(2-EmptyString) add_subdirectory(3-NonNumber) +add_subdirectory(4-RelaxedNumbers) diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/CMakeLists.txt b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/CMakeLists.txt index 754994b..093aff6 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/CMakeLists.txt @@ -1,2 +1,2 @@ INCLUDE(AddLolTest) -ADD_LOL_TEST(2-EmptyString ERROR) +ADD_LOL_TEST(2-EmptyString OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.err b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.err deleted file mode 100644 index e69de29..0000000 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.lol b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.lol index a254871..79a54a4 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.lol +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.lol @@ -1,4 +1,5 @@ HAI 1.3 I HAS A var ITZ "" var IS NOW A NUMBR + VISIBLE var KTHXBYE diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.out b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.out @@ -0,0 +1 @@ +0 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.readme b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.readme index 1ff03c9..bf0da71 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.readme +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/2-EmptyString/test.readme @@ -1,2 +1,2 @@ This test checks to make sure explicitly recasting an empty string to an -integer type results in an error. +integer type results in 0. diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/CMakeLists.txt b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/CMakeLists.txt index 76c3f19..d14ceab 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/CMakeLists.txt @@ -1,2 +1,2 @@ INCLUDE(AddLolTest) -ADD_LOL_TEST(3-NonNumber ERROR) +ADD_LOL_TEST(3-NonNumber OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.err b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.err deleted file mode 100644 index e69de29..0000000 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.lol b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.lol index 2c6d603..3c7cf75 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.lol +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.lol @@ -1,4 +1,5 @@ HAI 1.3 I HAS A var ITZ "abc" var IS NOW A NUMBR + VISIBLE var KTHXBYE diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.out b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.out new file mode 100644 index 0000000..573541a --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.out @@ -0,0 +1 @@ +0 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.readme b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.readme index 7fcf480..3ca976f 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.readme +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/3-NonNumber/test.readme @@ -1,2 +1,2 @@ This test checks to make sure explicitly recasting a non-number string to an -integer type results in an error. +integer type results in 0. diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/CMakeLists.txt b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/CMakeLists.txt new file mode 100644 index 0000000..9bb607c --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(AddLolTest) +ADD_LOL_TEST(4-RelaxedNumbers OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.lol b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.lol new file mode 100644 index 0000000..2ba13f5 --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.lol @@ -0,0 +1,14 @@ +HAI 1.3 + I HAS A var1 ITZ " 123" BTW leading whitespace is ignored + I HAS A var2 ITZ "123x" BTW parsing stops at the first non-digit + I HAS A var3 ITZ "0377" BTW octal prefix + I HAS A var4 ITZ "0xFF" BTW hexadecimal prefix + var1 IS NOW A NUMBR + var2 IS NOW A NUMBR + var3 IS NOW A NUMBR + var4 IS NOW A NUMBR + VISIBLE var1 + VISIBLE var2 + VISIBLE var3 + VISIBLE var4 +KTHXBYE diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.out b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.out new file mode 100644 index 0000000..93374fc --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.out @@ -0,0 +1,4 @@ +123 +123 +255 +255 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.readme b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.readme new file mode 100644 index 0000000..0468c3a --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/4-RelaxedNumbers/test.readme @@ -0,0 +1,2 @@ +This test checks that the explicit recast operator correctly casts string +values to integer types as would be done by libc's strtoll() function. diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/CMakeLists.txt b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/CMakeLists.txt index d8ddc15..63389f9 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/3-ToInteger/5-FromString/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(1-Numbers) add_subdirectory(2-EmptyString) add_subdirectory(3-NonNumber) +add_subdirectory(4-RelaxedNumbers) diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/CMakeLists.txt b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/CMakeLists.txt index 754994b..093aff6 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/CMakeLists.txt @@ -1,2 +1,2 @@ INCLUDE(AddLolTest) -ADD_LOL_TEST(2-EmptyString ERROR) +ADD_LOL_TEST(2-EmptyString OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.err b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.err deleted file mode 100644 index e69de29..0000000 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.lol b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.lol index bb453b3..723534b 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.lol +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.lol @@ -1,4 +1,5 @@ HAI 1.3 I HAS A var ITZ "" var IS NOW A NUMBAR + VISIBLE var KTHXBYE diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.out b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.out new file mode 100644 index 0000000..fb1088c --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.out @@ -0,0 +1 @@ +0.00 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.readme b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.readme index 02f9b6d..639ebee 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.readme +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/2-EmptyString/test.readme @@ -1,2 +1,2 @@ This test checks to make sure explicitly recasting an empty string to a -floating point decimal type results in an error. +floating point decimal type results in 0.00. diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/CMakeLists.txt b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/CMakeLists.txt index 76c3f19..d14ceab 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/CMakeLists.txt @@ -1,2 +1,2 @@ INCLUDE(AddLolTest) -ADD_LOL_TEST(3-NonNumber ERROR) +ADD_LOL_TEST(3-NonNumber OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.err b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.err deleted file mode 100644 index e69de29..0000000 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.lol b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.lol index 9131aa5..69b2567 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.lol +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.lol @@ -1,4 +1,5 @@ HAI 1.3 I HAS A var ITZ "abc" var IS NOW A NUMBAR + VISIBLE var KTHXBYE diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.out b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.out new file mode 100644 index 0000000..fb1088c --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.out @@ -0,0 +1 @@ +0.00 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.readme b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.readme index 135d6fa..9e46a50 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.readme +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/3-NonNumber/test.readme @@ -1,2 +1,2 @@ This test checks to make sure explicitly recasting a non-number string to a -floating point decimal type results in an error. +floating point decimal type results in 0.00. diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/CMakeLists.txt b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/CMakeLists.txt new file mode 100644 index 0000000..9bb607c --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(AddLolTest) +ADD_LOL_TEST(4-RelaxedNumbers OUTPUT test.out) diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.lol b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.lol new file mode 100644 index 0000000..5cd3246 --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.lol @@ -0,0 +1,8 @@ +HAI 1.3 + I HAS A var1 ITZ " 1.23" BTW leading whitespace is ignored + I HAS A var2 ITZ "1.23x" BTW parsing stops at the first non-digit + var1 IS NOW A NUMBAR + var2 IS NOW A NUMBAR + VISIBLE var1 + VISIBLE var2 +KTHXBYE diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.out b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.out new file mode 100644 index 0000000..f549c6b --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.out @@ -0,0 +1,2 @@ +1.23 +1.23 diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.readme b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.readme new file mode 100644 index 0000000..b8fcb43 --- /dev/null +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/4-RelaxedNumbers/test.readme @@ -0,0 +1,3 @@ +This test checks that the explicit recast operator correctly casts string +values to floating point decimal types as would be done by libc's +strtof() function. diff --git a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/CMakeLists.txt b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/CMakeLists.txt index d8ddc15..63389f9 100644 --- a/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/CMakeLists.txt +++ b/test/1.3-Tests/7-Operators/18-ExplicitRecast/4-ToFloat/5-FromString/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory(1-Numbers) add_subdirectory(2-EmptyString) add_subdirectory(3-NonNumber) +add_subdirectory(4-RelaxedNumbers)