Merge pull request #93856 from timothyqiu/expression-period
Fix parsing of `4.` in Expression
This commit is contained in:
commit
d1caac5e75
|
@ -30,12 +30,7 @@
|
||||||
|
|
||||||
#include "expression.h"
|
#include "expression.h"
|
||||||
|
|
||||||
#include "core/io/marshalls.h"
|
|
||||||
#include "core/math/math_funcs.h"
|
|
||||||
#include "core/object/class_db.h"
|
#include "core/object/class_db.h"
|
||||||
#include "core/object/ref_counted.h"
|
|
||||||
#include "core/os/os.h"
|
|
||||||
#include "core/variant/variant_parser.h"
|
|
||||||
|
|
||||||
Error Expression::_get_token(Token &r_token) {
|
Error Expression::_get_token(Token &r_token) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -392,7 +387,6 @@ Error Expression::_get_token(Token &r_token) {
|
||||||
if (is_digit(c)) {
|
if (is_digit(c)) {
|
||||||
} else if (c == 'e') {
|
} else if (c == 'e') {
|
||||||
reading = READING_EXP;
|
reading = READING_EXP;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
reading = READING_DONE;
|
reading = READING_DONE;
|
||||||
}
|
}
|
||||||
|
@ -419,7 +413,9 @@ Error Expression::_get_token(Token &r_token) {
|
||||||
is_first_char = false;
|
is_first_char = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c != 0) {
|
||||||
str_ofs--;
|
str_ofs--;
|
||||||
|
}
|
||||||
|
|
||||||
r_token.type = TK_CONSTANT;
|
r_token.type = TK_CONSTANT;
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,59 @@ TEST_CASE("[Expression] Floating-point arithmetic") {
|
||||||
"Float multiplication-addition-subtraction-division should return the expected result.");
|
"Float multiplication-addition-subtraction-division should return the expected result.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Expression] Floating-point notation") {
|
||||||
|
Expression expression;
|
||||||
|
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
expression.parse("2.") == OK,
|
||||||
|
"The expression should parse successfully.");
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
double(expression.execute()) == doctest::Approx(2.0),
|
||||||
|
"The expression should return the expected result.");
|
||||||
|
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
expression.parse("(2.)") == OK,
|
||||||
|
"The expression should parse successfully.");
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
double(expression.execute()) == doctest::Approx(2.0),
|
||||||
|
"The expression should return the expected result.");
|
||||||
|
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
expression.parse(".3") == OK,
|
||||||
|
"The expression should parse successfully.");
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
double(expression.execute()) == doctest::Approx(0.3),
|
||||||
|
"The expression should return the expected result.");
|
||||||
|
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
expression.parse("2.+5.") == OK,
|
||||||
|
"The expression should parse successfully.");
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
double(expression.execute()) == doctest::Approx(7.0),
|
||||||
|
"The expression should return the expected result.");
|
||||||
|
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
expression.parse(".3-.8") == OK,
|
||||||
|
"The expression should parse successfully.");
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
double(expression.execute()) == doctest::Approx(-0.5),
|
||||||
|
"The expression should return the expected result.");
|
||||||
|
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
expression.parse("2.+.2") == OK,
|
||||||
|
"The expression should parse successfully.");
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
double(expression.execute()) == doctest::Approx(2.2),
|
||||||
|
"The expression should return the expected result.");
|
||||||
|
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
expression.parse(".0*0.") == OK,
|
||||||
|
"The expression should parse successfully.");
|
||||||
|
CHECK_MESSAGE(
|
||||||
|
double(expression.execute()) == doctest::Approx(0.0),
|
||||||
|
"The expression should return the expected result.");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("[Expression] Scientific notation") {
|
TEST_CASE("[Expression] Scientific notation") {
|
||||||
Expression expression;
|
Expression expression;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue