fix token generator for negative numbers (#41)

This commit is contained in:
Pedro Flemming 2017-04-25 17:25:00 +02:00 committed by GitHub
parent 793258f872
commit 128cd74670
3 changed files with 835 additions and 828 deletions

File diff suppressed because it is too large Load Diff

View File

@ -179,13 +179,13 @@ TO TOKEN(TO)
[-+*/(){},.;<>=^%:?] { return yytext[0]; }
[0-9]+"."[0-9]* |
-?[0-9]+"."[0-9]* |
"."[0-9]* {
yylval->fval = atof(yytext);
return SQL_FLOATVAL;
}
[0-9]+ {
-?[0-9]+ {
yylval->ival = atol(yytext);
return SQL_INTVAL;
}

View File

@ -58,7 +58,7 @@ TEST(SelectExprTest) {
TEST(SelectHavingTest) {
TEST_PARSE_SINGLE_SQL(
"SELECT city, AVG(grade) AS avg_grade FROM students GROUP BY city HAVING AVG(grade) < 2.0",
"SELECT city, AVG(grade) AS avg_grade FROM students GROUP BY city HAVING AVG(grade) < -2.0",
kStmtSelect,
SelectStatement,
result,
@ -72,6 +72,7 @@ TEST(SelectHavingTest) {
ASSERT(group->having->isSimpleOp('<'));
ASSERT(group->having->expr->isType(kExprFunctionRef));
ASSERT(group->having->expr2->isType(kExprLiteralFloat));
ASSERT_EQ(group->having->expr2->fval, -2.0);
}
@ -122,7 +123,7 @@ TEST(OrderByTest) {
TEST(SelectBetweenTest) {
TEST_PARSE_SINGLE_SQL(
"SELECT grade, city FROM students WHERE grade BETWEEN 1 and c;",
"SELECT grade, city FROM students WHERE grade BETWEEN -1 and c;",
kStmtSelect,
SelectStatement,
result,
@ -139,7 +140,7 @@ TEST(SelectBetweenTest) {
ASSERT_EQ(where->exprList->size(), 2);
ASSERT(where->exprList->at(0)->isType(kExprLiteralInt));
ASSERT_EQ(where->exprList->at(0)->ival, 1);
ASSERT_EQ(where->exprList->at(0)->ival, -1);
ASSERT(where->exprList->at(1)->isType(kExprColumnRef));
ASSERT_STREQ(where->exprList->at(1)->getName(), "c");
}