Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luochenUmich authored and apavlo committed Dec 24, 2017
1 parent d6c6201 commit b6b2000
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/function/string_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ StringFunctions::StrWithLen StringFunctions::Substr(const char *str,
uint32_t end = unsigned(signed_end);
if (end > str_length) end = str_length;
if (begin > end) return StringFunctions::StrWithLen(nullptr, 0);
return StringFunctions::StrWithLen(str + begin, end - begin);
return StringFunctions::StrWithLen(str + begin, end - begin + 1);
}

// substring
Expand Down
50 changes: 24 additions & 26 deletions test/function/functions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_F(FunctionsTests, CatalogTest) {
internal_lang = pg_language.GetLanguageByOid(internal_lang->GetOid(), txn);
EXPECT_NE(nullptr, internal_lang);
EXPECT_EQ("internal", internal_lang->GetName());

// test add/del language
type::EphemeralPool pool;
std::string lanname = "foo_lang";
Expand All @@ -59,7 +59,7 @@ TEST_F(FunctionsTests, CatalogTest) {
pg_language.DeleteLanguage(lanname, txn);
inserted_lang = pg_language.GetLanguageByName(lanname, txn);
EXPECT_EQ(nullptr, inserted_lang);

txn_manager.CommitTransaction(txn);
auto &pg_proc = catalog::ProcCatalog::GetInstance();

Expand Down Expand Up @@ -93,7 +93,7 @@ TEST_F(FunctionsTests, FuncCallTest) {
auto txn = txn_manager.BeginTransaction();
catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, txn);
txn_manager.CommitTransaction(txn);

TestingSQLUtil::ExecuteSQLQuery("CREATE TABLE test(a DECIMAL, s VARCHAR);");
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO test VALUES (4.0, 'abc');");

Expand Down Expand Up @@ -129,7 +129,7 @@ TEST_F(FunctionsTests, SubstrFuncCallTest) {
auto txn = txn_manager.BeginTransaction();
catalog::Catalog::GetInstance()->CreateDatabase(DEFAULT_DB_NAME, txn);
txn_manager.CommitTransaction(txn);

TestingSQLUtil::ExecuteSQLQuery("CREATE TABLE test(a DECIMAL, s VARCHAR);");
TestingSQLUtil::ExecuteSQLQuery("INSERT INTO test VALUES (4.0, '1234567');");

Expand All @@ -138,34 +138,32 @@ TEST_F(FunctionsTests, SubstrFuncCallTest) {
std::string error_message;
int rows_affected;

// TestingSQLUtil::ExecuteSQLQuery("SELECT SUBSTR(s,1,5) FROM test;", result,
// tuple_descriptor, rows_affected,
// error_message);
// EXPECT_EQ(1, result.size());
// auto res = TestingSQLUtil::GetResultValueAsString(result, 0);
// EXPECT_EQ("12345", res);
TestingSQLUtil::ExecuteSQLQuery("SELECT SUBSTR(s,7,1) FROM test;", result,
TestingSQLUtil::ExecuteSQLQuery("SELECT SUBSTR(s,1,5) FROM test;", result,
tuple_descriptor, rows_affected,
error_message);
EXPECT_EQ(1, result.size());
auto res = TestingSQLUtil::GetResultValueAsString(result, 0);
EXPECT_EQ("12345", res);
TestingSQLUtil::ExecuteSQLQuery("SELECT SUBSTR(s,7,1) FROM test;", result,
tuple_descriptor, rows_affected,
error_message);
EXPECT_EQ(1, result.size());
res = TestingSQLUtil::GetResultValueAsString(result, 0);
EXPECT_EQ("7", res);

// TestingSQLUtil::ExecuteSQLQuery("SELECT SUBSTR(s,-2,4) FROM test;",
// result,
// tuple_descriptor, rows_affected,
// error_message);
// EXPECT_EQ(1, result.size());
// res = TestingSQLUtil::GetResultValueAsString(result, 0);
// EXPECT_EQ("1", res);

// TestingSQLUtil::ExecuteSQLQuery("SELECT SUBSTR(s,-2,2) FROM test;",
// result,
// tuple_descriptor, rows_affected,
// error_message);
// EXPECT_EQ(1, result.size());
// res = TestingSQLUtil::GetResultValueAsString(result, 0);
// EXPECT_EQ("", res);
TestingSQLUtil::ExecuteSQLQuery("SELECT SUBSTR(s,-2,4) FROM test;", result,
tuple_descriptor, rows_affected,
error_message);
EXPECT_EQ(1, result.size());
res = TestingSQLUtil::GetResultValueAsString(result, 0);
EXPECT_EQ("1", res);

TestingSQLUtil::ExecuteSQLQuery("SELECT SUBSTR(s,-2,2) FROM test;", result,
tuple_descriptor, rows_affected,
error_message);
EXPECT_EQ(1, result.size());
res = TestingSQLUtil::GetResultValueAsString(result, 0);
EXPECT_EQ("", res);

// free the database just created
txn = txn_manager.BeginTransaction();
Expand Down

0 comments on commit b6b2000

Please sign in to comment.