HyriseSQLParser/test/lib/select.cpp

47 lines
1.3 KiB
C++
Raw Normal View History

2014-12-03 16:32:56 +01:00
2014-12-18 12:11:26 +01:00
2014-12-03 16:32:56 +01:00
#include "test.h"
2014-12-18 12:11:26 +01:00
#include "helper.h"
2014-12-03 16:32:56 +01:00
#include "SQLParser.h"
using namespace hsql;
2014-12-18 12:11:26 +01:00
TEST(SelectTest) {
2016-02-27 15:01:06 +01:00
TEST_PARSE_SINGLE_SQL("SELECT * FROM students;", kStmtSelect, SelectStatement, stmt);
2014-12-18 12:11:26 +01:00
2016-02-27 15:22:22 +01:00
ASSERT_NULL(stmt->whereClause);
ASSERT_NULL(stmt->groupBy);
2014-12-18 12:11:26 +01:00
}
TEST(SelectHavingTest) {
2016-02-27 15:01:06 +01:00
TEST_PARSE_SINGLE_SQL("SELECT city, AVG(grade) AS avg_grade FROM students GROUP BY city HAVING AVG(grade) < 2.0", kStmtSelect, SelectStatement, stmt);
2016-02-27 15:22:22 +01:00
ASSERT_FALSE(stmt->selectDistinct);
2016-02-27 15:01:06 +01:00
2016-02-27 15:22:22 +01:00
GroupByDescription* group = stmt->groupBy;
2016-02-27 15:01:06 +01:00
ASSERT_NOTNULL(group);
ASSERT_EQ(group->columns->size(), 1);
ASSERT(group->having->isSimpleOp('<'));
ASSERT(group->having->expr->isType(kExprFunctionRef));
ASSERT(group->having->expr2->isType(kExprLiteralFloat));
2014-12-18 12:11:26 +01:00
}
2014-12-03 16:32:56 +01:00
2014-12-18 12:11:26 +01:00
TEST(SelectDistinctTest) {
2016-02-27 15:01:06 +01:00
TEST_PARSE_SINGLE_SQL("SELECT DISTINCT grade, city FROM students;", kStmtSelect, SelectStatement, stmt);
2014-12-18 12:28:24 +01:00
2016-02-27 15:22:22 +01:00
ASSERT(stmt->selectDistinct);
ASSERT_NULL(stmt->whereClause);
2014-12-03 16:32:56 +01:00
}
2014-12-18 12:11:26 +01:00
TEST(SelectGroupDistinctTest) {
2016-02-27 15:01:06 +01:00
TEST_PARSE_SINGLE_SQL("SELECT city, COUNT(name), COUNT(DISTINCT grade) FROM students GROUP BY city;", kStmtSelect, SelectStatement, stmt);
2014-12-18 12:28:24 +01:00
2016-02-27 15:22:22 +01:00
ASSERT_FALSE(stmt->selectDistinct);
ASSERT_EQ(stmt->selectList->size(), 3);
ASSERT(!stmt->selectList->at(1)->distinct);
ASSERT(stmt->selectList->at(2)->distinct);
2014-12-18 12:11:26 +01:00
}