mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-25 14:34:04 +02:00

* fix(SQLParser): move to Data dir; add extradirs, remove vs 140,150 build scripts generation * fix(ActiveRecord): Makefile #4453 * fix(Data): Make SQLParser internal * fix(build): ODBC Makefile and Data libs CmakeLists #4453 * fix(build): Data libs CMakeLists #4453 * fix(build): regenerate VS projects #4453 * fix(CppUnit): remove Foundation dependency * fix(SQLParser): remove leftover unnecessary includes * fix(SQLParser): remove fwd header #4453 * fix(PocoDoc): remove SQLParser from include list * fix(mkrelease): remove 140,150 vs projects * fix(SQLParser): Disable SQL parsing by default #4462 * fix(test): Disable SQL parsing by default #4462 * Fix detection of odbc and apache2 for Fedora (#4461) * Fixed transaction handling in MySQL test when SQL parser is switched off * chore(ParallelSocketAcceptor): remove unnecessary include and using from header --------- Co-authored-by: Matej Kenda <matejken@gmail.com> Co-authored-by: topazus <77263945+topazus@users.noreply.github.com> Co-authored-by: Friedrich Wilckens <frwilckens@gmail.com>
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#include "thirdparty/microtest/microtest.h"
|
|
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include "SQLParser.h"
|
|
#include "parser/bison_parser.h"
|
|
#include "sql_asserts.h"
|
|
|
|
using namespace hsql;
|
|
|
|
void test_tokens(const std::string& query, const std::vector<int16_t>& expected_tokens) {
|
|
std::vector<int16_t> tokens;
|
|
ASSERT(SQLParser::tokenize(query, &tokens));
|
|
|
|
ASSERT_EQ(expected_tokens.size(), tokens.size());
|
|
|
|
for (unsigned i = 0; i < expected_tokens.size(); ++i) {
|
|
ASSERT_EQ(expected_tokens[i], tokens[i]);
|
|
}
|
|
}
|
|
|
|
TEST(SQLParserTokenizeTest) {
|
|
test_tokens("SELECT * FROM test;", {SQL_SELECT, '*', SQL_FROM, SQL_IDENTIFIER, ';'});
|
|
test_tokens("SELECT a, 'b' FROM test WITH HINT;",
|
|
{SQL_SELECT, SQL_IDENTIFIER, ',', SQL_STRING, SQL_FROM, SQL_IDENTIFIER, SQL_WITH, SQL_HINT, ';'});
|
|
}
|
|
|
|
TEST(SQLParserTokenizeStringifyTest) {
|
|
const std::string query = "SELECT * FROM test;";
|
|
std::vector<int16_t> tokens;
|
|
ASSERT(SQLParser::tokenize(query, &tokens));
|
|
|
|
// Make u16string.
|
|
std::u16string token_string(tokens.cbegin(), tokens.cend());
|
|
|
|
// Check if u16 string is cacheable.
|
|
std::map<std::u16string, std::string> cache;
|
|
cache[token_string] = query;
|
|
|
|
ASSERT(query == cache[token_string]);
|
|
ASSERT(&query != &cache[token_string]);
|
|
}
|