summaryrefslogtreecommitdiff
path: root/libdbpp/unittests/testParse.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-12-04 20:32:55 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-12-04 20:32:55 +0000
commitaf336048f7f053f1c27e9c87530b2300ab20b015 (patch)
tree0676cfcdbadffd269d3c97c020aa5860fa908061 /libdbpp/unittests/testParse.cpp
parentSplit the parser tests away from the connection tests and introduce a better ... (diff)
downloadlibdbpp-af336048f7f053f1c27e9c87530b2300ab20b015.tar.bz2
libdbpp-af336048f7f053f1c27e9c87530b2300ab20b015.tar.xz
libdbpp-af336048f7f053f1c27e9c87530b2300ab20b015.zip
Assorted improvements to he SQL lexer to better handle whitespace and comments mixed into statements
Diffstat (limited to 'libdbpp/unittests/testParse.cpp')
-rw-r--r--libdbpp/unittests/testParse.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/libdbpp/unittests/testParse.cpp b/libdbpp/unittests/testParse.cpp
index 1272f9b..093cc7d 100644
--- a/libdbpp/unittests/testParse.cpp
+++ b/libdbpp/unittests/testParse.cpp
@@ -78,6 +78,45 @@ BOOST_AUTO_TEST_CASE( parseStringParse )
BOOST_REQUIRE_EQUAL("INSERT INTO name(t, i) VALUES('fancy string '' \\' \\r \\n', 7)", p.executed[1]);
}
+BOOST_AUTO_TEST_CASE( indentedStatement )
+{
+ RecordingParser p(rootDir / "indentedStatement.sql");
+ p.Execute();
+ BOOST_REQUIRE_EQUAL(1, p.executed.size());
+ BOOST_REQUIRE_EQUAL("SELECT 1", p.executed[0]);
+ BOOST_REQUIRE(p.comments.empty());
+}
+
+BOOST_AUTO_TEST_CASE( indentedOneLineComment )
+{
+ RecordingParser p(rootDir / "indentedOneLineComment.sql");
+ p.Execute();
+ BOOST_REQUIRE_EQUAL(1, p.comments.size());
+ BOOST_REQUIRE_EQUAL("Some comment text", p.comments[0]);
+ BOOST_REQUIRE(p.executed.empty());
+}
+
+BOOST_AUTO_TEST_CASE( indentedBlockComment )
+{
+ RecordingParser p(rootDir / "indentedBlockComment.sql");
+ p.Execute();
+ BOOST_REQUIRE_EQUAL(1, p.comments.size());
+ BOOST_REQUIRE_EQUAL("Some comment text", p.comments[0]);
+ BOOST_REQUIRE(p.executed.empty());
+}
+
+BOOST_AUTO_TEST_CASE( commentsMixedIn )
+{
+ RecordingParser p(rootDir / "commentsMixedIn.sql");
+ p.Execute();
+ BOOST_REQUIRE_EQUAL(1, p.executed.size());
+ BOOST_REQUIRE_EQUAL("CREATE TABLE foo(\n\t\tid int,\n\t\ttimestamp time stamp\n\t\t)", p.executed[0]);
+ BOOST_REQUIRE_EQUAL(3, p.comments.size());
+ BOOST_REQUIRE_EQUAL("Foo contains test things", p.comments[0]);
+ BOOST_REQUIRE_EQUAL("Every table deserves an Id, right?", p.comments[1]);
+ BOOST_REQUIRE_EQUAL("And a timestamp", p.comments[2]);
+}
+
BOOST_AUTO_TEST_CASE( parseUnterminateComment )
{
assertFail(rootDir / "unterminatedComment.sql");